Home Assistant Unofficial Reference 2024.12.1
button.py
Go to the documentation of this file.
1 """Support for Roborock button."""
2 
3 from __future__ import annotations
4 
5 from dataclasses import dataclass
6 
7 from roborock.roborock_typing import RoborockCommand
8 
9 from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
10 from homeassistant.const import EntityCategory
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 
14 from . import RoborockConfigEntry
15 from .coordinator import RoborockDataUpdateCoordinator
16 from .entity import RoborockEntityV1
17 
18 
19 @dataclass(frozen=True, kw_only=True)
21  """Describes a Roborock button entity."""
22 
23  command: RoborockCommand
24  param: list | dict | None
25 
26 
27 CONSUMABLE_BUTTON_DESCRIPTIONS = [
29  key="reset_sensor_consumable",
30  translation_key="reset_sensor_consumable",
31  command=RoborockCommand.RESET_CONSUMABLE,
32  param=["sensor_dirty_time"],
33  entity_category=EntityCategory.CONFIG,
34  entity_registry_enabled_default=False,
35  ),
37  key="reset_air_filter_consumable",
38  translation_key="reset_air_filter_consumable",
39  command=RoborockCommand.RESET_CONSUMABLE,
40  param=["filter_work_time"],
41  entity_category=EntityCategory.CONFIG,
42  entity_registry_enabled_default=False,
43  ),
45  key="reset_side_brush_consumable",
46  translation_key="reset_side_brush_consumable",
47  command=RoborockCommand.RESET_CONSUMABLE,
48  param=["side_brush_work_time"],
49  entity_category=EntityCategory.CONFIG,
50  entity_registry_enabled_default=False,
51  ),
53  key="reset_main_brush_consumable",
54  translation_key="reset_main_brush_consumable",
55  command=RoborockCommand.RESET_CONSUMABLE,
56  param=["main_brush_work_time"],
57  entity_category=EntityCategory.CONFIG,
58  entity_registry_enabled_default=False,
59  ),
60 ]
61 
62 
64  hass: HomeAssistant,
65  config_entry: RoborockConfigEntry,
66  async_add_entities: AddEntitiesCallback,
67 ) -> None:
68  """Set up Roborock button platform."""
71  coordinator,
72  description,
73  )
74  for coordinator in config_entry.runtime_data.v1
75  for description in CONSUMABLE_BUTTON_DESCRIPTIONS
76  if isinstance(coordinator, RoborockDataUpdateCoordinator)
77  )
78 
79 
81  """A class to define Roborock button entities."""
82 
83  entity_description: RoborockButtonDescription
84 
85  def __init__(
86  self,
87  coordinator: RoborockDataUpdateCoordinator,
88  entity_description: RoborockButtonDescription,
89  ) -> None:
90  """Create a button entity."""
91  super().__init__(
92  f"{entity_description.key}_{coordinator.duid_slug}",
93  coordinator.device_info,
94  coordinator.api,
95  )
96  self.entity_descriptionentity_description = entity_description
97 
98  async def async_press(self) -> None:
99  """Press the button."""
100  await self.sendsend(self.entity_descriptionentity_description.command, self.entity_descriptionentity_description.param)
None __init__(self, RoborockDataUpdateCoordinator coordinator, RoborockButtonDescription entity_description)
Definition: button.py:89
dict send(self, RoborockCommand|str command, dict[str, Any]|list[Any]|int|None params=None)
Definition: entity.py:60
None async_setup_entry(HomeAssistant hass, RoborockConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: button.py:67