diff --git a/custom_components/checkwatt/__init__.py b/custom_components/checkwatt/__init__.py index 36333a2..fa87d5d 100644 --- a/custom_components/checkwatt/__init__.py +++ b/custom_components/checkwatt/__init__.py @@ -59,6 +59,8 @@ class CheckwattResp(TypedDict): annual_fees: float battery_power: float battery_soc: float + dso: str + energy_provider: str async def update_listener(hass: HomeAssistant, entry): @@ -110,6 +112,7 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None: self.annual_fees = None self.last_annual_update = None self.is_boot = True + self.energy_provider = None self.random_offset = random.randint(0, 14) _LOGGER.debug("Fetching annual revenue at 3:%02d am", self.random_offset) @@ -141,6 +144,14 @@ async def _async_update_data(self) -> CheckwattResp: # The revenue sensors will be updated after ca 1 min if self.is_boot: self.is_boot = False + if ( + "Meter" in cw_inst.customer_details + and len(cw_inst.customer_details["Meter"]) > 0 + and "ElhandelsbolagId" in cw_inst.customer_details["Meter"][0] + ): + self.energy_provider = await cw_inst.get_energy_trading_company( + cw_inst.customer_details["Meter"][0]["ElhandelsbolagId"] + ) else: if self.update_monetary == 0: _LOGGER.debug("Fetching FCR-D data from CheckWatt") @@ -195,6 +206,8 @@ async def _async_update_data(self) -> CheckwattResp: "fcr_d_date": cw_inst.fcrd_timestamp, "battery_charge_peak": cw_inst.battery_charge_peak, "battery_discharge_peak": cw_inst.battery_discharge_peak, + "dso": cw_inst.battery_registration["Dso"], + "energy_provider": self.energy_provider, } if cw_inst.energy_data is not None: resp["battery_power"] = cw_inst.battery_power diff --git a/custom_components/checkwatt/const.py b/custom_components/checkwatt/const.py index 0ee4e50..f762a20 100644 --- a/custom_components/checkwatt/const.py +++ b/custom_components/checkwatt/const.py @@ -28,6 +28,9 @@ C_CHARGE_PEAK = "charge_peak" C_CITY = "city" C_DISCHARGE_PEAK = "discharge_peak" +C_DISPLAY_NAME = "display_name" +C_DSO = "dso" +C_ENERGY_PROVIDER = "energy_provider" C_FCRD_DATE = "fcr_d_date" C_FCRD_STATE = "fcr_d_state" C_FCRD_STATUS = "fcr_d_status" diff --git a/custom_components/checkwatt/manifest.json b/custom_components/checkwatt/manifest.json index 05ef18a..21ecd7c 100644 --- a/custom_components/checkwatt/manifest.json +++ b/custom_components/checkwatt/manifest.json @@ -12,8 +12,8 @@ "homekit": {}, "iot_class": "cloud_polling", "issue_tracker": "https://github.com/faanskit/ha-checkwatt/issues", - "requirements": ["pycheckwatt>=0.1.5"], + "requirements": ["pycheckwatt>=0.1.6"], "ssdp": [], - "version": "0.1.2", + "version": "0.1.3", "zeroconf": [] } diff --git a/custom_components/checkwatt/sensor.py b/custom_components/checkwatt/sensor.py index 80f86cd..62f45d9 100644 --- a/custom_components/checkwatt/sensor.py +++ b/custom_components/checkwatt/sensor.py @@ -28,6 +28,9 @@ C_CHARGE_PEAK, C_CITY, C_DISCHARGE_PEAK, + C_DISPLAY_NAME, + C_DSO, + C_ENERGY_PROVIDER, C_FCRD_DATE, C_FCRD_STATE, C_FCRD_STATUS, @@ -241,6 +244,10 @@ def __init__( self._attr_unique_id = f'checkwattUid_{self._coordinator.data["id"]}' self._attr_extra_state_attributes = {} + if "display_name" in self._coordinator.data: + self._attr_extra_state_attributes.update( + {C_DISPLAY_NAME: self._coordinator.data["display_name"]} + ) if "address" in self._coordinator.data: self._attr_extra_state_attributes.update( {C_ADR: self._coordinator.data["address"]} @@ -253,6 +260,14 @@ def __init__( self._attr_extra_state_attributes.update( {C_CITY: self._coordinator.data["city"]} ) + if "dso" in self._coordinator.data: + self._attr_extra_state_attributes.update( + {C_DSO: self._coordinator.data["dso"]} + ) + if "energy_provider" in self._coordinator.data: + self._attr_extra_state_attributes.update( + {C_ENERGY_PROVIDER: self._coordinator.data["energy_provider"]} + ) if "revenue" in self._coordinator.data and "fees" in self._coordinator.data: revenue = self._coordinator.data["revenue"] fees = self._coordinator.data["fees"] diff --git a/custom_components/checkwatt/strings.json b/custom_components/checkwatt/strings.json index e6e3689..3974edb 100644 --- a/custom_components/checkwatt/strings.json +++ b/custom_components/checkwatt/strings.json @@ -36,6 +36,9 @@ "daily_yield_sensor": { "name": "CheckWatt Daily Net Income", "state_attributes": { + "display_name": { + "name": "Facility" + }, "street_address": { "name": "Street Address" }, @@ -45,6 +48,12 @@ "city": { "name": "City" }, + "dso": { + "name": "Distribution System Operator" + }, + "energy_provider": { + "name": "Energy Provider" + }, "today_gross_income": { "name": "Today Gross Income" }, diff --git a/custom_components/checkwatt/translations/en.json b/custom_components/checkwatt/translations/en.json index ba67b10..7ed010b 100644 --- a/custom_components/checkwatt/translations/en.json +++ b/custom_components/checkwatt/translations/en.json @@ -36,6 +36,9 @@ "daily_yield_sensor": { "name": "CheckWatt Daily Net Income", "state_attributes": { + "display_name": { + "name": "Facility" + }, "street_address": { "name": "Street Address" }, @@ -45,6 +48,12 @@ "city": { "name": "City" }, + "dso": { + "name": "Distribution System Operator" + }, + "energy_provider": { + "name": "Energy Provider" + }, "today_gross_income": { "name": "Today Gross Income" }, diff --git a/custom_components/checkwatt/translations/sv.json b/custom_components/checkwatt/translations/sv.json index 7c71b7e..1131a4e 100644 --- a/custom_components/checkwatt/translations/sv.json +++ b/custom_components/checkwatt/translations/sv.json @@ -36,6 +36,9 @@ "daily_yield_sensor": { "name": "CheckWatt Daglig Intäkt", "state_attributes": { + "display_name": { + "name": "Anläggning" + }, "street_address": { "name": "Adress" }, @@ -45,6 +48,12 @@ "city": { "name": "Stad" }, + "dso": { + "name": "Nätägare" + }, + "energy_provider": { + "name": "Elhandelsbolag" + }, "today_gross_income": { "name": "Dagens Bruttoinkomst" },