1 """Support for switch entities."""
3 from __future__
import annotations
7 from gardena_bluetooth.const
import Valve
13 from .
import GardenaBluetoothConfigEntry
14 from .coordinator
import GardenaBluetoothCoordinator
15 from .entity
import GardenaBluetoothEntity
17 FALLBACK_WATERING_TIME_IN_SECONDS = 60 * 60
22 entry: GardenaBluetoothConfigEntry,
23 async_add_entities: AddEntitiesCallback,
25 """Set up switch based on a config entry."""
26 coordinator = entry.runtime_data
28 if GardenaBluetoothValve.characteristics.issubset(coordinator.characteristics):
35 """Representation of a valve switch."""
38 _attr_is_closed: bool |
None =
None
39 _attr_reports_position =
False
40 _attr_supported_features = ValveEntityFeature.OPEN | ValveEntityFeature.CLOSE
44 Valve.manual_watering_time.uuid,
45 Valve.remaining_open_time.uuid,
50 coordinator: GardenaBluetoothCoordinator,
52 """Initialize the switch."""
54 coordinator, {Valve.state.uuid, Valve.manual_watering_time.uuid}
63 """Turn the entity on."""
65 self.coordinator.
get_cached(Valve.manual_watering_time)
66 or FALLBACK_WATERING_TIME_IN_SECONDS
68 await self.coordinator.
write(Valve.remaining_open_time, value)
73 """Turn the entity off."""
74 await self.coordinator.
write(Valve.remaining_open_time, 0)
CharacteristicType|None get_cached(self, Characteristic[CharacteristicType] char)
None write(self, Characteristic[CharacteristicType] char, CharacteristicType value)
None _handle_coordinator_update(self)
None async_open_valve(self, **Any kwargs)
None __init__(self, GardenaBluetoothCoordinator coordinator)
None async_close_valve(self, **Any kwargs)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, GardenaBluetoothConfigEntry entry, AddEntitiesCallback async_add_entities)