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 CRW push #55

Merged
merged 1 commit into from
Jan 28, 2024
Merged
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
26 changes: 15 additions & 11 deletions custom_components/checkwatt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import asyncio
from datetime import time, timedelta
import logging
import random
from typing import TypedDict

import aiohttp
Expand Down Expand Up @@ -156,6 +157,7 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
self.fcrd_timestamp = None
self._id = None
self.update_all = 0
self.random_offset = random.randint(0, 14)
self.fcrd_today_net_revenue = None
self.fcrd_month_net_revenue = None
self.fcrd_month_net_estimate = None
Expand Down Expand Up @@ -236,6 +238,12 @@ async def _async_update_data(self) -> CheckwattResp: # noqa: C901
# Store fcrd_state at boot, used to spark event
self.fcrd_state = cw_inst.fcrd_state
self._id = cw_inst.customer_details["Id"]
(
charge_peak_ac,
charge_peak_dc,
discharge_peak_ac,
discharge_peak_dc,
) = await getPeakData(cw_inst)

# Price Zone is used both as Detailed Sensor and by Push to CheckWattRank
if push_to_cw_rank or use_power_sensors:
Expand All @@ -255,7 +263,9 @@ async def _async_update_data(self) -> CheckwattResp: # noqa: C901
!= dt_util.start_of_local_day(self.last_cw_rank_push)
):
_LOGGER.debug("Pushing to CheckWattRank")
if await self.push_to_checkwatt_rank(cw_inst, cwr_name):
if await self.push_to_checkwatt_rank(
cw_inst, charge_peak_ac, cwr_name
):
self.last_cw_rank_push = dt_util.now()

resp: CheckwattResp = {
Expand All @@ -274,12 +284,6 @@ async def _async_update_data(self) -> CheckwattResp: # noqa: C901
resp["grid_power"] = cw_inst.grid_power
resp["solar_power"] = cw_inst.solar_power
resp["battery_soc"] = cw_inst.battery_soc
(
charge_peak_ac,
charge_peak_dc,
discharge_peak_ac,
discharge_peak_dc,
) = await getPeakData(cw_inst)
resp["charge_peak_ac"] = charge_peak_ac
resp["charge_peak_dc"] = charge_peak_dc
resp["discharge_peak_ac"] = discharge_peak_ac
Expand Down Expand Up @@ -376,9 +380,9 @@ async def _async_update_data(self) -> CheckwattResp: # noqa: C901
except CheckwattError as err:
raise UpdateFailed(str(err)) from err

async def push_to_checkwatt_rank(self, cw_inst, cwr_name):
async def push_to_checkwatt_rank(self, cw_inst, charge_peak, cwr_name):
"""Push data to CheckWattRank."""
if self.today_net_revenue is not None:
if self.fcrd_today_net_revenue is not None:
if (
"Meter" in cw_inst.customer_details
and len(cw_inst.customer_details["Meter"]) > 0
Expand All @@ -391,10 +395,10 @@ async def push_to_checkwatt_rank(self, cw_inst, cwr_name):
"dso": cw_inst.battery_registration["Dso"],
"electricity_company": self.energy_provider,
"electricity_area": cw_inst.price_zone,
"installed_power": cw_inst.battery_charge_peak,
"installed_power": charge_peak,
"today_gross_income": 0,
"today_fee": 0,
"today_net_income": self.today_net_revenue,
"today_net_income": self.fcrd_today_net_revenue,
"reseller_id": cw_inst.customer_details["Meter"][0]["ResellerId"],
}
if BASIC_TEST:
Expand Down
Loading