mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Whrilpool add periodic update (#97222)
This commit is contained in:
parent
234715a8c6
commit
c6f21b47a8
@ -70,6 +70,7 @@ ICON_D = "mdi:tumble-dryer"
|
|||||||
ICON_W = "mdi:washing-machine"
|
ICON_W = "mdi:washing-machine"
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
SCAN_INTERVAL = timedelta(minutes=5)
|
||||||
|
|
||||||
|
|
||||||
def washer_state(washer: WasherDryer) -> str | None:
|
def washer_state(washer: WasherDryer) -> str | None:
|
||||||
@ -228,7 +229,7 @@ class WasherDryerClass(SensorEntity):
|
|||||||
class WasherDryerTimeClass(RestoreSensor):
|
class WasherDryerTimeClass(RestoreSensor):
|
||||||
"""A timestamp class for the whirlpool/maytag washer account."""
|
"""A timestamp class for the whirlpool/maytag washer account."""
|
||||||
|
|
||||||
_attr_should_poll = False
|
_attr_should_poll = True
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -272,6 +273,10 @@ class WasherDryerTimeClass(RestoreSensor):
|
|||||||
"""Return True if entity is available."""
|
"""Return True if entity is available."""
|
||||||
return self._wd.get_online()
|
return self._wd.get_online()
|
||||||
|
|
||||||
|
async def async_update(self) -> None:
|
||||||
|
"""Update status of Whirlpool."""
|
||||||
|
await self._wd.fetch_data()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def update_from_latest_data(self) -> None:
|
def update_from_latest_data(self) -> None:
|
||||||
"""Calculate the time stamp for completion."""
|
"""Calculate the time stamp for completion."""
|
||||||
|
@ -4,13 +4,14 @@ from unittest.mock import MagicMock
|
|||||||
|
|
||||||
from whirlpool.washerdryer import MachineState
|
from whirlpool.washerdryer import MachineState
|
||||||
|
|
||||||
|
from homeassistant.components.whirlpool.sensor import SCAN_INTERVAL
|
||||||
from homeassistant.core import CoreState, HomeAssistant, State
|
from homeassistant.core import CoreState, HomeAssistant, State
|
||||||
from homeassistant.helpers import entity_registry as er
|
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 . 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(
|
async def update_sensor_state(
|
||||||
@ -132,6 +133,12 @@ async def test_washer_sensor_values(
|
|||||||
|
|
||||||
await init_integration(hass)
|
await init_integration(hass)
|
||||||
|
|
||||||
|
async_fire_time_changed(
|
||||||
|
hass,
|
||||||
|
utcnow() + SCAN_INTERVAL,
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entity_id = "sensor.washer_state"
|
entity_id = "sensor.washer_state"
|
||||||
mock_instance = mock_sensor1_api
|
mock_instance = mock_sensor1_api
|
||||||
entry = entity_registry.async_get(entity_id)
|
entry = entity_registry.async_get(entity_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user