Skip to content

Commit

Permalink
Merge pull request #64 from faanskit/dev
Browse files Browse the repository at this point in the history
Added new attributes
  • Loading branch information
faanskit authored Feb 8, 2024
2 parents 0d6f40f + 527abe0 commit 4d114f9
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 1 deletion.
16 changes: 16 additions & 0 deletions custom_components/checkwatt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ class CheckwattResp(TypedDict):
charge_peak_dc: float
discharge_peak_ac: float
discharge_peak_dc: float
monthly_grid_peak_power: float

today_net_revenue: float
tomorrow_net_revenue: float
monthly_net_revenue: float
annual_net_revenue: float
month_estimate: float
Expand All @@ -100,6 +102,7 @@ class CheckwattResp(TypedDict):
fcr_d_status: str
fcr_d_info: str
fcr_d_date: str
reseller_id: int


async def update_listener(hass: HomeAssistant, entry):
Expand Down Expand Up @@ -317,10 +320,12 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
self.update_all = 0
self.random_offset = random.randint(0, 14)
self.fcrd_today_net_revenue = None
self.fcrd_tomorrow_net_revenue = None
self.fcrd_month_net_revenue = None
self.fcrd_month_net_estimate = None
self.fcrd_daily_net_average = None
self.fcrd_year_net_revenue = None
self.monthly_grid_peak_power = None

@property
def entry_id(self) -> str:
Expand Down Expand Up @@ -373,11 +378,19 @@ async def _async_update_data(self) -> CheckwattResp: # noqa: C901
if not await cw_inst.get_fcrd_year_net_revenue():
raise UpdateFailed("Unknown error get_revenue_year")

_LOGGER.debug("Fetching montly peak power")
if not await cw_inst.get_battery_month_peak_effect():
raise UpdateFailed(
"Unknown error get_battery_month_peak_effect"
)

self.fcrd_today_net_revenue = cw_inst.fcrd_today_net_revenue
self.fcrd_tomorrow_net_revenue = cw_inst.fcrd_tomorrow_net_revenue
self.fcrd_month_net_revenue = cw_inst.fcrd_month_net_revenue
self.fcrd_month_net_estimate = cw_inst.fcrd_month_net_estimate
self.fcrd_daily_net_average = cw_inst.fcrd_daily_net_average
self.fcrd_year_net_revenue = cw_inst.fcrd_year_net_revenue
self.monthly_grid_peak_power = cw_inst.month_peak_effect

if not self.is_boot:
self.update_all -= 1
Expand Down Expand Up @@ -426,6 +439,7 @@ async def _async_update_data(self) -> CheckwattResp: # noqa: C901
"display_name": cw_inst.display_name,
"dso": cw_inst.battery_registration["Dso"],
"energy_provider": self.energy_provider,
"reseller_id": cw_inst.reseller_id,
}
if cw_inst.energy_data is not None:
resp["battery_power"] = cw_inst.battery_power
Expand All @@ -436,10 +450,12 @@ async def _async_update_data(self) -> CheckwattResp: # noqa: C901
resp["charge_peak_dc"] = cw_inst.battery_charge_peak_dc
resp["discharge_peak_ac"] = cw_inst.battery_discharge_peak_ac
resp["discharge_peak_dc"] = cw_inst.battery_discharge_peak_dc
resp["monthly_grid_peak_power"] = self.monthly_grid_peak_power

# Use self stored variant of revenue parameters as they are not always fetched
if self.fcrd_today_net_revenue is not None:
resp["today_net_revenue"] = self.fcrd_today_net_revenue
resp["tomorrow_net_revenue"] = self.fcrd_tomorrow_net_revenue
if self.fcrd_month_net_revenue is not None:
resp["monthly_net_revenue"] = self.fcrd_month_net_revenue
resp["month_estimate"] = self.fcrd_month_net_estimate
Expand Down
3 changes: 3 additions & 0 deletions custom_components/checkwatt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@
C_MONTH_ESITIMATE = "month_estimate"
C_NEXT_UPDATE_TIME = "next_update"
C_PRICE_ZONE = "price_zone"
C_RESELLER_ID = "reseller_id"
C_SOLAR_POWER = "solar_power"
C_UPDATE_TIME = "last_update"
C_TOMORROW_REVENUE = "tomorrow_net_revenue"
C_VAT = "vat"
C_ZIP = "zip_code"
C_CHARGE_PEAK_AC = "charge_peak_ac"
C_CHARGE_PEAK_DC = "charge_peak_dc"
C_DISCHARGE_PEAK_AC = "discharge_peak_ac"
C_DISCHARGE_PEAK_DC = "discharge_peak_dc"
C_MONTHLY_GRID_PEAK_POWER = "monthly_grid_peak_power"

# CheckWatt Event Signals
EVENT_SIGNAL_FCRD = "fcrd"
2 changes: 1 addition & 1 deletion custom_components/checkwatt/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"homekit": {},
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/faanskit/ha-checkwatt/issues",
"requirements": ["pycheckwatt>=0.2.2", "aiohttp>=3.9.1"],
"requirements": ["pycheckwatt>=0.2.3", "aiohttp>=3.9.1"],
"ssdp": [],
"version": "0.2.1",
"zeroconf": []
Expand Down
35 changes: 35 additions & 0 deletions custom_components/checkwatt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@
C_FCRD_STATUS,
C_GRID_POWER,
C_MONTH_ESITIMATE,
C_MONTHLY_GRID_PEAK_POWER,
C_NEXT_UPDATE_TIME,
C_PRICE_ZONE,
C_RESELLER_ID,
C_SOLAR_POWER,
C_TOMORROW_REVENUE,
C_UPDATE_TIME,
C_VAT,
C_ZIP,
Expand Down Expand Up @@ -280,6 +283,10 @@ def __init__(
self._attr_extra_state_attributes.update(
{C_ENERGY_PROVIDER: self._coordinator.data["energy_provider"]}
)
if "tomorrow_net_revenue" in self._coordinator.data:
self._attr_extra_state_attributes.update(
{C_TOMORROW_REVENUE: self._coordinator.data["tomorrow_net_revenue"]}
)
if "update_time" in self._coordinator.data:
self._attr_extra_state_attributes.update(
{C_UPDATE_TIME: self._coordinator.data["update_time"]}
Expand All @@ -306,6 +313,10 @@ def _handle_coordinator_update(self) -> None:
self._attr_extra_state_attributes.update(
{C_NEXT_UPDATE_TIME: self._coordinator.data["next_update_time"]}
)
if "tomorrow_net_revenue" in self._coordinator.data:
self._attr_extra_state_attributes.update(
{C_TOMORROW_REVENUE: self._coordinator.data["tomorrow_net_revenue"]}
)
super()._handle_coordinator_update()

@property
Expand Down Expand Up @@ -510,6 +521,14 @@ async def async_update(self) -> None:
self._attr_extra_state_attributes.update(
{C_DISCHARGE_PEAK_DC: self._coordinator.data["discharge_peak_dc"]}
)
if "monthly_grid_peak_power" in self._coordinator.data:
self._attr_extra_state_attributes.update(
{
C_MONTHLY_GRID_PEAK_POWER: self._coordinator.data[
"monthly_grid_peak_power"
]
}
)
self._attr_available = True

@callback
Expand Down Expand Up @@ -545,6 +564,14 @@ def _handle_coordinator_update(self) -> None:
self._attr_extra_state_attributes.update(
{C_DISCHARGE_PEAK_DC: self._coordinator.data["discharge_peak_dc"]}
)
if "monthly_grid_peak_power" in self._coordinator.data:
self._attr_extra_state_attributes.update(
{
C_MONTHLY_GRID_PEAK_POWER: self._coordinator.data[
"monthly_grid_peak_power"
]
}
)
super()._handle_coordinator_update()

@property
Expand Down Expand Up @@ -582,6 +609,10 @@ async def async_update(self) -> None:
self._attr_extra_state_attributes.update(
{C_FCRD_DATE: self._coordinator.data["fcr_d_date"]}
)
if "reseller_id" in self._coordinator.data:
self._attr_extra_state_attributes.update(
{C_RESELLER_ID: self._coordinator.data["reseller_id"]}
)
self._attr_available = True

@callback
Expand Down Expand Up @@ -609,6 +640,10 @@ def _handle_coordinator_update(self) -> None:
self._attr_extra_state_attributes.update(
{C_FCRD_DATE: self._coordinator.data["fcr_d_date"]}
)
if "reseller_id" in self._coordinator.data:
self._attr_extra_state_attributes.update(
{C_RESELLER_ID: self._coordinator.data["reseller_id"]}
)
super()._handle_coordinator_update()

@property
Expand Down
9 changes: 9 additions & 0 deletions custom_components/checkwatt/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
"energy_provider": {
"name": "Energy Provider"
},
"tomorrow_net_revenue": {
"name": "Tomorrow Net Income"
},
"last_update": {
"name": "Last update"
},
Expand Down Expand Up @@ -136,6 +139,9 @@
},
"discharge_peak_dc": {
"name": "Discharge Peak DC"
},
"monthly_grid_peak_power": {
"name": "Montly Peak Grid Power"
}
}
},
Expand All @@ -153,6 +159,9 @@
},
"fcr_d_date": {
"name": "FCR-D Date"
},
"reseller_id": {
"name": "Partner Id"
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions custom_components/checkwatt/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
"energy_provider": {
"name": "Energy Provider"
},
"tomorrow_net_revenue": {
"name": "Tomorrow Net Income"
},
"last_update": {
"name": "Last update"
},
Expand Down Expand Up @@ -136,6 +139,9 @@
},
"discharge_peak_dc": {
"name": "Discharge Peak DC"
},
"monthly_grid_peak_power": {
"name": "Montly Peak Grid Power"
}
}
},
Expand All @@ -153,6 +159,9 @@
},
"fcr_d_date": {
"name": "FCR-D Date"
},
"reseller_id": {
"name": "Partner Id"
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions custom_components/checkwatt/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
"energy_provider": {
"name": "Elhandelsbolag"
},
"tomorrow_net_revenue": {
"name": "Intäkt imorgon"
},
"last_update": {
"name": "Senaste uppdateringen"
},
Expand Down Expand Up @@ -136,6 +139,9 @@
},
"discharge_peak_dc": {
"name": "Urladdningstopp DC"
},
"monthly_grid_peak_power": {
"name": "Månadens maximala näteffekt"
}
}
},
Expand All @@ -153,6 +159,9 @@
},
"fcr_d_date": {
"name": "FCR-D Datum"
},
"reseller_id": {
"name": "Partner Id"
}
}
}
Expand Down

0 comments on commit 4d114f9

Please sign in to comment.