Skip to content

Commit

Permalink
Poll econet water heater once an hour (home-assistant#90961)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingSquirrel authored Nov 27, 2023
1 parent 669b347 commit b4553f1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
8 changes: 3 additions & 5 deletions homeassistant/components/econet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for EcoNet products."""
import asyncio
from datetime import timedelta
import logging

Expand Down Expand Up @@ -80,14 +81,11 @@ async def resubscribe(now):
await hass.async_add_executor_job(api.unsubscribe)
api.subscribe()

async def fetch_update(now):
"""Fetch the latest changes from the API."""
# Refresh values
await asyncio.sleep(60)
await api.refresh_equipment()

config_entry.async_on_unload(async_track_time_interval(hass, resubscribe, INTERVAL))
config_entry.async_on_unload(
async_track_time_interval(hass, fetch_update, INTERVAL + timedelta(minutes=1))
)

return True

Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/econet/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async def async_setup_entry(
class EcoNetThermostat(EcoNetEntity, ClimateEntity):
"""Define an Econet thermostat."""

_attr_should_poll = True
_attr_temperature_unit = UnitOfTemperature.FAHRENHEIT

def __init__(self, thermostat):
Expand Down
18 changes: 5 additions & 13 deletions homeassistant/components/econet/water_heater.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Rheem EcoNet water heaters."""
from datetime import timedelta
import logging
from typing import Any

Expand All @@ -17,12 +18,14 @@
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, STATE_OFF, UnitOfTemperature
from homeassistant.core import HomeAssistant, callback
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import EcoNetEntity
from .const import DOMAIN, EQUIPMENT

SCAN_INTERVAL = timedelta(hours=1)

_LOGGER = logging.getLogger(__name__)

ECONET_STATE_TO_HA = {
Expand Down Expand Up @@ -52,6 +55,7 @@ async def async_setup_entry(
EcoNetWaterHeater(water_heater)
for water_heater in equipment[EquipmentType.WATER_HEATER]
],
update_before_add=True,
)


Expand All @@ -64,18 +68,8 @@ class EcoNetWaterHeater(EcoNetEntity, WaterHeaterEntity):
def __init__(self, water_heater):
"""Initialize."""
super().__init__(water_heater)
self._running = water_heater.running
self.water_heater = water_heater

@callback
def on_update_received(self):
"""Update was pushed from the econet API."""
if self._running != self.water_heater.running:
# Water heater running state has changed so check usage on next update
self._attr_should_poll = True
self._running = self.water_heater.running
self.async_write_ha_state()

@property
def is_away_mode_on(self):
"""Return true if away mode is on."""
Expand Down Expand Up @@ -153,8 +147,6 @@ async def async_update(self) -> None:
"""Get the latest energy usage."""
await self.water_heater.get_energy_usage()
await self.water_heater.get_water_usage()
self.async_write_ha_state()
self._attr_should_poll = False

def turn_away_mode_on(self) -> None:
"""Turn away mode on."""
Expand Down

0 comments on commit b4553f1

Please sign in to comment.