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

Fixed additional Dso related bugs. #67

Merged
merged 2 commits into from
Feb 12, 2024
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
25 changes: 20 additions & 5 deletions custom_components/checkwatt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ async def update_history_items(call: ServiceCall) -> ServiceResponse:
)

async with CheckWattRankManager() as cwr:
dso = ""
if cw.battery_registration is not None:
if "Dso" in cw.battery_registration:
dso = cw.battery_registration["Dso"]

(
status,
stored_items,
Expand All @@ -177,10 +182,13 @@ async def update_history_items(call: ServiceCall) -> ServiceResponse:
display_name=(
cwr_name if cwr_name != "" else cw.display_name
),
dso=cw.battery_registration["Dso"],
dso=dso,
electricity_company=energy_provider,
electricity_area=cw.price_zone,
installed_power=cw.battery_charge_peak_ac,
installed_power=min(
cw.battery_charge_peak_ac,
cw.battery_discharge_peak_ac,
),
reseller_id=cw.reseller_id,
reporter=CHECKWATTRANK_REPORTER,
historical_data=hd,
Expand Down Expand Up @@ -284,12 +292,18 @@ async def push_to_checkwatt_rank(cw_inst, cwr_name, today_net_income):
cw_inst.energy_provider_id
)
async with CheckWattRankManager() as cwr:
dso = ""
if cw_inst.battery_registration is not None:
if "Dso" in cw_inst.battery_registration:
dso = cw_inst.battery_registration["Dso"]
if await cwr.push_to_checkwatt_rank(
display_name=(cwr_name if cwr_name != "" else cw_inst.display_name),
dso=cw_inst.battery_registration["Dso"],
dso=dso,
electricity_company=energy_provider,
electricity_area=cw_inst.price_zone,
installed_power=cw_inst.battery_charge_peak_ac,
installed_power=min(
cw_inst.battery_charge_peak_ac, cw_inst.battery_discharge_peak_ac
),
today_net_income=today_net_income,
reseller_id=cw_inst.reseller_id,
reporter=CHECKWATTRANK_REPORTER,
Expand Down Expand Up @@ -441,7 +455,8 @@ async def _async_update_data(self) -> CheckwattResp: # noqa: C901
"reseller_id": cw_inst.reseller_id,
}
if cw_inst.battery_registration is not None:
resp["dso"] = cw_inst.battery_registration["Dso"]
if "Dso" in cw_inst.battery_registration:
resp["dso"] = cw_inst.battery_registration["Dso"]
if cw_inst.energy_data is not None:
resp["battery_power"] = cw_inst.battery_power
resp["grid_power"] = cw_inst.grid_power
Expand Down
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.4", "aiohttp>=3.9.1"],
"requirements": ["pycheckwatt>=0.2.5", "aiohttp>=3.9.1"],
"ssdp": [],
"version": "0.2.1",
"zeroconf": []
Expand Down
12 changes: 8 additions & 4 deletions custom_components/checkwatt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,10 @@ async def async_update(self) -> None:
@callback
def _handle_coordinator_update(self) -> None:
"""Get the latest data and updates the states."""
self._attr_native_value = round(
self._coordinator.data["monthly_net_revenue"], 2
)
if "monthly_net_revenue" in self._coordinator.data:
self._attr_native_value = round(
self._coordinator.data["monthly_net_revenue"], 2
)
if "month_estimate" in self._coordinator.data:
self._attr_extra_state_attributes.update(
{C_MONTH_ESITIMATE: round(self._coordinator.data["month_estimate"], 2)}
Expand Down Expand Up @@ -398,7 +399,10 @@ async def async_update(self) -> None:
@callback
def _handle_coordinator_update(self) -> None:
"""Get the latest data and updates the states."""
self._attr_native_value = round(self._coordinator.data["annual_net_revenue"], 2)
if "annual_net_revenue" in self._coordinator.data:
self._attr_native_value = round(
self._coordinator.data["annual_net_revenue"], 2
)
super()._handle_coordinator_update()

@property
Expand Down
Loading