Whrilpool add periodic update (#97222)

pull/97241/head
mkmer 2023-07-25 16:23:31 -04:00 committed by GitHub
parent 234715a8c6
commit c6f21b47a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -70,6 +70,7 @@ ICON_D = "mdi:tumble-dryer"
ICON_W = "mdi:washing-machine"
_LOGGER = logging.getLogger(__name__)
SCAN_INTERVAL = timedelta(minutes=5)
def washer_state(washer: WasherDryer) -> str | None:
@ -228,7 +229,7 @@ class WasherDryerClass(SensorEntity):
class WasherDryerTimeClass(RestoreSensor):
"""A timestamp class for the whirlpool/maytag washer account."""
_attr_should_poll = False
_attr_should_poll = True
_attr_has_entity_name = True
def __init__(
@ -272,6 +273,10 @@ class WasherDryerTimeClass(RestoreSensor):
"""Return True if entity is available."""
return self._wd.get_online()
async def async_update(self) -> None:
"""Update status of Whirlpool."""
await self._wd.fetch_data()
@callback
def update_from_latest_data(self) -> None:
"""Calculate the time stamp for completion."""

View File

@ -4,13 +4,14 @@ from unittest.mock import MagicMock
from whirlpool.washerdryer import MachineState
from homeassistant.components.whirlpool.sensor import SCAN_INTERVAL
from homeassistant.core import CoreState, HomeAssistant, State
from homeassistant.helpers import entity_registry as er
from homeassistant.util.dt import as_timestamp, utc_from_timestamp
from homeassistant.util.dt import as_timestamp, utc_from_timestamp, utcnow
from . import init_integration
from tests.common import mock_restore_cache_with_extra_data
from tests.common import async_fire_time_changed, mock_restore_cache_with_extra_data
async def update_sensor_state(
@ -132,6 +133,12 @@ async def test_washer_sensor_values(
await init_integration(hass)
async_fire_time_changed(
hass,
utcnow() + SCAN_INTERVAL,
)
await hass.async_block_till_done()
entity_id = "sensor.washer_state"
mock_instance = mock_sensor1_api
entry = entity_registry.async_get(entity_id)