1 """Matter vacuum platform."""
3 from __future__
import annotations
5 from enum
import IntEnum
6 from typing
import TYPE_CHECKING, Any
8 from chip.clusters
import Objects
as clusters
9 from matter_server.client.models
import device_types
17 StateVacuumEntityDescription,
25 from .entity
import MatterEntity
26 from .helpers
import get_matter
27 from .models
import MatterDiscoverySchema
31 """Operational State of the vacuum cleaner.
33 Combination of generic OperationalState and RvcOperationalState.
37 UNABLE_TO_START_OR_RESUME = 0x01
38 UNABLE_TO_COMPLETE_OPERATION = 0x02
39 COMMAND_INVALID_IN_STATE = 0x03
40 SEEKING_CHARGER = 0x40
46 """Enum with available ModeTag values."""
55 config_entry: ConfigEntry,
56 async_add_entities: AddEntitiesCallback,
58 """Set up Matter vacuum platform from Config Entry."""
60 matter.register_platform_handler(Platform.VACUUM, async_add_entities)
64 """Representation of a Matter Vacuum cleaner entity."""
66 _last_accepted_commands: list[int] |
None =
None
67 _supported_run_modes: (
68 dict[int, clusters.RvcCleanMode.Structs.ModeOptionStruct] |
None
70 entity_description: StateVacuumEntityDescription
71 _platform_translation_key =
"vacuum"
74 """Stop the vacuum cleaner."""
78 """Set the vacuum cleaner to return to the dock."""
79 await self.
_send_device_command_send_device_command(clusters.RvcOperationalState.Commands.GoHome())
82 """Locate the vacuum cleaner."""
86 """Start or resume the cleaning task."""
90 clusters.RvcOperationalState.Commands.Resume.command_id
94 clusters.RvcOperationalState.Commands.Resume()
100 """Pause the cleaning task."""
105 command: clusters.ClusterCommand,
107 """Send a command to the device."""
109 node_id=self.
_endpoint_endpoint.node.node_id,
110 endpoint_id=self.
_endpoint_endpoint.endpoint_id,
116 """Update from device."""
121 clusters.PowerSource.Attributes.BatPercentRemaining
125 clusters.RvcRunMode.Attributes.CurrentMode
128 clusters.RvcOperationalState.Attributes.OperationalState
130 state: str |
None =
None
133 if operational_state
in (OperationalState.CHARGING, OperationalState.DOCKED):
135 elif operational_state == OperationalState.SEEKING_CHARGER:
136 state = STATE_RETURNING
137 elif operational_state
in (
138 OperationalState.UNABLE_TO_COMPLETE_OPERATION,
139 OperationalState.UNABLE_TO_START_OR_RESUME,
143 tags = {x.value
for x
in run_mode.modeTags}
144 if ModeTag.CLEANING
in tags:
145 state = STATE_CLEANING
146 elif ModeTag.IDLE
in tags:
152 """Calculate features for HA Vacuum platform."""
154 clusters.RvcOperationalState.Attributes.AcceptedCommandList
161 supported_features |= VacuumEntityFeature.STATE
164 clusters.PowerSource.Attributes.BatPercentRemaining
166 supported_features |= VacuumEntityFeature.BATTERY
169 supported_features |= VacuumEntityFeature.LOCATE
171 run_modes: list[clusters.RvcCleanMode.Structs.ModeOptionStruct] = (
173 clusters.RvcRunMode.Attributes.SupportedModes
179 clusters.RvcOperationalState.Commands.Pause.command_id
180 in accepted_operational_commands
182 supported_features |= VacuumEntityFeature.PAUSE
184 clusters.OperationalState.Commands.Stop.command_id
185 in accepted_operational_commands
187 supported_features |= VacuumEntityFeature.STOP
189 clusters.OperationalState.Commands.Start.command_id
190 in accepted_operational_commands
193 supported_features |= VacuumEntityFeature.START
195 clusters.RvcOperationalState.Commands.Resume.command_id
196 in accepted_operational_commands
198 supported_features |= VacuumEntityFeature.START
200 clusters.RvcOperationalState.Commands.GoHome.command_id
201 in accepted_operational_commands
203 supported_features |= VacuumEntityFeature.RETURN_HOME
209 DISCOVERY_SCHEMAS = [
211 platform=Platform.VACUUM,
213 key=
"MatterVacuumCleaner", name=
None
215 entity_class=MatterVacuum,
216 required_attributes=(
217 clusters.RvcRunMode.Attributes.CurrentMode,
218 clusters.RvcOperationalState.Attributes.CurrentPhase,
220 optional_attributes=(
221 clusters.RvcCleanMode.Attributes.CurrentMode,
222 clusters.PowerSource.Attributes.BatPercentRemaining,
224 device_type=(device_types.RoboticVacuumCleaner,),
Any get_matter_attribute_value(self, type[ClusterAttributeDescriptor] attribute, bool null_as_none=True)
None async_return_to_base(self, **Any kwargs)
None async_stop(self, **Any kwargs)
None _calculate_features(self)
None _update_from_device(self)
None _send_device_command(self, clusters.ClusterCommand command)
None async_locate(self, **Any kwargs)
web.Response get(self, web.Request request, str config_key)
MatterAdapter get_matter(HomeAssistant hass)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)