feat: 初始化小米 IoT (MIoT) 智能家居 Go 库
- 实现 MIoT 客户端核心功能(MQTT 连接、设备管理、属性读写) - 支持云端 API 调用与局域网设备发现(mDNS) - 集成国际化(i18n)多语言支持 - 添加 MIoT 设备规约解析器(spec_parser) - 包含单元测试与使用示例
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
# R2-02 — spec_parser.go: ValueList 查询方法
|
||||
|
||||
## 缺失方法
|
||||
|
||||
在 `MIoTSpecValueList` 上添加 5 个查询方法:
|
||||
|
||||
### Names / Values / Descriptions
|
||||
```python
|
||||
@property
|
||||
def names(self) -> list[str]:
|
||||
return [item.name for item in self.items]
|
||||
@property
|
||||
def values(self) -> list[Any]:
|
||||
return [item.value for item in self.items]
|
||||
@property
|
||||
def descriptions(self) -> list[str]:
|
||||
return [item.description for item in self.items]
|
||||
```
|
||||
|
||||
### 双向查找
|
||||
```python
|
||||
def get_value_by_description(self, description: str) -> Any:
|
||||
for item in self.items:
|
||||
if item.description == description:
|
||||
return item.value
|
||||
return None
|
||||
|
||||
def get_description_by_value(self, value: Any) -> Optional[str]:
|
||||
for item in self.items:
|
||||
if item.value == value:
|
||||
return item.description
|
||||
return None
|
||||
```
|
||||
|
||||
## 目标文件
|
||||
|
||||
`D:\miot\go-miot\spec_parser.go`
|
||||
|
||||
在 `MIoTSpecValueList` 上添加:
|
||||
- `func (vl *MIoTSpecValueList) Names() []string`
|
||||
- `func (vl *MIoTSpecValueList) Values() []interface{}`
|
||||
- `func (vl *MIoTSpecValueList) Descriptions() []string`
|
||||
- `func (vl *MIoTSpecValueList) GetValueByDescription(desc string) interface{}`
|
||||
- `func (vl *MIoTSpecValueList) GetDescriptionByValue(value interface{}) string`
|
||||
Reference in New Issue
Block a user