python-siseli 0.2.1__py3-none-any.whl → 0.2.2__py3-none-any.whl
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.
- {python_siseli-0.2.1.dist-info → python_siseli-0.2.2.dist-info}/METADATA +1 -1
- {python_siseli-0.2.1.dist-info → python_siseli-0.2.2.dist-info}/RECORD +5 -5
- siseli/models/state.py +59 -0
- {python_siseli-0.2.1.dist-info → python_siseli-0.2.2.dist-info}/WHEEL +0 -0
- {python_siseli-0.2.1.dist-info → python_siseli-0.2.2.dist-info}/top_level.txt +0 -0
|
@@ -22,9 +22,9 @@ siseli/models/dashboard.py,sha256=P86feNI8Yn6ADkwDGFQJFUESrKLt6VttGqsEiNzGnZA,11
|
|
|
22
22
|
siseli/models/device.py,sha256=u57-csypaF-c5hAimqb8GIMeZqYZMKMhYFBTVuBRSfQ,657
|
|
23
23
|
siseli/models/dictionary.py,sha256=d6KCu77UMlPcIDON8G3sjuytkSfbI5go1y3I_jAGTX8,422
|
|
24
24
|
siseli/models/history.py,sha256=dx26VWLJosucMvwL36vojvAguvkMiv5GEKTllUtZV0Y,791
|
|
25
|
-
siseli/models/state.py,sha256=
|
|
25
|
+
siseli/models/state.py,sha256=WXONHjGx9Ro87mJqn1Y0T-nt3PJKOTbWXAyzqZ2GX48,4749
|
|
26
26
|
siseli/models/station.py,sha256=02OLINAVblnKkF73ZwKxYvPtUFROsu4-g544oDg8ApA,1783
|
|
27
|
-
python_siseli-0.2.
|
|
28
|
-
python_siseli-0.2.
|
|
29
|
-
python_siseli-0.2.
|
|
30
|
-
python_siseli-0.2.
|
|
27
|
+
python_siseli-0.2.2.dist-info/METADATA,sha256=m7CXqxigJiQL4vA3P9cqZ-RnYJKPwnl9onCyRBbs0Kc,1439
|
|
28
|
+
python_siseli-0.2.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
29
|
+
python_siseli-0.2.2.dist-info/top_level.txt,sha256=Dofr9c7hGvRRV6ij6aoPuAZqxEjkgtsBeN4KtFHbGgo,7
|
|
30
|
+
python_siseli-0.2.2.dist-info/RECORD,,
|
siseli/models/state.py
CHANGED
|
@@ -9,6 +9,19 @@ from typing import Any
|
|
|
9
9
|
from .common import LookupValue
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
def _numeric(value: Any) -> float | None:
|
|
13
|
+
"""Return finite numeric telemetry as a float, otherwise None."""
|
|
14
|
+
if value is None or isinstance(value, bool):
|
|
15
|
+
return None
|
|
16
|
+
try:
|
|
17
|
+
number = float(value)
|
|
18
|
+
except (TypeError, ValueError, OverflowError):
|
|
19
|
+
return None
|
|
20
|
+
if number != number or number in (float("inf"), float("-inf")):
|
|
21
|
+
return None
|
|
22
|
+
return number
|
|
23
|
+
|
|
24
|
+
|
|
12
25
|
@dataclass
|
|
13
26
|
class StateAttribute:
|
|
14
27
|
"""A single telemetry attribute."""
|
|
@@ -76,6 +89,52 @@ class DeviceState:
|
|
|
76
89
|
"""Return an attribute by its key, or *None* if not present."""
|
|
77
90
|
return self.fields.get(key)
|
|
78
91
|
|
|
92
|
+
def to_sensor_data(self) -> dict[str, Any]:
|
|
93
|
+
"""Return stable, typed semantic telemetry fields for integrations.
|
|
94
|
+
|
|
95
|
+
API-specific field names, unit conversions, and derived battery values
|
|
96
|
+
belong here rather than in consumer integrations. Invalid numeric
|
|
97
|
+
telemetry is represented as None. Power values reported in kW by this
|
|
98
|
+
device are converted to W.
|
|
99
|
+
"""
|
|
100
|
+
def value(api_key: str) -> Any:
|
|
101
|
+
attribute = self.fields.get(api_key)
|
|
102
|
+
return attribute.value if attribute is not None else None
|
|
103
|
+
|
|
104
|
+
def number(api_key: str) -> float | None:
|
|
105
|
+
return _numeric(value(api_key))
|
|
106
|
+
|
|
107
|
+
voltage = number("batteryVoltage")
|
|
108
|
+
charging = number("batteryChargingCurrent")
|
|
109
|
+
discharging = number("batteryDischargeCurrent")
|
|
110
|
+
current = (
|
|
111
|
+
charging - discharging
|
|
112
|
+
if charging is not None and discharging is not None
|
|
113
|
+
else None
|
|
114
|
+
)
|
|
115
|
+
pv_power = number("generationPower")
|
|
116
|
+
load_power = number("acOutputActivePower")
|
|
117
|
+
battery_power = (
|
|
118
|
+
voltage * current
|
|
119
|
+
if voltage is not None and current is not None
|
|
120
|
+
else None
|
|
121
|
+
)
|
|
122
|
+
return {
|
|
123
|
+
"battery_soc": number("batteryCapacity"),
|
|
124
|
+
"battery_voltage": voltage,
|
|
125
|
+
"battery_current": current,
|
|
126
|
+
"battery_power": battery_power,
|
|
127
|
+
"pv_voltage": number("pvInputVoltage1"),
|
|
128
|
+
"pv_current": number("pv1InputCurrentForBattery"),
|
|
129
|
+
"pv_power": pv_power * 1000 if pv_power is not None else None,
|
|
130
|
+
"grid_voltage": number("gridVoltage"),
|
|
131
|
+
"grid_frequency": number("gridFrequency"),
|
|
132
|
+
"output_voltage": number("acOutputVoltage"),
|
|
133
|
+
"output_frequency": number("acOutputFrequency"),
|
|
134
|
+
"load_power": load_power * 1000 if load_power is not None else None,
|
|
135
|
+
"inverter_state": value("workingMode"),
|
|
136
|
+
}
|
|
137
|
+
|
|
79
138
|
|
|
80
139
|
@dataclass
|
|
81
140
|
class FlowNode:
|
|
File without changes
|
|
File without changes
|