Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/modules/devices/sonnen/sonnenbatterie/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,19 @@ def __state_from_channel(self, channel: ChannelDict) -> Union[CounterState, Inve
ValueError: If the direction is neither "consumption" nor "production".
"""
if channel["direction"] == self.PowerMeterDirection.CONSUMPTION.value:
powers = [channel[f"w_l{phase}"] for phase in range(1, 4)]
currents = [channel[f"a_l{phase}"] for phase in range(1, 4)]
voltages = [channel[f"v_l{phase}_n"] for phase in range(1, 4)]
power_factors = [
powers[phase] / (voltages[phase] * currents[phase])
if voltages[phase] and currents[phase] else None
for phase in range(0, 3)
]
return CounterState(power=channel["w_total"],
powers=[channel[f"w_l{phase}"] for phase in range(1, 4)],
currents=[channel[f"a_l{phase}"] for phase in range(1, 4)],
voltages=[channel[f"v_l{phase}_n"] for phase in range(1, 4)],
powers=powers,
currents=currents,
voltages=voltages,
power_factors=power_factors,
imported=channel["kwh_imported"] * 1000,
exported=channel["kwh_exported"] * 1000)
elif channel["direction"] == self.PowerMeterDirection.PRODUCTION.value:
Expand Down