Skip to content

Commit

Permalink
feat: add battery
Browse files Browse the repository at this point in the history
  • Loading branch information
acesyde committed May 8, 2023
1 parent 65141ea commit 61d3dbc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions custom_components/mylight_systems/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,11 @@ async def async_get_battery_state(
if device["deviceId"] == battery_id:
for state in device["sensorStates"]:
if state["sensorId"] == battery_id + "-soc":
measure.type = state["type"]
measure.unit = state["unit"]
measure.value = state["value"]
measure = Measure(
state["measure"]["type"],
state["measure"]["value"],
state["measure"]["unit"],
)
return measure

return measure
6 changes: 3 additions & 3 deletions custom_components/mylight_systems/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.const import PERCENTAGE, POWER_WATT, UnitOfEnergy
from homeassistant.const import PERCENTAGE, POWER_KILO_WATT, UnitOfEnergy

from .const import DOMAIN
from .coordinator import (
Expand Down Expand Up @@ -130,9 +130,9 @@ class MyLightSensorEntityDescription(
key="battery_state",
name="Battery state",
icon="mdi:battery",
native_unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_KILO_WATT,
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda data: float(data.battery_state.value / 3600)
value_fn=lambda data: round(data.battery_state.value / 36e2 / 1e3, 2)
if data.battery_state is not None
else 0,
),
Expand Down

0 comments on commit 61d3dbc

Please sign in to comment.