pyimouapi 1.2.5__tar.gz → 1.2.6__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.
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/PKG-INFO +1 -1
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/pyimouapi/const.py +9 -1
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/pyimouapi/ha_device.py +56 -3
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/pyimouapi.egg-info/PKG-INFO +1 -1
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/setup.py +1 -1
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/LICENSE +0 -0
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/README.md +0 -0
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/pyimouapi/__init__.py +0 -0
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/pyimouapi/device.py +0 -0
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/pyimouapi/exceptions.py +0 -0
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/pyimouapi/openapi.py +0 -0
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/pyimouapi.egg-info/SOURCES.txt +0 -0
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/pyimouapi.egg-info/dependency_links.txt +0 -0
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/pyimouapi.egg-info/requires.txt +0 -0
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/pyimouapi.egg-info/top_level.txt +0 -0
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/pyproject.toml +0 -0
- {pyimouapi-1.2.5 → pyimouapi-1.2.6}/setup.cfg +0 -0
|
@@ -413,7 +413,15 @@ SENSOR_TYPE_REF = {
|
|
|
413
413
|
"expression": "('e1' if data['14603']==0 else 'e2') if data['14603'] != 1 else int(data['14602'] / data['14601'] * 100)",
|
|
414
414
|
}
|
|
415
415
|
],
|
|
416
|
-
"battery": [
|
|
416
|
+
"battery": [
|
|
417
|
+
{"ref": "11600", "default": "15", "ref_type": "properties"},
|
|
418
|
+
{
|
|
419
|
+
"ref": "106200",
|
|
420
|
+
"default": "0",
|
|
421
|
+
"ref_type": "properties",
|
|
422
|
+
"expression": "battery_106200(data)",
|
|
423
|
+
},
|
|
424
|
+
],
|
|
417
425
|
"temperature_current": [
|
|
418
426
|
{"ref": "16000", "default": "10", "ref_type": "properties"}
|
|
419
427
|
],
|
|
@@ -69,6 +69,53 @@ from simpleeval import SimpleEval
|
|
|
69
69
|
|
|
70
70
|
_LOGGER: logging.Logger = logging.getLogger(__package__)
|
|
71
71
|
|
|
72
|
+
|
|
73
|
+
def _battery_level_from_106200_list(data) -> int:
|
|
74
|
+
"""解析 ref 106200 电量属性: [{"106202": 电池类型, "106203": 电量}, ...]。
|
|
75
|
+
多条时取 106202==0 的 106203;仅一条时取该条的 106203。
|
|
76
|
+
键均为字符串。
|
|
77
|
+
"""
|
|
78
|
+
if not isinstance(data, list) or not data:
|
|
79
|
+
return 0
|
|
80
|
+
|
|
81
|
+
k_type, k_level = "106202", "106203"
|
|
82
|
+
|
|
83
|
+
def _to_int(v):
|
|
84
|
+
if v is None:
|
|
85
|
+
return None
|
|
86
|
+
if isinstance(v, bool):
|
|
87
|
+
return int(v)
|
|
88
|
+
if isinstance(v, int):
|
|
89
|
+
return v
|
|
90
|
+
if isinstance(v, float):
|
|
91
|
+
return int(v)
|
|
92
|
+
try:
|
|
93
|
+
return int(str(v).strip())
|
|
94
|
+
except ValueError:
|
|
95
|
+
return None
|
|
96
|
+
|
|
97
|
+
if len(data) == 1:
|
|
98
|
+
row = data[0]
|
|
99
|
+
if not isinstance(row, dict):
|
|
100
|
+
return 0
|
|
101
|
+
level = _to_int(row.get(k_level))
|
|
102
|
+
return level if level is not None else 0
|
|
103
|
+
|
|
104
|
+
for row in data:
|
|
105
|
+
if not isinstance(row, dict):
|
|
106
|
+
continue
|
|
107
|
+
if _to_int(row.get(k_type)) == 0:
|
|
108
|
+
level = _to_int(row.get(k_level))
|
|
109
|
+
if level is not None:
|
|
110
|
+
return level
|
|
111
|
+
|
|
112
|
+
row0 = data[0]
|
|
113
|
+
if not isinstance(row0, dict):
|
|
114
|
+
return 0
|
|
115
|
+
level = _to_int(row0.get(k_level))
|
|
116
|
+
return level if level is not None else 0
|
|
117
|
+
|
|
118
|
+
|
|
72
119
|
NUMBER_TYPE = [
|
|
73
120
|
PARAM_STORAGE_USED,
|
|
74
121
|
PARAM_TEMPERATURE_CURRENT,
|
|
@@ -412,9 +459,15 @@ class ImouHaDeviceManager(object):
|
|
|
412
459
|
return devices
|
|
413
460
|
|
|
414
461
|
@staticmethod
|
|
415
|
-
def get_expression_value(expression: str, data
|
|
462
|
+
def get_expression_value(expression: str, data):
|
|
416
463
|
s = SimpleEval(
|
|
417
|
-
names={"data": data},
|
|
464
|
+
names={"data": data},
|
|
465
|
+
functions={
|
|
466
|
+
"round": round,
|
|
467
|
+
"int": int,
|
|
468
|
+
"str": str,
|
|
469
|
+
"battery_106200": _battery_level_from_106200_list,
|
|
470
|
+
},
|
|
418
471
|
)
|
|
419
472
|
return s.eval(expression)
|
|
420
473
|
|
|
@@ -1040,7 +1093,7 @@ class ImouHaDeviceManager(object):
|
|
|
1040
1093
|
device_id, device.channel_id, device.product_id, [value[PARAM_REF]]
|
|
1041
1094
|
)
|
|
1042
1095
|
data = result[PARAM_PROPERTIES][value[PARAM_REF]]
|
|
1043
|
-
if value.get(PARAM_EXPRESSION) and isinstance(data, dict):
|
|
1096
|
+
if value.get(PARAM_EXPRESSION) and isinstance(data, (dict, list)):
|
|
1044
1097
|
state = self.get_expression_value(value[PARAM_EXPRESSION], data)
|
|
1045
1098
|
else:
|
|
1046
1099
|
state = data
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|