Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for additional sensor attributes (dso, provider, etc.) #44

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions custom_components/checkwatt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
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 @@ -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"
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.5"],
"requirements": ["pycheckwatt>=0.1.6"],
"ssdp": [],
"version": "0.1.2",
"version": "0.1.3",
"zeroconf": []
}
15 changes: 15 additions & 0 deletions custom_components/checkwatt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"]}
Expand All @@ -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"]
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 @@ -36,6 +36,9 @@
"daily_yield_sensor": {
"name": "CheckWatt Daily Net Income",
"state_attributes": {
"display_name": {
"name": "Facility"
},
"street_address": {
"name": "Street Address"
},
Expand All @@ -45,6 +48,12 @@
"city": {
"name": "City"
},
"dso": {
"name": "Distribution System Operator"
},
"energy_provider": {
"name": "Energy Provider"
},
"today_gross_income": {
"name": "Today Gross Income"
},
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 @@ -36,6 +36,9 @@
"daily_yield_sensor": {
"name": "CheckWatt Daily Net Income",
"state_attributes": {
"display_name": {
"name": "Facility"
},
"street_address": {
"name": "Street Address"
},
Expand All @@ -45,6 +48,12 @@
"city": {
"name": "City"
},
"dso": {
"name": "Distribution System Operator"
},
"energy_provider": {
"name": "Energy Provider"
},
"today_gross_income": {
"name": "Today Gross Income"
},
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 @@ -36,6 +36,9 @@
"daily_yield_sensor": {
"name": "CheckWatt Daglig Intäkt",
"state_attributes": {
"display_name": {
"name": "Anläggning"
},
"street_address": {
"name": "Adress"
},
Expand All @@ -45,6 +48,12 @@
"city": {
"name": "Stad"
},
"dso": {
"name": "Nätägare"
},
"energy_provider": {
"name": "Elhandelsbolag"
},
"today_gross_income": {
"name": "Dagens Bruttoinkomst"
},
Expand Down
Loading