mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 07:05:48 +01:00
Set sensors to unknown when no next alarm is set in Sleep as Android (#150558)
This commit is contained in:
@@ -85,6 +85,12 @@ class SleepAsAndroidSensorEntity(SleepAsAndroidEntity, RestoreSensor):
|
||||
):
|
||||
self._attr_native_value = label
|
||||
|
||||
if (
|
||||
data[ATTR_EVENT] == "alarm_rescheduled"
|
||||
and data.get(ATTR_VALUE1) is None
|
||||
):
|
||||
self._attr_native_value = None
|
||||
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
|
||||
@@ -122,3 +122,45 @@ async def test_webhook_sensor(
|
||||
|
||||
assert (state := hass.states.get("sensor.sleep_as_android_alarm_label"))
|
||||
assert state.state == "label"
|
||||
|
||||
|
||||
async def test_webhook_sensor_alarm_unset(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
) -> None:
|
||||
"""Test unsetting sensors if there is no next alarm."""
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
client = await hass_client_no_auth()
|
||||
|
||||
response = await client.post(
|
||||
"/api/webhook/webhook_id",
|
||||
json={
|
||||
"event": "alarm_rescheduled",
|
||||
"value1": "1582719660934",
|
||||
"value2": "label",
|
||||
},
|
||||
)
|
||||
assert response.status == HTTPStatus.NO_CONTENT
|
||||
|
||||
assert (state := hass.states.get("sensor.sleep_as_android_next_alarm"))
|
||||
assert state.state == "2020-02-26T12:21:00+00:00"
|
||||
|
||||
assert (state := hass.states.get("sensor.sleep_as_android_alarm_label"))
|
||||
assert state.state == "label"
|
||||
|
||||
response = await client.post(
|
||||
"/api/webhook/webhook_id",
|
||||
json={"event": "alarm_rescheduled"},
|
||||
)
|
||||
assert (state := hass.states.get("sensor.sleep_as_android_next_alarm"))
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
assert (state := hass.states.get("sensor.sleep_as_android_alarm_label"))
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
Reference in New Issue
Block a user