Add active watering time sensor to Hydrawise (#120177)

This commit is contained in:
Thomas Kistler 2024-06-26 00:24:48 -07:00 committed by GitHub
parent 30e0bcb324
commit bff9d12cc0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 263 additions and 51 deletions

View file

@ -3,7 +3,7 @@
from collections.abc import Awaitable, Callable
from unittest.mock import patch
from pydrawise.schema import Controller, User, Zone
from pydrawise.schema import Controller, ControllerWaterUseSummary, User, Zone
import pytest
from syrupy.assertion import SnapshotAssertion
@ -53,10 +53,15 @@ async def test_suspended_state(
async def test_no_sensor_and_water_state(
hass: HomeAssistant,
controller: Controller,
controller_water_use_summary: ControllerWaterUseSummary,
mock_add_config_entry: Callable[[], Awaitable[MockConfigEntry]],
) -> None:
"""Test rain sensor, flow sensor, and water use in the absence of flow and rain sensors."""
controller.sensors = []
controller_water_use_summary.total_use = None
controller_water_use_summary.total_active_use = None
controller_water_use_summary.total_inactive_use = None
controller_water_use_summary.active_use_by_zone_id = {}
await mock_add_config_entry()
assert hass.states.get("sensor.zone_one_daily_active_water_use") is None
@ -65,6 +70,18 @@ async def test_no_sensor_and_water_state(
assert hass.states.get("sensor.home_controller_daily_inactive_water_use") is None
assert hass.states.get("binary_sensor.home_controller_rain_sensor") is None
sensor = hass.states.get("sensor.home_controller_daily_active_watering_time")
assert sensor is not None
assert sensor.state == "123.0"
sensor = hass.states.get("sensor.zone_one_daily_active_watering_time")
assert sensor is not None
assert sensor.state == "123.0"
sensor = hass.states.get("sensor.zone_two_daily_active_watering_time")
assert sensor is not None
assert sensor.state == "0.0"
sensor = hass.states.get("binary_sensor.home_controller_connectivity")
assert sensor is not None
assert sensor.state == "on"