Velbus split of entity in its own file (#79653)

* Velbus split of entity in its own file

* Update coveragerc
pull/79666/head
Maikel Punie 2022-10-05 17:03:23 +02:00 committed by GitHub
parent 5d7756885b
commit 0eb1101de8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 45 additions and 38 deletions

View File

@ -1426,6 +1426,7 @@ omit =
homeassistant/components/velbus/const.py
homeassistant/components/velbus/cover.py
homeassistant/components/velbus/diagnostics.py
homeassistant/components/velbus/entity.py
homeassistant/components/velbus/light.py
homeassistant/components/velbus/sensor.py
homeassistant/components/velbus/switch.py

View File

@ -3,7 +3,6 @@ from __future__ import annotations
import logging
from velbusaio.channels import Channel as VelbusChannel
from velbusaio.controller import Velbus
import voluptuous as vol
@ -13,7 +12,6 @@ from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import device_registry
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import DeviceEntry
from homeassistant.helpers.entity import DeviceInfo, Entity
from .const import (
CONF_INTERFACE,
@ -146,32 +144,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.services.async_remove(DOMAIN, SERVICE_SYNC)
hass.services.async_remove(DOMAIN, SERVICE_SET_MEMO_TEXT)
return unload_ok
class VelbusEntity(Entity):
"""Representation of a Velbus entity."""
_attr_should_poll: bool = False
def __init__(self, channel: VelbusChannel) -> None:
"""Initialize a Velbus entity."""
self._channel = channel
self._attr_name = channel.get_name()
self._attr_device_info = DeviceInfo(
identifiers={
(DOMAIN, str(channel.get_module_address())),
},
manufacturer="Velleman",
model=channel.get_module_type_name(),
name=channel.get_full_name(),
sw_version=channel.get_module_sw_version(),
)
serial = channel.get_module_serial() or str(channel.get_module_address())
self._attr_unique_id = f"{serial}-{channel.get_channel_number()}"
async def async_added_to_hass(self) -> None:
"""Add listener for state changes."""
self._channel.on_status_update(self._on_update)
async def _on_update(self) -> None:
self.async_write_ha_state()

View File

@ -6,8 +6,8 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import VelbusEntity
from .const import DOMAIN
from .entity import VelbusEntity
async def async_setup_entry(

View File

@ -12,8 +12,8 @@ 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
from .entity import VelbusEntity
async def async_setup_entry(

View File

@ -15,8 +15,8 @@ from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import VelbusEntity
from .const import DOMAIN, PRESET_MODES
from .entity import VelbusEntity
async def async_setup_entry(

View File

@ -14,8 +14,8 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import VelbusEntity
from .const import DOMAIN
from .entity import VelbusEntity
async def async_setup_entry(

View File

@ -0,0 +1,37 @@
"""Support for Velbus devices."""
from __future__ import annotations
from velbusaio.channels import Channel as VelbusChannel
from homeassistant.helpers.entity import DeviceInfo, Entity
from .const import DOMAIN
class VelbusEntity(Entity):
"""Representation of a Velbus entity."""
_attr_should_poll: bool = False
def __init__(self, channel: VelbusChannel) -> None:
"""Initialize a Velbus entity."""
self._channel = channel
self._attr_name = channel.get_name()
self._attr_device_info = DeviceInfo(
identifiers={
(DOMAIN, str(channel.get_module_address())),
},
manufacturer="Velleman",
model=channel.get_module_type_name(),
name=channel.get_full_name(),
sw_version=channel.get_module_sw_version(),
)
serial = channel.get_module_serial() or str(channel.get_module_address())
self._attr_unique_id = f"{serial}-{channel.get_channel_number()}"
async def async_added_to_hass(self) -> None:
"""Add listener for state changes."""
self._channel.on_status_update(self._on_update)
async def _on_update(self) -> None:
self.async_write_ha_state()

View File

@ -24,8 +24,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity, EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import VelbusEntity
from .const import DOMAIN
from .entity import VelbusEntity
async def async_setup_entry(

View File

@ -12,8 +12,8 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import VelbusEntity
from .const import DOMAIN
from .entity import VelbusEntity
async def async_setup_entry(

View File

@ -8,8 +8,8 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import VelbusEntity
from .const import DOMAIN
from .entity import VelbusEntity
async def async_setup_entry(