mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Restore sleepy oralb devices state at startup (#97983)
This commit is contained in:
parent
b7f936fcdd
commit
56c2276630
@ -111,7 +111,9 @@ async def async_setup_entry(
|
|||||||
OralBBluetoothSensorEntity, async_add_entities
|
OralBBluetoothSensorEntity, async_add_entities
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
entry.async_on_unload(coordinator.async_register_processor(processor))
|
entry.async_on_unload(
|
||||||
|
coordinator.async_register_processor(processor, SensorEntityDescription)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class OralBBluetoothSensorEntity(
|
class OralBBluetoothSensorEntity(
|
||||||
|
@ -9,7 +9,10 @@ from homeassistant.components.bluetooth import (
|
|||||||
async_address_present,
|
async_address_present,
|
||||||
)
|
)
|
||||||
from homeassistant.components.oralb.const import DOMAIN
|
from homeassistant.components.oralb.const import DOMAIN
|
||||||
from homeassistant.const import ATTR_ASSUMED_STATE, ATTR_FRIENDLY_NAME
|
from homeassistant.const import (
|
||||||
|
ATTR_ASSUMED_STATE,
|
||||||
|
ATTR_FRIENDLY_NAME,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
@ -31,6 +34,7 @@ async def test_sensors(
|
|||||||
hass: HomeAssistant, entity_registry_enabled_by_default: None
|
hass: HomeAssistant, entity_registry_enabled_by_default: None
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setting up creates the sensors."""
|
"""Test setting up creates the sensors."""
|
||||||
|
start_monotonic = time.monotonic()
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
unique_id=ORALB_SERVICE_INFO.address,
|
unique_id=ORALB_SERVICE_INFO.address,
|
||||||
@ -59,6 +63,30 @@ async def test_sensors(
|
|||||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# Fastforward time without BLE advertisements
|
||||||
|
monotonic_now = start_monotonic + FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS + 1
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.bluetooth.manager.MONOTONIC_TIME",
|
||||||
|
return_value=monotonic_now,
|
||||||
|
), patch_all_discovered_devices([]):
|
||||||
|
async_fire_time_changed(
|
||||||
|
hass,
|
||||||
|
dt_util.utcnow()
|
||||||
|
+ timedelta(seconds=FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS + 1),
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# All of these devices are sleepy so we should still be available
|
||||||
|
toothbrush_sensor = hass.states.get(
|
||||||
|
"sensor.smart_series_7000_48be_toothbrush_state"
|
||||||
|
)
|
||||||
|
toothbrush_sensor_attrs = toothbrush_sensor.attributes
|
||||||
|
assert toothbrush_sensor.state == "running"
|
||||||
|
|
||||||
|
|
||||||
async def test_sensors_io_series_4(
|
async def test_sensors_io_series_4(
|
||||||
hass: HomeAssistant, entity_registry_enabled_by_default: None
|
hass: HomeAssistant, entity_registry_enabled_by_default: None
|
||||||
@ -103,6 +131,11 @@ async def test_sensors_io_series_4(
|
|||||||
async_address_present(hass, ORALB_IO_SERIES_4_SERVICE_INFO.address) is False
|
async_address_present(hass, ORALB_IO_SERIES_4_SERVICE_INFO.address) is False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
toothbrush_sensor = hass.states.get("sensor.io_series_4_48be_mode")
|
toothbrush_sensor = hass.states.get("sensor.io_series_4_48be_mode")
|
||||||
# Sleepy devices should keep their state over time
|
# Sleepy devices should keep their state over time
|
||||||
assert toothbrush_sensor.state == "gum care"
|
assert toothbrush_sensor.state == "gum care"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user