Skip to content

Commit

Permalink
首次提交 - 智谱清言 版本号: 2024.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KNOOP committed Oct 12, 2024
0 parents commit e0ce244
Show file tree
Hide file tree
Showing 17 changed files with 853 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 智谱清言 AI Home Assistant 🏡

![GitHub Version](https://img.shields.io/github/v/release/knoop7/zhipuai)
![GitHub Issues](https://img.shields.io/github/issues/knoop7/zhipuai)
![GitHub Forks](https://img.shields.io/github/forks/knoop7/zhipuai?style=social)
![GitHub Stars](https://img.shields.io/github/stars/knoop7/zhipuai?style=social)

<img src="https://github.com/user-attachments/assets/f8ff7a6c-4449-496a-889a-d205469a84df" alt="image" width="700" height="400">



## 🔧 安装步骤
打开 Home Assistant 仪表板。
点击侧边栏中的 "HACS"。
进入 "集成" 页面,点击右下角的 "探索并下载存储库"。
搜索项目地址 https://github.com/knoop7/zhipuai
点击安装项目,并根据提示完成安装。

进入 Home Assistant 的“设置” -> “设备与服务”,找到“智谱清言”集成并添加。


智谱清言 AI 集成让 Home Assistant 用户通过自然语言或语音指令控制智能家居设备,提供更直观的家居自动化体验。

## 🚀 使用指南

1. **访问界面**
打开 Home Assistant 仪表板,找到“智谱清言”卡片或集成页面。

2. **输入指令**
在对话框中输入自然语言指令,或使用语音助手说出指令。

3. **查看响应**
系统会执行指令并提供反馈,设备状态变化会实时更新。

4. **探索功能**
尝试不同类型的指令来控制各种设备,或查询家居状态。

## 💡 常用指令示例

- "打开客厅灯"
- "将卧室温度调到 22 度"
- "播放音乐"
- "明早 7 点的备忘录"
- "检查门锁状态"
Binary file added custom_components/.DS_Store
Binary file not shown.
44 changes: 44 additions & 0 deletions custom_components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 智谱清言 AI Home Assistant 🏡

![GitHub Version](https://img.shields.io/github/v/release/knoop7/zhipuai)
![GitHub Issues](https://img.shields.io/github/issues/knoop7/zhipuai)
![GitHub Forks](https://img.shields.io/github/forks/knoop7/zhipuai?style=social)
![GitHub Stars](https://img.shields.io/github/stars/knoop7/zhipuai?style=social)

<img src="https://github.com/user-attachments/assets/f8ff7a6c-4449-496a-889a-d205469a84df" alt="image" width="700" height="400">



## 🔧 安装步骤
打开 Home Assistant 仪表板。
点击侧边栏中的 "HACS"。
进入 "集成" 页面,点击右下角的 "探索并下载存储库"。
搜索项目地址 https://github.com/knoop7/zhipuai
点击安装项目,并根据提示完成安装。

进入 Home Assistant 的“设置” -> “设备与服务”,找到“智谱清言”集成并添加。


智谱清言 AI 集成让 Home Assistant 用户通过自然语言或语音指令控制智能家居设备,提供更直观的家居自动化体验。

## 🚀 使用指南

1. **访问界面**
打开 Home Assistant 仪表板,找到“智谱清言”卡片或集成页面。

2. **输入指令**
在对话框中输入自然语言指令,或使用语音助手说出指令。

3. **查看响应**
系统会执行指令并提供反馈,设备状态变化会实时更新。

4. **探索功能**
尝试不同类型的指令来控制各种设备,或查询家居状态。

## 💡 常用指令示例

- "打开客厅灯"
- "将卧室温度调到 22 度"
- "播放音乐"
- "明早 7 点的备忘录"
- "检查门锁状态"
5 changes: 5 additions & 0 deletions custom_components/hacs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "智谱清言",
"render_readme": true,
"homeassistant": "2023.6.0"
}
76 changes: 76 additions & 0 deletions custom_components/zhipuai/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from __future__ import annotations
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY, Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.dispatcher import async_dispatcher_send
from .const import DOMAIN, LOGGER

PLATFORMS: list[Platform] = [Platform.CONVERSATION]

class ZhipuAIConfigEntry:

def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry):
self.hass = hass
self.config_entry = config_entry
self.api_key = config_entry.data[CONF_API_KEY]
self.options = config_entry.options
self._unsub_options_update_listener = None
self._cleanup_callbacks = []

@property
def entry_id(self):
return self.config_entry.entry_id

@property
def title(self):
return self.config_entry.title

async def async_setup(self) -> None:
self._unsub_options_update_listener = self.config_entry.add_update_listener(
self.async_options_updated
)

async def async_unload(self) -> None:
if self._unsub_options_update_listener is not None:
self._unsub_options_update_listener()
self._unsub_options_update_listener = None
# Call all cleanup callbacks
for cleanup_callback in self._cleanup_callbacks:
cleanup_callback()
self._cleanup_callbacks.clear()

def async_on_unload(self, func):
self._cleanup_callbacks.append(func)

@callback
async def async_options_updated(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
self.options = entry.options
async_dispatcher_send(hass, f"{DOMAIN}_options_updated", entry)

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data.setdefault(DOMAIN, {})
try:
zhipuai_entry = ZhipuAIConfigEntry(hass, entry)
await zhipuai_entry.async_setup()
hass.data[DOMAIN][entry.entry_id] = zhipuai_entry
LOGGER.info("成功设置, 条目 ID: %s", entry.entry_id)
except Exception as ex:
LOGGER.error("设置 AI 时出错: %s", ex)
raise ConfigEntryNotReady from ex

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
zhipuai_entry = hass.data[DOMAIN].get(entry.entry_id)
if zhipuai_entry is None:
return True

if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
await zhipuai_entry.async_unload()
hass.data[DOMAIN].pop(entry.entry_id, None)
LOGGER.info("已卸载 AI 条目,ID: %s", entry.entry_id)

return unload_ok
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit e0ce244

Please sign in to comment.