1 """Matter valve platform."""
3 from __future__
import annotations
5 from chip.clusters
import Objects
as clusters
6 from matter_server.client.models
import device_types
11 ValveEntityDescription,
19 from .entity
import MatterEntity
20 from .helpers
import get_matter
21 from .models
import MatterDiscoverySchema
23 ValveConfigurationAndControl = clusters.ValveConfigurationAndControl
25 ValveStateEnum = ValveConfigurationAndControl.Enums.ValveStateEnum
30 config_entry: ConfigEntry,
31 async_add_entities: AddEntitiesCallback,
33 """Set up Matter valve platform from Config Entry."""
35 matter.register_platform_handler(Platform.VALVE, async_add_entities)
39 """Representation of a Matter Valve."""
41 _feature_map: int |
None =
None
42 entity_description: ValveEntityDescription
43 _platform_translation_key =
"valve"
47 command: clusters.ClusterCommand,
49 """Send a command to the device."""
51 node_id=self.
_endpoint_endpoint.node.node_id,
52 endpoint_id=self.
_endpoint_endpoint.endpoint_id,
58 await self.
send_device_commandsend_device_command(ValveConfigurationAndControl.Commands.Open())
61 """Close the valve."""
62 await self.
send_device_commandsend_device_command(ValveConfigurationAndControl.Commands.Close())
65 """Move the valve to a specific position."""
67 ValveConfigurationAndControl.Commands.Open(targetLevel=position)
72 """Update from device."""
76 ValveConfigurationAndControl.Attributes.CurrentState
80 ValveConfigurationAndControl.Attributes.TargetState
83 current_state == ValveStateEnum.kTransitioning
84 and target_state == ValveStateEnum.kOpen
89 current_state == ValveStateEnum.kTransitioning
90 and target_state == ValveStateEnum.kClosed
94 elif current_state == ValveStateEnum.kClosed:
105 ValveConfigurationAndControl.Attributes.CurrentLevel
112 """Calculate features for HA Valve platform from Matter FeatureMap."""
115 ValveConfigurationAndControl.Attributes.FeatureMap
125 if feature_map & ValveConfigurationAndControl.Bitmaps.Feature.kLevel:
132 ValveEntityFeature.CLOSE | ValveEntityFeature.OPEN
137 DISCOVERY_SCHEMAS = [
139 platform=Platform.VALVE,
142 device_class=ValveDeviceClass.WATER,
145 entity_class=MatterValve,
146 required_attributes=(
147 ValveConfigurationAndControl.Attributes.CurrentState,
148 ValveConfigurationAndControl.Attributes.TargetState,
150 optional_attributes=(ValveConfigurationAndControl.Attributes.CurrentLevel,),
151 device_type=(device_types.WaterValve,),
Any get_matter_attribute_value(self, type[ClusterAttributeDescriptor] attribute, bool null_as_none=True)
None async_close_valve(self)
None async_open_valve(self)
None _calculate_features(self)
None _update_from_device(self)
None async_set_valve_position(self, int position)
None send_device_command(self, clusters.ClusterCommand command)
_attr_current_valve_position
ValveEntityFeature supported_features(self)
int|None supported_features(self)
MatterAdapter get_matter(HomeAssistant hass)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)