Add velbus buttons platform (#73323)

This commit is contained in:
Maikel Punie 2022-06-28 18:41:29 +02:00 committed by GitHub
parent 9fef1004a2
commit 040ece76ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 49 additions and 5 deletions

View file

@ -1361,6 +1361,7 @@ omit =
homeassistant/components/vasttrafik/sensor.py homeassistant/components/vasttrafik/sensor.py
homeassistant/components/velbus/__init__.py homeassistant/components/velbus/__init__.py
homeassistant/components/velbus/binary_sensor.py homeassistant/components/velbus/binary_sensor.py
homeassistant/components/velbus/button.py
homeassistant/components/velbus/climate.py homeassistant/components/velbus/climate.py
homeassistant/components/velbus/const.py homeassistant/components/velbus/const.py
homeassistant/components/velbus/cover.py homeassistant/components/velbus/cover.py

View file

@ -28,6 +28,7 @@ _LOGGER = logging.getLogger(__name__)
PLATFORMS = [ PLATFORMS = [
Platform.BINARY_SENSOR, Platform.BINARY_SENSOR,
Platform.BUTTON,
Platform.CLIMATE, Platform.CLIMATE,
Platform.COVER, Platform.COVER,
Platform.LIGHT, Platform.LIGHT,

View file

@ -0,0 +1,42 @@
"""Support for Velbus Buttons."""
from __future__ import annotations
from velbusaio.channels import (
Button as VelbusaioButton,
ButtonCounter as VelbusaioButtonCounter,
)
from homeassistant.components.button import ButtonEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import VelbusEntity
from .const import DOMAIN
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up Velbus switch based on config_entry."""
await hass.data[DOMAIN][entry.entry_id]["tsk"]
cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
entities = []
for channel in cntrl.get_all("button"):
entities.append(VelbusButton(channel))
async_add_entities(entities)
class VelbusButton(VelbusEntity, ButtonEntity):
"""Representation of a Velbus Binary Sensor."""
_channel: VelbusaioButton | VelbusaioButtonCounter
_attr_entity_registry_enabled_default = False
_attr_entity_category = EntityCategory.CONFIG
async def async_press(self) -> None:
"""Handle the button press."""
await self._channel.press()

View file

@ -2,7 +2,7 @@
"domain": "velbus", "domain": "velbus",
"name": "Velbus", "name": "Velbus",
"documentation": "https://www.home-assistant.io/integrations/velbus", "documentation": "https://www.home-assistant.io/integrations/velbus",
"requirements": ["velbus-aio==2022.6.1"], "requirements": ["velbus-aio==2022.6.2"],
"config_flow": true, "config_flow": true,
"codeowners": ["@Cereal2nd", "@brefra"], "codeowners": ["@Cereal2nd", "@brefra"],
"dependencies": ["usb"], "dependencies": ["usb"],

View file

@ -53,9 +53,9 @@ class VelbusSensor(VelbusEntity, SensorEntity):
self._attr_name = f"{self._attr_name}-counter" self._attr_name = f"{self._attr_name}-counter"
# define the device class # define the device class
if self._is_counter: if self._is_counter:
self._attr_device_class = SensorDeviceClass.ENERGY
elif channel.is_counter_channel():
self._attr_device_class = SensorDeviceClass.POWER self._attr_device_class = SensorDeviceClass.POWER
elif channel.is_counter_channel():
self._attr_device_class = SensorDeviceClass.ENERGY
elif channel.is_temperature(): elif channel.is_temperature():
self._attr_device_class = SensorDeviceClass.TEMPERATURE self._attr_device_class = SensorDeviceClass.TEMPERATURE
# define the icon # define the icon

View file

@ -2384,7 +2384,7 @@ vallox-websocket-api==2.11.0
vehicle==0.4.0 vehicle==0.4.0
# homeassistant.components.velbus # homeassistant.components.velbus
velbus-aio==2022.6.1 velbus-aio==2022.6.2
# homeassistant.components.venstar # homeassistant.components.venstar
venstarcolortouch==0.16 venstarcolortouch==0.16

View file

@ -1581,7 +1581,7 @@ vallox-websocket-api==2.11.0
vehicle==0.4.0 vehicle==0.4.0
# homeassistant.components.velbus # homeassistant.components.velbus
velbus-aio==2022.6.1 velbus-aio==2022.6.2
# homeassistant.components.venstar # homeassistant.components.venstar
venstarcolortouch==0.16 venstarcolortouch==0.16