Skip to content

Commit

Permalink
Added grid and solar power attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
faanskit committed Jan 4, 2024
1 parent 8315d1e commit b0c693b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
4 changes: 4 additions & 0 deletions custom_components/checkwatt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class CheckwattResp(TypedDict):
price_zone: str
annual_revenue: float
annual_fees: float
grid_power: float
solar_power: float
battery_power: float
battery_soc: float
dso: str
Expand Down Expand Up @@ -229,6 +231,8 @@ async def _async_update_data(self) -> CheckwattResp:
}
if cw_inst.energy_data is not None:
resp["battery_power"] = cw_inst.battery_power
resp["grid_power"] = cw_inst.grid_power
resp["solar_power"] = cw_inst.solar_power
resp["battery_soc"] = cw_inst.battery_soc

# Use self stored variant of revenue parameters as they are not always fetched
Expand Down
2 changes: 2 additions & 0 deletions custom_components/checkwatt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
C_DISCHARGE_PEAK = "discharge_peak"
C_DISPLAY_NAME = "display_name"
C_DSO = "dso"
C_GRID_POWER = "grid_power"
C_ENERGY_PROVIDER = "energy_provider"
C_FCRD_DATE = "fcr_d_date"
C_FCRD_STATE = "fcr_d_state"
C_FCRD_STATUS = "fcr_d_status"
C_NEXT_UPDATE_TIME = "next_update"
C_PRICE_ZONE = "price_zone"
C_SOLAR_POWER = "solar_power"
C_TODAY_FEES = "today_fees"
C_TODAY_FEE_RATE = "today_fees_rate"
C_TODAY_GROSS = "today_gross_income"
Expand Down
4 changes: 2 additions & 2 deletions custom_components/checkwatt/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"homekit": {},
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/faanskit/ha-checkwatt/issues",
"requirements": ["pycheckwatt>=0.1.6", "aiohttp>=3.9.1"],
"requirements": ["pycheckwatt>=0.1.7", "aiohttp>=3.9.1"],
"ssdp": [],
"version": "0.1.4",
"version": "0.1.5-RC.1",
"zeroconf": []
}
18 changes: 18 additions & 0 deletions custom_components/checkwatt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
C_FCRD_DATE,
C_FCRD_STATE,
C_FCRD_STATUS,
C_GRID_POWER,
C_NEXT_UPDATE_TIME,
C_PRICE_ZONE,
C_SOLAR_POWER,
C_TODAY_FEE_RATE,
C_TODAY_FEES,
C_TODAY_GROSS,
Expand Down Expand Up @@ -647,6 +649,14 @@ async def async_update(self) -> None:
self._attr_extra_state_attributes.update(
{C_BATTERY_POWER: self._coordinator.data["battery_power"]}
)
if "grid_power" in self._coordinator.data:
self._attr_extra_state_attributes.update(
{C_GRID_POWER: self._coordinator.data["grid_power"]}
)
if "solar_power" in self._coordinator.data:
self._attr_extra_state_attributes.update(
{C_SOLAR_POWER: self._coordinator.data["solar_power"]}
)
self._attr_available = True

@callback
Expand All @@ -658,6 +668,14 @@ def _handle_coordinator_update(self) -> None:
self._attr_extra_state_attributes.update(
{C_BATTERY_POWER: self._coordinator.data["battery_power"]}
)
if "grid_power" in self._coordinator.data:
self._attr_extra_state_attributes.update(
{C_GRID_POWER: self._coordinator.data["grid_power"]}
)
if "solar_power" in self._coordinator.data:
self._attr_extra_state_attributes.update(
{C_SOLAR_POWER: self._coordinator.data["solar_power"]}
)
super()._handle_coordinator_update()

@property
Expand Down
6 changes: 6 additions & 0 deletions custom_components/checkwatt/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@
"state_attributes": {
"battery_power": {
"name": "Battery Power"
},
"grid_power": {
"name": "Grid Power"
},
"solar_power": {
"name": "Solar Power"
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions custom_components/checkwatt/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@
"state_attributes": {
"battery_power": {
"name": "Battery Power"
},
"grid_power": {
"name": "Grid Power"
},
"solar_power": {
"name": "Solar Power"
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions custom_components/checkwatt/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@
"state_attributes": {
"battery_power": {
"name": "Batterieffekt"
},
"grid_power": {
"name": "Näteffekt"
},
"solar_power": {
"name": "Solcellseffekt"
}
}
}
Expand Down

0 comments on commit b0c693b

Please sign in to comment.