python-siseli 0.2.1__tar.gz → 0.2.2__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.
- {python_siseli-0.2.1 → python_siseli-0.2.2}/PKG-INFO +1 -1
- {python_siseli-0.2.1 → python_siseli-0.2.2}/pyproject.toml +1 -1
- {python_siseli-0.2.1 → python_siseli-0.2.2}/python_siseli.egg-info/PKG-INFO +1 -1
- {python_siseli-0.2.1 → python_siseli-0.2.2}/python_siseli.egg-info/SOURCES.txt +1 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/models/state.py +59 -0
- python_siseli-0.2.2/tests/test_normalized_telemetry.py +88 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/README.md +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/python_siseli.egg-info/dependency_links.txt +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/python_siseli.egg-info/requires.txt +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/python_siseli.egg-info/top_level.txt +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/setup.cfg +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/__init__.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/_utils.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/alarms.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/auth.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/client.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/config.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/const.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/dashboard.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/device.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/dictionary.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/exceptions.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/history.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/models/__init__.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/models/alarm.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/models/auth.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/models/common.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/models/config.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/models/dashboard.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/models/device.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/models/dictionary.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/models/history.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/models/station.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/open_auth.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/state.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/siseli/station.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/tests/test_auth.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/tests/test_open_auth.py +0 -0
- {python_siseli-0.2.1 → python_siseli-0.2.2}/tests/test_phase3.py +0 -0
|
@@ -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:
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Tests for semantic device telemetry normalization."""
|
|
2
|
+
|
|
3
|
+
from datetime import UTC, datetime
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from siseli.models.state import DeviceState, StateAttribute
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def make_state(values: dict) -> DeviceState:
|
|
11
|
+
fields = {
|
|
12
|
+
key: StateAttribute(
|
|
13
|
+
key=key,
|
|
14
|
+
unit="",
|
|
15
|
+
value=value,
|
|
16
|
+
value_display=str(value),
|
|
17
|
+
name_display=key,
|
|
18
|
+
is_hidden=False,
|
|
19
|
+
)
|
|
20
|
+
for key, value in values.items()
|
|
21
|
+
}
|
|
22
|
+
return DeviceState(time=datetime.now(UTC), fields=fields, raw={})
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_to_sensor_data_maps_fields_and_converts_power_units() -> None:
|
|
26
|
+
result = make_state(
|
|
27
|
+
{
|
|
28
|
+
"batteryCapacity": 85,
|
|
29
|
+
"batteryVoltage": 52.1,
|
|
30
|
+
"batteryChargingCurrent": 10.5,
|
|
31
|
+
"batteryDischargeCurrent": 0,
|
|
32
|
+
"pvInputVoltage1": 380,
|
|
33
|
+
"pv1InputCurrentForBattery": 3.2,
|
|
34
|
+
"generationPower": 1.216,
|
|
35
|
+
"gridVoltage": 230,
|
|
36
|
+
"gridFrequency": 50,
|
|
37
|
+
"acOutputVoltage": 230,
|
|
38
|
+
"acOutputFrequency": 50,
|
|
39
|
+
"acOutputActivePower": 0.420,
|
|
40
|
+
"workingMode": "B",
|
|
41
|
+
}
|
|
42
|
+
).to_sensor_data()
|
|
43
|
+
|
|
44
|
+
assert result["battery_soc"] == pytest.approx(85)
|
|
45
|
+
assert result["battery_voltage"] == pytest.approx(52.1)
|
|
46
|
+
assert result["pv_voltage"] == pytest.approx(380)
|
|
47
|
+
assert result["pv_current"] == pytest.approx(3.2)
|
|
48
|
+
assert result["grid_voltage"] == pytest.approx(230)
|
|
49
|
+
assert result["grid_frequency"] == pytest.approx(50)
|
|
50
|
+
assert result["output_voltage"] == pytest.approx(230)
|
|
51
|
+
assert result["output_frequency"] == pytest.approx(50)
|
|
52
|
+
assert result["battery_current"] == pytest.approx(10.5)
|
|
53
|
+
assert result["battery_power"] == pytest.approx(547.05)
|
|
54
|
+
assert result["pv_power"] == pytest.approx(1216)
|
|
55
|
+
assert result["load_power"] == pytest.approx(420)
|
|
56
|
+
assert result["inverter_state"] == "B"
|
|
57
|
+
assert "grid_power" not in result
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_to_sensor_data_handles_discharge_and_invalid_values() -> None:
|
|
61
|
+
result = make_state(
|
|
62
|
+
{
|
|
63
|
+
"batteryVoltage": 52.1,
|
|
64
|
+
"batteryChargingCurrent": 0,
|
|
65
|
+
"batteryDischargeCurrent": 4.2,
|
|
66
|
+
"pvInputVoltage1": "--",
|
|
67
|
+
"pv1InputCurrentForBattery": True,
|
|
68
|
+
"generationPower": float("nan"),
|
|
69
|
+
"acOutputActivePower": "not available",
|
|
70
|
+
"workingMode": "B",
|
|
71
|
+
}
|
|
72
|
+
).to_sensor_data()
|
|
73
|
+
|
|
74
|
+
assert result["battery_current"] == pytest.approx(-4.2)
|
|
75
|
+
assert result["battery_power"] == pytest.approx(-52.1 * 4.2)
|
|
76
|
+
assert result["pv_voltage"] is None
|
|
77
|
+
assert result["pv_current"] is None
|
|
78
|
+
assert result["pv_power"] is None
|
|
79
|
+
assert result["load_power"] is None
|
|
80
|
+
assert result["inverter_state"] == "B"
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_to_sensor_data_returns_none_when_derived_inputs_missing() -> None:
|
|
84
|
+
result = make_state(
|
|
85
|
+
{"batteryVoltage": 12.8, "batteryChargingCurrent": 1}
|
|
86
|
+
).to_sensor_data()
|
|
87
|
+
assert result["battery_current"] is None
|
|
88
|
+
assert result["battery_power"] is None
|
|
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
|
|
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
|
|
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
|