Fix Watergate Power supply mode description and MQTT/Wifi uptimes (#135085)

This commit is contained in:
adam-the-hero 2025-01-14 14:40:01 +01:00 committed by GitHub
parent 38d008bb66
commit 026df07451
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 7 deletions

View File

@ -90,7 +90,7 @@ DESCRIPTIONS: list[WatergateSensorEntityDescription] = [
WatergateSensorEntityDescription( WatergateSensorEntityDescription(
value_fn=lambda data: ( value_fn=lambda data: (
dt_util.as_utc( dt_util.as_utc(
dt_util.now() - timedelta(microseconds=data.networking.wifi_uptime) dt_util.now() - timedelta(milliseconds=data.networking.wifi_uptime)
) )
if data.networking if data.networking
else None else None
@ -104,7 +104,7 @@ DESCRIPTIONS: list[WatergateSensorEntityDescription] = [
WatergateSensorEntityDescription( WatergateSensorEntityDescription(
value_fn=lambda data: ( value_fn=lambda data: (
dt_util.as_utc( dt_util.as_utc(
dt_util.now() - timedelta(microseconds=data.networking.mqtt_uptime) dt_util.now() - timedelta(milliseconds=data.networking.mqtt_uptime)
) )
if data.networking if data.networking
else None else None
@ -158,7 +158,11 @@ DESCRIPTIONS: list[WatergateSensorEntityDescription] = [
), ),
WatergateSensorEntityDescription( WatergateSensorEntityDescription(
value_fn=lambda data: ( value_fn=lambda data: (
PowerSupplyMode(data.state.power_supply.replace("+", "_")) PowerSupplyMode(
data.state.power_supply.replace("+", "_").replace(
"external_battery", "battery_external"
)
)
if data.state if data.state
else None else None
), ),

View File

@ -43,7 +43,7 @@
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': '2021-01-09T11:59:59+00:00', 'state': '2021-01-09T11:59:58+00:00',
}) })
# --- # ---
# name: test_sensor[sensor.sonic_power_supply_mode-entry] # name: test_sensor[sensor.sonic_power_supply_mode-entry]
@ -501,6 +501,6 @@
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': '2021-01-09T11:59:59+00:00', 'state': '2021-01-09T11:59:57+00:00',
}) })
# --- # ---

View File

@ -140,11 +140,11 @@ async def test_power_supply_webhook(
power_supply_change_data = { power_supply_change_data = {
"type": "power-supply-changed", "type": "power-supply-changed",
"data": {"supply": "external"}, "data": {"supply": "external_battery"},
} }
client = await hass_client_no_auth() client = await hass_client_no_auth()
await client.post(f"/api/webhook/{MOCK_WEBHOOK_ID}", json=power_supply_change_data) await client.post(f"/api/webhook/{MOCK_WEBHOOK_ID}", json=power_supply_change_data)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get(entity_id).state == "external" assert hass.states.get(entity_id).state == "battery_external"