diff --git a/homeassistant/components/econet/__init__.py b/homeassistant/components/econet/__init__.py index 36cdeb688218a..67cbd7496e32b 100644 --- a/homeassistant/components/econet/__init__.py +++ b/homeassistant/components/econet/__init__.py @@ -1,4 +1,5 @@ """Support for EcoNet products.""" +import asyncio from datetime import timedelta import logging @@ -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 diff --git a/homeassistant/components/econet/climate.py b/homeassistant/components/econet/climate.py index e77c4face7477..f5328da47764a 100644 --- a/homeassistant/components/econet/climate.py +++ b/homeassistant/components/econet/climate.py @@ -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): diff --git a/homeassistant/components/econet/water_heater.py b/homeassistant/components/econet/water_heater.py index cbaf4551d0316..a99ab08772917 100644 --- a/homeassistant/components/econet/water_heater.py +++ b/homeassistant/components/econet/water_heater.py @@ -1,4 +1,5 @@ """Support for Rheem EcoNet water heaters.""" +from datetime import timedelta import logging from typing import Any @@ -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 = { @@ -52,6 +55,7 @@ async def async_setup_entry( EcoNetWaterHeater(water_heater) for water_heater in equipment[EquipmentType.WATER_HEATER] ], + update_before_add=True, ) @@ -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.""" @@ -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."""