mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 18:27:51 +00:00
Add button platform to microBees (#111141)
* add button platform to microBees * use list comprehension for async_add_entities * add a transaltion_key and fix list comprehension * add panic button * remove BUTTON_PRODUCT_IDS
This commit is contained in:
parent
fc4b18b907
commit
1109aba211
@ -766,6 +766,7 @@ omit =
|
|||||||
homeassistant/components/microbees/__init__.py
|
homeassistant/components/microbees/__init__.py
|
||||||
homeassistant/components/microbees/api.py
|
homeassistant/components/microbees/api.py
|
||||||
homeassistant/components/microbees/application_credentials.py
|
homeassistant/components/microbees/application_credentials.py
|
||||||
|
homeassistant/components/microbees/button.py
|
||||||
homeassistant/components/microbees/const.py
|
homeassistant/components/microbees/const.py
|
||||||
homeassistant/components/microbees/coordinator.py
|
homeassistant/components/microbees/coordinator.py
|
||||||
homeassistant/components/microbees/entity.py
|
homeassistant/components/microbees/entity.py
|
||||||
|
53
homeassistant/components/microbees/button.py
Normal file
53
homeassistant/components/microbees/button.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
"""Button integration microBees."""
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.components.button import ButtonEntity
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
from .coordinator import MicroBeesUpdateCoordinator
|
||||||
|
from .entity import MicroBeesActuatorEntity
|
||||||
|
|
||||||
|
BUTTON_TRANSLATIONS = {51: "button_gate", 91: "button_panic"}
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
|
) -> None:
|
||||||
|
"""Set up the microBees button platform."""
|
||||||
|
coordinator: MicroBeesUpdateCoordinator = hass.data[DOMAIN][
|
||||||
|
entry.entry_id
|
||||||
|
].coordinator
|
||||||
|
async_add_entities(
|
||||||
|
MBButton(coordinator, bee_id, button.id)
|
||||||
|
for bee_id, bee in coordinator.data.bees.items()
|
||||||
|
if bee.productID in BUTTON_TRANSLATIONS
|
||||||
|
for button in bee.actuators
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MBButton(MicroBeesActuatorEntity, ButtonEntity):
|
||||||
|
"""Representation of a microBees button."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: MicroBeesUpdateCoordinator,
|
||||||
|
bee_id: int,
|
||||||
|
actuator_id: int,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the microBees button."""
|
||||||
|
super().__init__(coordinator, bee_id, actuator_id)
|
||||||
|
self._attr_translation_key = BUTTON_TRANSLATIONS.get(self.bee.productID)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> str:
|
||||||
|
"""Name of the switch."""
|
||||||
|
return self.actuator.name
|
||||||
|
|
||||||
|
async def async_press(self, **kwargs: Any) -> None:
|
||||||
|
"""Turn on the button."""
|
||||||
|
await self.coordinator.microbees.sendCommand(
|
||||||
|
self.actuator.id, self.actuator.configuration.actuator_timing * 1000
|
||||||
|
)
|
@ -5,6 +5,7 @@ DOMAIN = "microbees"
|
|||||||
OAUTH2_AUTHORIZE = "https://dev.microbees.com/oauth/authorize"
|
OAUTH2_AUTHORIZE = "https://dev.microbees.com/oauth/authorize"
|
||||||
OAUTH2_TOKEN = "https://dev.microbees.com/oauth/token"
|
OAUTH2_TOKEN = "https://dev.microbees.com/oauth/token"
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
|
Platform.BUTTON,
|
||||||
Platform.LIGHT,
|
Platform.LIGHT,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
Platform.SWITCH,
|
Platform.SWITCH,
|
||||||
|
@ -7,6 +7,14 @@
|
|||||||
"socket_it": {
|
"socket_it": {
|
||||||
"default": "mdi:power-socket-it"
|
"default": "mdi:power-socket-it"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"button": {
|
||||||
|
"button_gate": {
|
||||||
|
"default": "mdi:gate"
|
||||||
|
},
|
||||||
|
"button_panic": {
|
||||||
|
"default": "mdi:alert-octagram"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user