Skip to content

Commit

Permalink
Fixed CRW push
Browse files Browse the repository at this point in the history
  • Loading branch information
faanskit committed Jan 28, 2024
1 parent 39aa48f commit efb436e
Showing 1 changed file with 15 additions and 11 deletions.
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

0 comments on commit efb436e

Please sign in to comment.