Home Assistant Unofficial Reference 2024.12.1
valve.py
Go to the documentation of this file.
1 """Support for Hydrawise sprinkler valves."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from pydrawise.schema import Zone
8 
10  ValveDeviceClass,
11  ValveEntity,
12  ValveEntityDescription,
13  ValveEntityFeature,
14 )
15 from homeassistant.config_entries import ConfigEntry
16 from homeassistant.core import HomeAssistant
17 from homeassistant.helpers.entity_platform import AddEntitiesCallback
18 
19 from .const import DOMAIN
20 from .coordinator import HydrawiseUpdateCoordinators
21 from .entity import HydrawiseEntity
22 
23 VALVE_TYPES: tuple[ValveEntityDescription, ...] = (
25  key="zone",
26  device_class=ValveDeviceClass.WATER,
27  ),
28 )
29 
30 
32  hass: HomeAssistant,
33  config_entry: ConfigEntry,
34  async_add_entities: AddEntitiesCallback,
35 ) -> None:
36  """Set up the Hydrawise valve platform."""
37  coordinators: HydrawiseUpdateCoordinators = hass.data[DOMAIN][config_entry.entry_id]
39  HydrawiseValve(coordinators.main, description, controller, zone_id=zone.id)
40  for controller in coordinators.main.data.controllers.values()
41  for zone in controller.zones
42  for description in VALVE_TYPES
43  )
44 
45 
47  """A Hydrawise valve."""
48 
49  _attr_name = None
50  _attr_reports_position = False
51  _attr_supported_features = ValveEntityFeature.OPEN | ValveEntityFeature.CLOSE
52  zone: Zone
53 
54  async def async_open_valve(self, **kwargs: Any) -> None:
55  """Open the valve."""
56  await self.coordinator.api.start_zone(self.zonezone)
57 
58  async def async_close_valve(self) -> None:
59  """Close the valve."""
60  await self.coordinator.api.stop_zone(self.zonezone)
61 
62  def _update_attrs(self) -> None:
63  """Update state attributes."""
64  self._attr_is_closed_attr_is_closed = self.zonezone.scheduled_runs.current_run is None
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: valve.py:35