Skip to content

Commit

Permalink
fix: Fixed issue with increased debug logging. Also reduced default l…
Browse files Browse the repository at this point in the history
…ogging to debug level
  • Loading branch information
BottlecapDave committed Oct 27, 2022
1 parent a4b8af6 commit 2add166
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion custom_components/octopus_energy/__init__.py
Expand Up @@ -84,7 +84,7 @@ async def async_update_electricity_rates_data():
if (DATA_RATES not in hass.data[DOMAIN] or (current.minute % 30) == 0 or len(hass.data[DOMAIN][DATA_RATES]) == 0):

tariff_codes = await async_get_current_electricity_agreement_tariff_codes(client, config)
_LOGGER.info(f'tariff_codes: {tariff_codes}')
_LOGGER.debug(f'tariff_codes: {tariff_codes}')

period_from = as_utc(current.replace(hour=0, minute=0, second=0, microsecond=0))
period_to = as_utc((current + timedelta(days=2)).replace(hour=0, minute=0, second=0, microsecond=0))
Expand All @@ -96,6 +96,7 @@ async def async_update_electricity_rates_data():
if new_rates != None:
rates[key] = new_rates
elif (DATA_RATES in hass.data[DOMAIN] and key in hass.data[DOMAIN][DATA_RATES]):
_LOGGER.debug(f"Failed to retrieve new rates for {tariff_code}, so using cached rates")
rates[key] = hass.data[DOMAIN][DATA_RATES][key]

hass.data[DOMAIN][DATA_RATES] = rates
Expand Down
6 changes: 3 additions & 3 deletions custom_components/octopus_energy/binary_sensor.py
Expand Up @@ -101,7 +101,7 @@ def is_on(self):
# Find the current rate. Rates change a maximum of once every 30 minutes.
current_date = utcnow()
if (current_date.minute % 30) == 0 or len(self._target_rates) == 0:
_LOGGER.info(f'Updating OctopusEnergyTargetRate {self._config[CONFIG_TARGET_NAME]}')
_LOGGER.debug(f'Updating OctopusEnergyTargetRate {self._config[CONFIG_TARGET_NAME]}')

# If all of our target times have passed, it's time to recalculate the next set
all_rates_in_past = True
Expand All @@ -117,12 +117,12 @@ def is_on(self):
all_rates = self.coordinator.data
if len(all_rates) == 1 or CONFIG_TARGET_MPAN not in self._config:
all_rates = next(iter(all_rates.values()))
else:
else:
all_rates = all_rates.get(self._config[CONFIG_TARGET_MPAN])
else:
all_rates = []

_LOGGER.debug(f'{len(all_rates)} rate periods found for meter {self._config[CONFIG_TARGET_MPAN]}')
_LOGGER.debug(f'{len(all_rates) if all_rates != None else None} rate periods found for meter {self._config[CONFIG_TARGET_MPAN]}')

start_time = None
if CONFIG_TARGET_START_TIME in self._config:
Expand Down
14 changes: 7 additions & 7 deletions custom_components/octopus_energy/sensor.py
Expand Up @@ -227,7 +227,7 @@ def state(self):
# Find the current rate. We only need to do this every half an hour
now = utcnow()
if (now.minute % 30) == 0 or self._state == None:
_LOGGER.info(f"Updating OctopusEnergyElectricityCurrentRate for '{self._mpan}/{self._serial_number}'")
_LOGGER.debug(f"Updating OctopusEnergyElectricityCurrentRate for '{self._mpan}/{self._serial_number}'")

current_rate = None
if self.coordinator.data != None:
Expand Down Expand Up @@ -305,7 +305,7 @@ def state(self):
# Find the previous rate. We only need to do this every half an hour
now = utcnow()
if (now.minute % 30) == 0 or self._state == None:
_LOGGER.info(f"Updating OctopusEnergyElectricityPreviousRate for '{self._mpan}/{self._serial_number}'")
_LOGGER.debug(f"Updating OctopusEnergyElectricityPreviousRate for '{self._mpan}/{self._serial_number}'")

target = now - timedelta(minutes=30)

Expand Down Expand Up @@ -387,7 +387,7 @@ def state(self):
)

if (consumption != None and len(consumption["consumptions"]) > 2):
_LOGGER.info(f"Calculated previous electricity consumption for '{self._mpan}/{self._serial_number}'...")
_LOGGER.debug(f"Calculated previous electricity consumption for '{self._mpan}/{self._serial_number}'...")
self._state = consumption["total"]
self._latest_date = consumption["last_calculated_timestamp"]

Expand Down Expand Up @@ -477,7 +477,7 @@ async def async_update(self):
)

if (consumption_cost != None and len(consumption_cost["charges"]) > 2):
_LOGGER.info(f"Calculated previous electricity consumption cost for '{self._mpan}/{self._serial_number}'...")
_LOGGER.debug(f"Calculated previous electricity consumption cost for '{self._mpan}/{self._serial_number}'...")
self._latest_date = consumption_cost["last_calculated_timestamp"]
self._state = consumption_cost["total"]

Expand Down Expand Up @@ -571,7 +571,7 @@ async def async_update(self):

utc_now = utcnow()
if (self._latest_date == None or (self._latest_date + timedelta(days=1)) < utc_now):
_LOGGER.info('Updating OctopusEnergyGasCurrentRate')
_LOGGER.debug('Updating OctopusEnergyGasCurrentRate')

period_from = as_utc(parse_datetime(utc_now.strftime("%Y-%m-%dT00:00:00Z")))
period_to = as_utc(parse_datetime((utc_now + timedelta(days=1)).strftime("%Y-%m-%dT00:00:00Z")))
Expand Down Expand Up @@ -653,7 +653,7 @@ def state(self):
)

if (consumption != None and len(consumption["consumptions"]) > 2):
_LOGGER.info(f"Calculated previous gas consumption for '{self._mprn}/{self._serial_number}'...")
_LOGGER.debug(f"Calculated previous gas consumption for '{self._mprn}/{self._serial_number}'...")
self._state = consumption["total_m3"]
self._latest_date = consumption["last_calculated_timestamp"]

Expand Down Expand Up @@ -745,7 +745,7 @@ async def async_update(self):
)

if (consumption_cost != None and len(consumption_cost["charges"]) > 2):
_LOGGER.info(f"Calculated previous gas consumption cost for '{self._mprn}/{self._serial_number}'...")
_LOGGER.debug(f"Calculated previous gas consumption cost for '{self._mprn}/{self._serial_number}'...")
self._latest_date = consumption_cost["last_calculated_timestamp"]
self._state = consumption_cost["total"]

Expand Down

0 comments on commit 2add166

Please sign in to comment.