Skip to content

Commit

Permalink
feat: green energy
Browse files Browse the repository at this point in the history
  • Loading branch information
btpemercier committed May 3, 2023
1 parent 006e0bc commit f37fe3d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions custom_components/mylight_systems/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MyLightSystemsCoordinatorData(NamedTuple):
self_conso: Measure
msb_charge: Measure
msb_discharge: Measure
green_energy: Measure


# https://developers.home-assistant.io/docs/integration_fetching_data#coordinated-single-api-poll-for-data-for-all-entities
Expand Down Expand Up @@ -94,6 +95,9 @@ async def _async_update_data(self) -> MyLightSystemsCoordinatorData:
msb_discharge=self.find_measure_by_type(
result, "msb_discharge"
),
green_energy=self.find_measure_by_type(
result, "green_energy"
),
)
except (
UnauthorizedException,
Expand Down
19 changes: 15 additions & 4 deletions custom_components/mylight_systems/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MyLightSensorEntityDescription(
MYLIGHT_SENSORS: tuple[MyLightSensorEntityDescription, ...] = (
MyLightSensorEntityDescription(
key="total_solar_production",
name="Total solar power production",
name="Solar power production",
icon="mdi:solar-panel",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING,
Expand All @@ -62,7 +62,7 @@ class MyLightSensorEntityDescription(
),
MyLightSensorEntityDescription(
key="total_grid_without_battery_consumption",
name="Total power consumption from the grid without virtual battery",
name="Grid power consumption",
icon="mdi:transmission-tower",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING,
Expand Down Expand Up @@ -95,7 +95,7 @@ class MyLightSensorEntityDescription(
),
MyLightSensorEntityDescription(
key="total_msb_charge",
name="Total My Smart Battery Charge",
name="Battery Charge",
icon="mdi:battery-high",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING,
Expand All @@ -106,7 +106,7 @@ class MyLightSensorEntityDescription(
),
MyLightSensorEntityDescription(
key="total_msb_discharge",
name="Total My Smart Battery Discharge",
name="Battery Discharge",
icon="mdi:battery-low",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING,
Expand All @@ -115,6 +115,17 @@ class MyLightSensorEntityDescription(
if data.msb_discharge is not None
else 0,
),
MyLightSensorEntityDescription(
key="total_green_energy",
name="Green energy",
icon="mdi:solar-panel",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
value_fn=lambda data: round(data.green_energy.value / 36e2, 2)
if data.green_energy is not None
else 0,
),
)


Expand Down

0 comments on commit f37fe3d

Please sign in to comment.