Skip to content

Commit

Permalink
Add state sleeping to battery states
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Ott <[email protected]>
  • Loading branch information
DerOetzi committed Aug 18, 2024
1 parent fb39da8 commit 7e1c75f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion solaredge2mqtt/services/modbus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ def _map_batteries(
battery_data = SunSpecBattery(battery_raw)
logger.debug(battery_data)
logger.info(
LOGGING_DEVICE_INFO + ": {power} W, {state_of_charge} %",
LOGGING_DEVICE_INFO + ": {status}, {power} W, {state_of_charge} %",
device=battery_key,
info=battery_data.info,
status=battery_data.status,
power=battery_data.power,
state_of_charge=battery_data.state_of_charge,
)
Expand Down
16 changes: 14 additions & 2 deletions solaredge2mqtt/services/modbus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from influxdb_client import Point
from pydantic import Field
from solaredge_modbus import BATTERY_STATUS_MAP, C_SUNSPEC_DID_MAP, INVERTER_STATUS_MAP
from solaredge_modbus import C_SUNSPEC_DID_MAP, INVERTER_STATUS_MAP

from solaredge2mqtt.core.exceptions import InvalidDataException
from solaredge2mqtt.core.logging import logger
Expand Down Expand Up @@ -132,6 +132,18 @@ def homeassistant_device_info_with_name(self, name: str) -> dict[str, any]:
return self.info.homeassistant_device_info(name)


BATTERY_STATUS_MAP = {
0: "Off",
1: "Standby",
2: "Init",
3: "Charge",
4: "Discharge",
5: "Fault",
6: "Idle",
10: "Power Saving",
}


class SunSpecBattery(SunSpecComponent):
COMPONENT = "battery"

Expand All @@ -146,7 +158,7 @@ def __init__(self, data: dict[str, str | int]) -> None:
if "status" not in data:
raise InvalidDataException("Missing battery status")

if data["status"] not in range(0, len(BATTERY_STATUS_MAP)):
if data["status"] not in BATTERY_STATUS_MAP:
raise InvalidDataException(f"Invalid battery status: {data['status']}")

status = BATTERY_STATUS_MAP[data["status"]]
Expand Down

0 comments on commit 7e1c75f

Please sign in to comment.