mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 08:07:45 +00:00
Move homeworks base entity to separate module (#126097)
* Move homeworks base entity to separate module * Move calculate_unique_id to util.py
This commit is contained in:
parent
ca59805907
commit
219417cfb5
@ -33,7 +33,6 @@ from homeassistant.exceptions import ConfigEntryNotReady, ServiceValidationError
|
|||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.debounce import Debouncer
|
from homeassistant.helpers.debounce import Debouncer
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
||||||
from homeassistant.helpers.entity import Entity
|
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
|
||||||
@ -48,8 +47,6 @@ CONF_COMMAND = "command"
|
|||||||
EVENT_BUTTON_PRESS = "homeworks_button_press"
|
EVENT_BUTTON_PRESS = "homeworks_button_press"
|
||||||
EVENT_BUTTON_RELEASE = "homeworks_button_release"
|
EVENT_BUTTON_RELEASE = "homeworks_button_release"
|
||||||
|
|
||||||
DEFAULT_FADE_RATE = 1.0
|
|
||||||
|
|
||||||
KEYPAD_LEDSTATE_POLL_COOLDOWN = 1.0
|
KEYPAD_LEDSTATE_POLL_COOLDOWN = 1.0
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||||
@ -204,37 +201,6 @@ async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
|||||||
await hass.config_entries.async_reload(entry.entry_id)
|
await hass.config_entries.async_reload(entry.entry_id)
|
||||||
|
|
||||||
|
|
||||||
def calculate_unique_id(controller_id: str, addr: str, idx: int) -> str:
|
|
||||||
"""Calculate entity unique id."""
|
|
||||||
return f"homeworks.{controller_id}.{addr}.{idx}"
|
|
||||||
|
|
||||||
|
|
||||||
class HomeworksEntity(Entity):
|
|
||||||
"""Base class of a Homeworks device."""
|
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
|
||||||
_attr_should_poll = False
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
controller: Homeworks,
|
|
||||||
controller_id: str,
|
|
||||||
addr: str,
|
|
||||||
idx: int,
|
|
||||||
name: str | None,
|
|
||||||
) -> None:
|
|
||||||
"""Initialize Homeworks device."""
|
|
||||||
self._addr = addr
|
|
||||||
self._idx = idx
|
|
||||||
self._controller_id = controller_id
|
|
||||||
self._attr_name = name
|
|
||||||
self._attr_unique_id = calculate_unique_id(
|
|
||||||
self._controller_id, self._addr, self._idx
|
|
||||||
)
|
|
||||||
self._controller = controller
|
|
||||||
self._attr_extra_state_attributes = {"homeworks_address": self._addr}
|
|
||||||
|
|
||||||
|
|
||||||
class HomeworksKeypad:
|
class HomeworksKeypad:
|
||||||
"""When you want signals instead of entities.
|
"""When you want signals instead of entities.
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ from homeassistant.helpers.device_registry import DeviceInfo
|
|||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import HomeworksData, HomeworksEntity, HomeworksKeypad
|
from . import HomeworksData, HomeworksKeypad
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_ADDR,
|
CONF_ADDR,
|
||||||
CONF_BUTTONS,
|
CONF_BUTTONS,
|
||||||
@ -25,6 +25,7 @@ from .const import (
|
|||||||
CONF_NUMBER,
|
CONF_NUMBER,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
from .entity import HomeworksEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import HomeworksData, HomeworksEntity
|
from . import HomeworksData
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_ADDR,
|
CONF_ADDR,
|
||||||
CONF_BUTTONS,
|
CONF_BUTTONS,
|
||||||
@ -23,6 +23,7 @@ from .const import (
|
|||||||
CONF_RELEASE_DELAY,
|
CONF_RELEASE_DELAY,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
from .entity import HomeworksEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
@ -39,7 +39,6 @@ from homeassistant.helpers.selector import TextSelector
|
|||||||
from homeassistant.helpers.typing import VolDictType
|
from homeassistant.helpers.typing import VolDictType
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
|
||||||
from . import DEFAULT_FADE_RATE, calculate_unique_id
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_ADDR,
|
CONF_ADDR,
|
||||||
CONF_BUTTONS,
|
CONF_BUTTONS,
|
||||||
@ -56,9 +55,12 @@ from .const import (
|
|||||||
DEFAULT_LIGHT_NAME,
|
DEFAULT_LIGHT_NAME,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
from .util import calculate_unique_id
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DEFAULT_FADE_RATE = 1.0
|
||||||
|
|
||||||
CONTROLLER_EDIT = {
|
CONTROLLER_EDIT = {
|
||||||
vol.Required(CONF_HOST): selector.TextSelector(),
|
vol.Required(CONF_HOST): selector.TextSelector(),
|
||||||
vol.Required(CONF_PORT): selector.NumberSelector(
|
vol.Required(CONF_PORT): selector.NumberSelector(
|
||||||
|
35
homeassistant/components/homeworks/entity.py
Normal file
35
homeassistant/components/homeworks/entity.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
"""Support for Lutron Homeworks Series 4 and 8 systems."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pyhomeworks.pyhomeworks import Homeworks
|
||||||
|
|
||||||
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
|
from .util import calculate_unique_id
|
||||||
|
|
||||||
|
|
||||||
|
class HomeworksEntity(Entity):
|
||||||
|
"""Base class of a Homeworks device."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
controller: Homeworks,
|
||||||
|
controller_id: str,
|
||||||
|
addr: str,
|
||||||
|
idx: int,
|
||||||
|
name: str | None,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize Homeworks device."""
|
||||||
|
self._addr = addr
|
||||||
|
self._idx = idx
|
||||||
|
self._controller_id = controller_id
|
||||||
|
self._attr_name = name
|
||||||
|
self._attr_unique_id = calculate_unique_id(
|
||||||
|
self._controller_id, self._addr, self._idx
|
||||||
|
)
|
||||||
|
self._controller = controller
|
||||||
|
self._attr_extra_state_attributes = {"homeworks_address": self._addr}
|
@ -15,8 +15,9 @@ from homeassistant.helpers.device_registry import DeviceInfo
|
|||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import HomeworksData, HomeworksEntity
|
from . import HomeworksData
|
||||||
from .const import CONF_ADDR, CONF_CONTROLLER_ID, CONF_DIMMERS, CONF_RATE, DOMAIN
|
from .const import CONF_ADDR, CONF_CONTROLLER_ID, CONF_DIMMERS, CONF_RATE, DOMAIN
|
||||||
|
from .entity import HomeworksEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
6
homeassistant/components/homeworks/util.py
Normal file
6
homeassistant/components/homeworks/util.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
"""Support for Lutron Homeworks Series 4 and 8 systems."""
|
||||||
|
|
||||||
|
|
||||||
|
def calculate_unique_id(controller_id: str, addr: str, idx: int) -> str:
|
||||||
|
"""Calculate entity unique id."""
|
||||||
|
return f"homeworks.{controller_id}.{addr}.{idx}"
|
Loading…
x
Reference in New Issue
Block a user