Velbus split of entity in its own file (#79653)
* Velbus split of entity in its own file * Update coveragerc
This commit is contained in:
parent
5d7756885b
commit
0eb1101de8
10 changed files with 45 additions and 38 deletions
|
@ -1426,6 +1426,7 @@ omit =
|
||||||
homeassistant/components/velbus/const.py
|
homeassistant/components/velbus/const.py
|
||||||
homeassistant/components/velbus/cover.py
|
homeassistant/components/velbus/cover.py
|
||||||
homeassistant/components/velbus/diagnostics.py
|
homeassistant/components/velbus/diagnostics.py
|
||||||
|
homeassistant/components/velbus/entity.py
|
||||||
homeassistant/components/velbus/light.py
|
homeassistant/components/velbus/light.py
|
||||||
homeassistant/components/velbus/sensor.py
|
homeassistant/components/velbus/sensor.py
|
||||||
homeassistant/components/velbus/switch.py
|
homeassistant/components/velbus/switch.py
|
||||||
|
|
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from velbusaio.channels import Channel as VelbusChannel
|
|
||||||
from velbusaio.controller import Velbus
|
from velbusaio.controller import Velbus
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
@ -13,7 +12,6 @@ from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
from homeassistant.helpers import device_registry
|
from homeassistant.helpers import device_registry
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.device_registry import DeviceEntry
|
from homeassistant.helpers.device_registry import DeviceEntry
|
||||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_INTERFACE,
|
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_SYNC)
|
||||||
hass.services.async_remove(DOMAIN, SERVICE_SET_MEMO_TEXT)
|
hass.services.async_remove(DOMAIN, SERVICE_SET_MEMO_TEXT)
|
||||||
return unload_ok
|
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()
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import VelbusEntity
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .entity import VelbusEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
|
|
@ -12,8 +12,8 @@ from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import VelbusEntity
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .entity import VelbusEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
|
|
@ -15,8 +15,8 @@ from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import VelbusEntity
|
|
||||||
from .const import DOMAIN, PRESET_MODES
|
from .const import DOMAIN, PRESET_MODES
|
||||||
|
from .entity import VelbusEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
|
|
@ -14,8 +14,8 @@ from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import VelbusEntity
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .entity import VelbusEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
|
37
homeassistant/components/velbus/entity.py
Normal file
37
homeassistant/components/velbus/entity.py
Normal 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()
|
|
@ -24,8 +24,8 @@ from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import Entity, EntityCategory
|
from homeassistant.helpers.entity import Entity, EntityCategory
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import VelbusEntity
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .entity import VelbusEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
|
|
@ -12,8 +12,8 @@ from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import VelbusEntity
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .entity import VelbusEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
|
|
@ -8,8 +8,8 @@ from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import VelbusEntity
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .entity import VelbusEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue