connectlife-cloud 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- connectlife_cloud-0.1.0/PKG-INFO +109 -0
- connectlife_cloud-0.1.0/README.md +69 -0
- connectlife_cloud-0.1.0/connectlife_cloud.egg-info/PKG-INFO +109 -0
- connectlife_cloud-0.1.0/connectlife_cloud.egg-info/SOURCES.txt +16 -0
- connectlife_cloud-0.1.0/connectlife_cloud.egg-info/dependency_links.txt +1 -0
- connectlife_cloud-0.1.0/connectlife_cloud.egg-info/requires.txt +11 -0
- connectlife_cloud-0.1.0/connectlife_cloud.egg-info/top_level.txt +1 -0
- connectlife_cloud-0.1.0/devices/__init__.py +46 -0
- connectlife_cloud-0.1.0/devices/atw_035_699.py +117 -0
- connectlife_cloud-0.1.0/devices/base.py +129 -0
- connectlife_cloud-0.1.0/devices/base_bean.py +203 -0
- connectlife_cloud-0.1.0/devices/bean_006_299.py +141 -0
- connectlife_cloud-0.1.0/devices/hum_007.py +90 -0
- connectlife_cloud-0.1.0/devices/split_ac_009_199.py +143 -0
- connectlife_cloud-0.1.0/devices/window_ac_008_399.py +104 -0
- connectlife_cloud-0.1.0/pyproject.toml +80 -0
- connectlife_cloud-0.1.0/setup.cfg +4 -0
- connectlife_cloud-0.1.0/setup.py +56 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: connectlife-cloud
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ConnectLife Cloud API client library for Home Assistant integrations
|
|
5
|
+
Home-page: https://github.com/Connectlife-LLC/connectlife-cloud
|
|
6
|
+
Author: ConnectLife LLC
|
|
7
|
+
Author-email: ConnectLife LLC <support@connectlife.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/Connectlife-LLC/connectlife-cloud
|
|
10
|
+
Project-URL: Repository, https://github.com/Connectlife-LLC/connectlife-cloud
|
|
11
|
+
Project-URL: Issues, https://github.com/Connectlife-LLC/connectlife-cloud/issues
|
|
12
|
+
Keywords: homeassistant,connectlife,api,client,iot
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Home Automation
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Requires-Python: >=3.8
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
Requires-Dist: aiohttp>=3.8.0
|
|
28
|
+
Requires-Dist: pytz>=2021.1
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-asyncio>=0.18.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-cov>=2.10.0; extra == "dev"
|
|
33
|
+
Requires-Dist: black>=21.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: isort>=5.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: mypy>=0.910; extra == "dev"
|
|
36
|
+
Requires-Dist: pre-commit>=2.15.0; extra == "dev"
|
|
37
|
+
Dynamic: author
|
|
38
|
+
Dynamic: home-page
|
|
39
|
+
Dynamic: requires-python
|
|
40
|
+
|
|
41
|
+
# ConnectLife Cloud API Client
|
|
42
|
+
|
|
43
|
+
A Python client library for the ConnectLife Cloud API, designed for Home Assistant integrations.
|
|
44
|
+
|
|
45
|
+
## Features
|
|
46
|
+
|
|
47
|
+
- Async/await support
|
|
48
|
+
- Full type hints
|
|
49
|
+
- Comprehensive error handling
|
|
50
|
+
- Device management
|
|
51
|
+
- Real-time status updates
|
|
52
|
+
- Power consumption tracking
|
|
53
|
+
- Self-check diagnostics
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install connectlife-cloud
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import asyncio
|
|
65
|
+
from connectlife_cloud import ConnectLifeCloudClient
|
|
66
|
+
|
|
67
|
+
async def main():
|
|
68
|
+
client = ConnectLifeCloudClient(
|
|
69
|
+
client_id="your_client_id",
|
|
70
|
+
client_secret="your_client_secret"
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
try:
|
|
74
|
+
# Get devices
|
|
75
|
+
devices = await client.get_devices(access_token="your_token")
|
|
76
|
+
print(f"Found {len(devices)} devices")
|
|
77
|
+
|
|
78
|
+
# Control a device
|
|
79
|
+
result = await client.control_device(
|
|
80
|
+
puid="device_puid",
|
|
81
|
+
properties={"power": True, "mode": "cool"},
|
|
82
|
+
access_token="your_token"
|
|
83
|
+
)
|
|
84
|
+
print(f"Control result: {result}")
|
|
85
|
+
|
|
86
|
+
finally:
|
|
87
|
+
await client.close()
|
|
88
|
+
|
|
89
|
+
asyncio.run(main())
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## API Reference
|
|
93
|
+
|
|
94
|
+
### ConnectLifeCloudClient
|
|
95
|
+
|
|
96
|
+
The main client class for interacting with the ConnectLife Cloud API.
|
|
97
|
+
|
|
98
|
+
#### Methods
|
|
99
|
+
|
|
100
|
+
- `get_devices(access_token)`: Get list of devices
|
|
101
|
+
- `control_device(puid, properties, access_token)`: Control a device
|
|
102
|
+
- `get_property_list(device_type_code, device_feature_code, access_token)`: Get device properties
|
|
103
|
+
- `query_static_data(puid, access_token)`: Query static device data
|
|
104
|
+
- `get_hour_power(date, puid, access_token)`: Get hourly power consumption
|
|
105
|
+
- `get_self_check(no_record, puid, access_token)`: Get device self-check info
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
MIT License
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# ConnectLife Cloud API Client
|
|
2
|
+
|
|
3
|
+
A Python client library for the ConnectLife Cloud API, designed for Home Assistant integrations.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Async/await support
|
|
8
|
+
- Full type hints
|
|
9
|
+
- Comprehensive error handling
|
|
10
|
+
- Device management
|
|
11
|
+
- Real-time status updates
|
|
12
|
+
- Power consumption tracking
|
|
13
|
+
- Self-check diagnostics
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install connectlife-cloud
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
import asyncio
|
|
25
|
+
from connectlife_cloud import ConnectLifeCloudClient
|
|
26
|
+
|
|
27
|
+
async def main():
|
|
28
|
+
client = ConnectLifeCloudClient(
|
|
29
|
+
client_id="your_client_id",
|
|
30
|
+
client_secret="your_client_secret"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
# Get devices
|
|
35
|
+
devices = await client.get_devices(access_token="your_token")
|
|
36
|
+
print(f"Found {len(devices)} devices")
|
|
37
|
+
|
|
38
|
+
# Control a device
|
|
39
|
+
result = await client.control_device(
|
|
40
|
+
puid="device_puid",
|
|
41
|
+
properties={"power": True, "mode": "cool"},
|
|
42
|
+
access_token="your_token"
|
|
43
|
+
)
|
|
44
|
+
print(f"Control result: {result}")
|
|
45
|
+
|
|
46
|
+
finally:
|
|
47
|
+
await client.close()
|
|
48
|
+
|
|
49
|
+
asyncio.run(main())
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## API Reference
|
|
53
|
+
|
|
54
|
+
### ConnectLifeCloudClient
|
|
55
|
+
|
|
56
|
+
The main client class for interacting with the ConnectLife Cloud API.
|
|
57
|
+
|
|
58
|
+
#### Methods
|
|
59
|
+
|
|
60
|
+
- `get_devices(access_token)`: Get list of devices
|
|
61
|
+
- `control_device(puid, properties, access_token)`: Control a device
|
|
62
|
+
- `get_property_list(device_type_code, device_feature_code, access_token)`: Get device properties
|
|
63
|
+
- `query_static_data(puid, access_token)`: Query static device data
|
|
64
|
+
- `get_hour_power(date, puid, access_token)`: Get hourly power consumption
|
|
65
|
+
- `get_self_check(no_record, puid, access_token)`: Get device self-check info
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
MIT License
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: connectlife-cloud
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ConnectLife Cloud API client library for Home Assistant integrations
|
|
5
|
+
Home-page: https://github.com/Connectlife-LLC/connectlife-cloud
|
|
6
|
+
Author: ConnectLife LLC
|
|
7
|
+
Author-email: ConnectLife LLC <support@connectlife.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/Connectlife-LLC/connectlife-cloud
|
|
10
|
+
Project-URL: Repository, https://github.com/Connectlife-LLC/connectlife-cloud
|
|
11
|
+
Project-URL: Issues, https://github.com/Connectlife-LLC/connectlife-cloud/issues
|
|
12
|
+
Keywords: homeassistant,connectlife,api,client,iot
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Home Automation
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Requires-Python: >=3.8
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
Requires-Dist: aiohttp>=3.8.0
|
|
28
|
+
Requires-Dist: pytz>=2021.1
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-asyncio>=0.18.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-cov>=2.10.0; extra == "dev"
|
|
33
|
+
Requires-Dist: black>=21.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: isort>=5.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: mypy>=0.910; extra == "dev"
|
|
36
|
+
Requires-Dist: pre-commit>=2.15.0; extra == "dev"
|
|
37
|
+
Dynamic: author
|
|
38
|
+
Dynamic: home-page
|
|
39
|
+
Dynamic: requires-python
|
|
40
|
+
|
|
41
|
+
# ConnectLife Cloud API Client
|
|
42
|
+
|
|
43
|
+
A Python client library for the ConnectLife Cloud API, designed for Home Assistant integrations.
|
|
44
|
+
|
|
45
|
+
## Features
|
|
46
|
+
|
|
47
|
+
- Async/await support
|
|
48
|
+
- Full type hints
|
|
49
|
+
- Comprehensive error handling
|
|
50
|
+
- Device management
|
|
51
|
+
- Real-time status updates
|
|
52
|
+
- Power consumption tracking
|
|
53
|
+
- Self-check diagnostics
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install connectlife-cloud
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import asyncio
|
|
65
|
+
from connectlife_cloud import ConnectLifeCloudClient
|
|
66
|
+
|
|
67
|
+
async def main():
|
|
68
|
+
client = ConnectLifeCloudClient(
|
|
69
|
+
client_id="your_client_id",
|
|
70
|
+
client_secret="your_client_secret"
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
try:
|
|
74
|
+
# Get devices
|
|
75
|
+
devices = await client.get_devices(access_token="your_token")
|
|
76
|
+
print(f"Found {len(devices)} devices")
|
|
77
|
+
|
|
78
|
+
# Control a device
|
|
79
|
+
result = await client.control_device(
|
|
80
|
+
puid="device_puid",
|
|
81
|
+
properties={"power": True, "mode": "cool"},
|
|
82
|
+
access_token="your_token"
|
|
83
|
+
)
|
|
84
|
+
print(f"Control result: {result}")
|
|
85
|
+
|
|
86
|
+
finally:
|
|
87
|
+
await client.close()
|
|
88
|
+
|
|
89
|
+
asyncio.run(main())
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## API Reference
|
|
93
|
+
|
|
94
|
+
### ConnectLifeCloudClient
|
|
95
|
+
|
|
96
|
+
The main client class for interacting with the ConnectLife Cloud API.
|
|
97
|
+
|
|
98
|
+
#### Methods
|
|
99
|
+
|
|
100
|
+
- `get_devices(access_token)`: Get list of devices
|
|
101
|
+
- `control_device(puid, properties, access_token)`: Control a device
|
|
102
|
+
- `get_property_list(device_type_code, device_feature_code, access_token)`: Get device properties
|
|
103
|
+
- `query_static_data(puid, access_token)`: Query static device data
|
|
104
|
+
- `get_hour_power(date, puid, access_token)`: Get hourly power consumption
|
|
105
|
+
- `get_self_check(no_record, puid, access_token)`: Get device self-check info
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
MIT License
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
setup.py
|
|
4
|
+
connectlife_cloud.egg-info/PKG-INFO
|
|
5
|
+
connectlife_cloud.egg-info/SOURCES.txt
|
|
6
|
+
connectlife_cloud.egg-info/dependency_links.txt
|
|
7
|
+
connectlife_cloud.egg-info/requires.txt
|
|
8
|
+
connectlife_cloud.egg-info/top_level.txt
|
|
9
|
+
devices/__init__.py
|
|
10
|
+
devices/atw_035_699.py
|
|
11
|
+
devices/base.py
|
|
12
|
+
devices/base_bean.py
|
|
13
|
+
devices/bean_006_299.py
|
|
14
|
+
devices/hum_007.py
|
|
15
|
+
devices/split_ac_009_199.py
|
|
16
|
+
devices/window_ac_008_399.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
devices
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Device parsers package."""
|
|
2
|
+
from typing import Dict, Type
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
from .atw_035_699 import SplitWater035699Parser
|
|
6
|
+
from .base import BaseDeviceParser
|
|
7
|
+
from .base_bean import BaseBeanParser
|
|
8
|
+
from .hum_007 import Humidity007Parser
|
|
9
|
+
from .split_ac_009_199 import SplitAC009199Parser
|
|
10
|
+
from .window_ac_008_399 import WindowAC008399Parser
|
|
11
|
+
from .bean_006_299 import Split006299Parser
|
|
12
|
+
|
|
13
|
+
_LOGGER = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
# Registry of device parsers
|
|
16
|
+
DEVICE_PARSERS: Dict[tuple[str, str], Type[BaseDeviceParser]] = {
|
|
17
|
+
("035", "699"): SplitWater035699Parser,
|
|
18
|
+
("006", "299"): Split006299Parser,
|
|
19
|
+
("007", ""): Humidity007Parser,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_device_parser(device_type: str , feature_code: str) -> Type[BaseDeviceParser]:
|
|
24
|
+
"""Get device parser for the given device type."""
|
|
25
|
+
_LOGGER.debug("Getting device parser for type %s", device_type)
|
|
26
|
+
if DEVICE_PARSERS.get((device_type, feature_code)):
|
|
27
|
+
_LOGGER.debug("三联供设备 %s", device_type)
|
|
28
|
+
return DEVICE_PARSERS[(device_type, feature_code)]
|
|
29
|
+
if device_type == "007":
|
|
30
|
+
_LOGGER.debug("除湿机设备 %s", device_type)
|
|
31
|
+
return Humidity007Parser
|
|
32
|
+
# 预设的设备类型集合
|
|
33
|
+
supported_device_types = ["009", "008", "006", "016"]
|
|
34
|
+
if device_type in supported_device_types:
|
|
35
|
+
parser_class = BaseBeanParser
|
|
36
|
+
_LOGGER.debug("Using default parser for device type %s", device_type)
|
|
37
|
+
# try:
|
|
38
|
+
# static_data = await self.async_get_property_list(device_type, feature_code)
|
|
39
|
+
# _LOGGER.debug("Static data for device %s: %s: %s", device_type, feature_code, static_data)
|
|
40
|
+
# except Exception as query_err:
|
|
41
|
+
# _LOGGER.error("Error querying static data for device %s: %s", feature_code, query_err)
|
|
42
|
+
return parser_class
|
|
43
|
+
else:
|
|
44
|
+
_LOGGER.warning("Unsupported device type: %s", device_type)
|
|
45
|
+
raise ValueError(f"Unsupported device type: {device_type}")
|
|
46
|
+
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Parser for Split AC (009-199) device type."""
|
|
2
|
+
from typing import Dict
|
|
3
|
+
|
|
4
|
+
from .base import BaseDeviceParser, DeviceAttribute
|
|
5
|
+
|
|
6
|
+
class SplitWater035699Parser(BaseDeviceParser):
|
|
7
|
+
"""Parser for Split AC 009-199 device type."""
|
|
8
|
+
|
|
9
|
+
@property
|
|
10
|
+
def device_type(self) -> str:
|
|
11
|
+
return "035"
|
|
12
|
+
|
|
13
|
+
@property
|
|
14
|
+
def feature_code(self) -> str:
|
|
15
|
+
return "699"
|
|
16
|
+
|
|
17
|
+
@property
|
|
18
|
+
def attributes(self) -> Dict[str, DeviceAttribute]:
|
|
19
|
+
return {
|
|
20
|
+
"t_work_mode": DeviceAttribute(
|
|
21
|
+
key="t_work_mode",
|
|
22
|
+
name="设定模式",
|
|
23
|
+
attr_type="Enum",
|
|
24
|
+
step=1,
|
|
25
|
+
value_range="1, 0, 15, 5, 6, 16, 3",
|
|
26
|
+
value_map={
|
|
27
|
+
"0": "制热",
|
|
28
|
+
"1": "制冷",
|
|
29
|
+
"15": "自动",
|
|
30
|
+
"5": "热水+制冷",
|
|
31
|
+
"16": "热水+自动",
|
|
32
|
+
"3": "热水",
|
|
33
|
+
"6": "热水+制热"
|
|
34
|
+
},
|
|
35
|
+
read_write="RW"
|
|
36
|
+
),
|
|
37
|
+
"t_temp": DeviceAttribute(
|
|
38
|
+
key="t_temp",
|
|
39
|
+
name="设置温度",
|
|
40
|
+
attr_type="Number",
|
|
41
|
+
step=1,
|
|
42
|
+
value_range="16~32,61~90",
|
|
43
|
+
read_write="RW"
|
|
44
|
+
),
|
|
45
|
+
"t_power": DeviceAttribute(
|
|
46
|
+
key="t_power",
|
|
47
|
+
name="开关机",
|
|
48
|
+
attr_type="Enum",
|
|
49
|
+
step=1,
|
|
50
|
+
value_range="0,1",
|
|
51
|
+
value_map={
|
|
52
|
+
"0": "关",
|
|
53
|
+
"1": "开"
|
|
54
|
+
},
|
|
55
|
+
read_write="RW"
|
|
56
|
+
),
|
|
57
|
+
"f_zone1water_temp1": DeviceAttribute(
|
|
58
|
+
key="f_zone1water_temp1",
|
|
59
|
+
name="1温区实际值",
|
|
60
|
+
attr_type="Number",
|
|
61
|
+
step=1,
|
|
62
|
+
value_range="16~32,61~90",
|
|
63
|
+
read_write="R"
|
|
64
|
+
),
|
|
65
|
+
"f_zone2water_temp2": DeviceAttribute(
|
|
66
|
+
key="f_zone2water_temp2",
|
|
67
|
+
name="2温区实际值",
|
|
68
|
+
attr_type="Number",
|
|
69
|
+
step=1,
|
|
70
|
+
value_range="16~32,61~90",
|
|
71
|
+
read_write="R"
|
|
72
|
+
),
|
|
73
|
+
"f_water_tank_temp": DeviceAttribute(
|
|
74
|
+
key="f_water_tank_temp",
|
|
75
|
+
name="生活热水实际值",
|
|
76
|
+
attr_type="Number",
|
|
77
|
+
step=1,
|
|
78
|
+
value_range="16~32,61~90",
|
|
79
|
+
read_write="R"
|
|
80
|
+
),
|
|
81
|
+
"t_zone1water_settemp1": DeviceAttribute(
|
|
82
|
+
key="t_zone1water_settemp1",
|
|
83
|
+
name="1温区设置值",
|
|
84
|
+
attr_type="Number",
|
|
85
|
+
step=1,
|
|
86
|
+
value_range="16~32,61~90",
|
|
87
|
+
read_write="RW"
|
|
88
|
+
),
|
|
89
|
+
"t_zone2water_settemp2": DeviceAttribute(
|
|
90
|
+
key="t_zone2water_settemp2",
|
|
91
|
+
name="2温区设置值",
|
|
92
|
+
attr_type="Number",
|
|
93
|
+
step=1,
|
|
94
|
+
value_range="16~32,61~90",
|
|
95
|
+
read_write="RW"
|
|
96
|
+
),
|
|
97
|
+
"t_dhw_temp": DeviceAttribute(
|
|
98
|
+
key="t_dhw_temp",
|
|
99
|
+
name="生活热水设置值",
|
|
100
|
+
attr_type="Number",
|
|
101
|
+
step=1,
|
|
102
|
+
value_range="16~32,61~90",
|
|
103
|
+
read_write="RW"
|
|
104
|
+
),
|
|
105
|
+
"f_power_consumption": DeviceAttribute(
|
|
106
|
+
key="f_power_consumption",
|
|
107
|
+
name="电量累积消耗值",
|
|
108
|
+
attr_type="Number",
|
|
109
|
+
read_write="R"
|
|
110
|
+
),
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
def remove_attribute(self, key: str) -> None:
|
|
114
|
+
"""移除指定的属性"""
|
|
115
|
+
attributes = self.attributes
|
|
116
|
+
if key in attributes:
|
|
117
|
+
del attributes[key]
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""Base device parser class."""
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
from typing import Any, Dict, Optional
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
import logging
|
|
6
|
+
|
|
7
|
+
_LOGGER = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class DeviceAttribute:
|
|
11
|
+
"""Device attribute definition."""
|
|
12
|
+
key: str
|
|
13
|
+
name: str
|
|
14
|
+
attr_type: str
|
|
15
|
+
step: int = 1
|
|
16
|
+
value_range: Optional[str] = None#数值区间
|
|
17
|
+
value_map: Optional[Dict[str, str]] = None#数值集合
|
|
18
|
+
read_write: str = "RW"
|
|
19
|
+
|
|
20
|
+
class BaseDeviceParser(ABC):
|
|
21
|
+
"""Base class for device parsers."""
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
@abstractmethod
|
|
25
|
+
def device_type(self) -> str:
|
|
26
|
+
"""Return device type code."""
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
@abstractmethod
|
|
31
|
+
def feature_code(self) -> str:
|
|
32
|
+
"""Return feature code."""
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
@abstractmethod
|
|
37
|
+
def attributes(self) -> Dict[str, DeviceAttribute]:
|
|
38
|
+
"""Return device attributes."""
|
|
39
|
+
pass
|
|
40
|
+
def remove_attribute(self, key: str) -> None:
|
|
41
|
+
"""移除指定的属性"""
|
|
42
|
+
attributes = self.attributes
|
|
43
|
+
if key in attributes:
|
|
44
|
+
del attributes[key]
|
|
45
|
+
|
|
46
|
+
def parse_status(self, status: Dict[str, Any]) -> Dict[str, Any]:
|
|
47
|
+
"""Parse device status."""
|
|
48
|
+
_LOGGER.debug(
|
|
49
|
+
"Parsing status for device type %s-%s with attributes: %s",
|
|
50
|
+
self.device_type,
|
|
51
|
+
self.feature_code,
|
|
52
|
+
{k: attr.name for k, attr in self.attributes.items()}
|
|
53
|
+
)
|
|
54
|
+
_LOGGER.debug("Raw status: %s", status)
|
|
55
|
+
|
|
56
|
+
parsed_status = {}
|
|
57
|
+
for key, attr in self.attributes.items():
|
|
58
|
+
if key in status:
|
|
59
|
+
value = status[key]
|
|
60
|
+
try:
|
|
61
|
+
if attr.value_map and value in attr.value_map:
|
|
62
|
+
parsed_value = attr.value_map[value]
|
|
63
|
+
# _LOGGER.debug(
|
|
64
|
+
# "Mapped attribute %s (%s) from %s to %s",
|
|
65
|
+
# key, attr.name, value, parsed_value
|
|
66
|
+
# )
|
|
67
|
+
elif attr.attr_type == "Number":
|
|
68
|
+
parsed_value = float(value)
|
|
69
|
+
# _LOGGER.debug(
|
|
70
|
+
# "Converted attribute %s (%s) to number: %s",
|
|
71
|
+
# key, attr.name, parsed_value
|
|
72
|
+
# )
|
|
73
|
+
else:
|
|
74
|
+
parsed_value = value
|
|
75
|
+
# _LOGGER.debug(
|
|
76
|
+
# "Using raw value for attribute %s (%s): %s",
|
|
77
|
+
# key, attr.name, parsed_value
|
|
78
|
+
# )
|
|
79
|
+
parsed_status[key] = parsed_value
|
|
80
|
+
except (ValueError, TypeError) as err:
|
|
81
|
+
_LOGGER.warning(
|
|
82
|
+
"Failed to parse attribute %s (%s) with value %s: %s",
|
|
83
|
+
key, attr.name, value, err
|
|
84
|
+
)
|
|
85
|
+
continue
|
|
86
|
+
|
|
87
|
+
_LOGGER.debug("Parsed status: %s", parsed_status)
|
|
88
|
+
return parsed_status
|
|
89
|
+
|
|
90
|
+
def validate_value(self, key: str, value: Any) -> bool:
|
|
91
|
+
"""Validate value for a given attribute."""
|
|
92
|
+
if key not in self.attributes:
|
|
93
|
+
_LOGGER.warning("Attribute %s not found in device type %s-%s",
|
|
94
|
+
key, self.device_type, self.feature_code)
|
|
95
|
+
return False
|
|
96
|
+
|
|
97
|
+
attr = self.attributes[key]
|
|
98
|
+
if attr.read_write == "R":
|
|
99
|
+
_LOGGER.warning("Attribute %s (%s) is read-only", key, attr.name)
|
|
100
|
+
return False
|
|
101
|
+
|
|
102
|
+
if attr.value_range:
|
|
103
|
+
try:
|
|
104
|
+
min_val, max_val = map(float, attr.value_range.split(","))
|
|
105
|
+
value = float(value)
|
|
106
|
+
valid = min_val <= value <= max_val
|
|
107
|
+
if not valid:
|
|
108
|
+
_LOGGER.warning(
|
|
109
|
+
"Value %s for attribute %s (%s) is outside valid range %s-%s",
|
|
110
|
+
value, key, attr.name, min_val, max_val
|
|
111
|
+
)
|
|
112
|
+
return valid
|
|
113
|
+
except (ValueError, TypeError) as err:
|
|
114
|
+
_LOGGER.warning(
|
|
115
|
+
"Failed to validate range for attribute %s (%s): %s",
|
|
116
|
+
key, attr.name, err
|
|
117
|
+
)
|
|
118
|
+
return False
|
|
119
|
+
|
|
120
|
+
if attr.value_map:
|
|
121
|
+
valid = str(value) in attr.value_map.keys()
|
|
122
|
+
if not valid:
|
|
123
|
+
_LOGGER.warning(
|
|
124
|
+
"Value %s for attribute %s (%s) is not in valid map %s",
|
|
125
|
+
value, key, attr.name, list(attr.value_map.keys())
|
|
126
|
+
)
|
|
127
|
+
return valid
|
|
128
|
+
|
|
129
|
+
return True
|