1 """Valve for Shelly."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
6 from typing
import Any, cast
8 from aioshelly.block_device
import Block
9 from aioshelly.const
import BLOCK_GENERATIONS, MODEL_GAS
14 ValveEntityDescription,
20 from .coordinator
import ShellyBlockCoordinator, ShellyConfigEntry
22 BlockEntityDescription,
23 ShellyBlockAttributeEntity,
24 async_setup_block_attribute_entities,
26 from .utils
import async_remove_shelly_entity, get_device_entry_gen
29 @dataclass(kw_only=True, frozen=True)
31 """Class to describe a BLOCK valve."""
34 GAS_VALVE = BlockValveDescription(
37 available=
lambda block: block.valve
not in (
"failure",
"checking"),
38 removal_condition=
lambda _, block: block.valve
in (
"not_connected",
"unknown"),
44 config_entry: ShellyConfigEntry,
45 async_add_entities: AddEntitiesCallback,
47 """Set up valves for device."""
55 config_entry: ShellyConfigEntry,
56 async_add_entities: AddEntitiesCallback,
58 """Set up valve for device."""
59 coordinator = config_entry.runtime_data.block
60 assert coordinator
and coordinator.device.blocks
62 if coordinator.model == MODEL_GAS:
67 {(
"valve",
"valve"): GAS_VALVE},
71 unique_id = f
"{coordinator.mac}-valve_0-valve"
76 """Entity that controls a valve on block based Shelly devices."""
78 entity_description: BlockValveDescription
79 _attr_device_class = ValveDeviceClass.GAS
80 _attr_supported_features = ValveEntityFeature.OPEN | ValveEntityFeature.CLOSE
84 coordinator: ShellyBlockCoordinator,
87 description: BlockValveDescription,
89 """Initialize block valve."""
90 super().
__init__(coordinator, block, attribute, description)
96 """Return if the valve is closing."""
98 return cast(bool, self.
control_resultcontrol_result[
"state"] ==
"closing")
104 """Return if the valve is opening."""
106 return cast(bool, self.
control_resultcontrol_result[
"state"] ==
"opening")
122 """When device updates, clear control result that overrides state."""
StateType attribute_value(self)
Any set_state(self, **Any kwargs)
None _update_callback(self)
None async_open_valve(self, **Any kwargs)
None __init__(self, ShellyBlockCoordinator coordinator, Block block, str attribute, BlockValveDescription description)
None async_close_valve(self, **Any kwargs)
None async_write_ha_state(self)
None async_setup_block_attribute_entities(HomeAssistant hass, AddEntitiesCallback async_add_entities, ShellyBlockCoordinator coordinator, Mapping[tuple[str, str], BlockEntityDescription] sensors, Callable sensor_class)
int get_device_entry_gen(ConfigEntry entry)
None async_remove_shelly_entity(HomeAssistant hass, str domain, str unique_id)
None async_setup_entry(HomeAssistant hass, ShellyConfigEntry config_entry, AddEntitiesCallback async_add_entities)
None async_setup_block_entry(HomeAssistant hass, ShellyConfigEntry config_entry, AddEntitiesCallback async_add_entities)