mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Extract LutronDevice into separate file (#107285)
This commit is contained in:
parent
52653220e3
commit
9672ca5719
@ -16,7 +16,6 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import Entity
|
|
||||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
@ -178,39 +177,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
|
|
||||||
class LutronDevice(Entity):
|
|
||||||
"""Representation of a Lutron device entity."""
|
|
||||||
|
|
||||||
_attr_should_poll = False
|
|
||||||
|
|
||||||
def __init__(self, area_name, lutron_device, controller) -> None:
|
|
||||||
"""Initialize the device."""
|
|
||||||
self._lutron_device = lutron_device
|
|
||||||
self._controller = controller
|
|
||||||
self._area_name = area_name
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
|
||||||
"""Register callbacks."""
|
|
||||||
self._lutron_device.subscribe(self._update_callback, None)
|
|
||||||
|
|
||||||
def _update_callback(self, _device, _context, _event, _params):
|
|
||||||
"""Run when invoked by pylutron when the device state changes."""
|
|
||||||
self.schedule_update_ha_state()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name of the device."""
|
|
||||||
return f"{self._area_name} {self._lutron_device.name}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return a unique ID."""
|
|
||||||
# Temporary fix for https://github.com/thecynic/pylutron/issues/70
|
|
||||||
if self._lutron_device.uuid is None:
|
|
||||||
return None
|
|
||||||
return f"{self._controller.guid}_{self._lutron_device.uuid}"
|
|
||||||
|
|
||||||
|
|
||||||
class LutronButton:
|
class LutronButton:
|
||||||
"""Representation of a button on a Lutron keypad.
|
"""Representation of a button on a Lutron keypad.
|
||||||
|
|
||||||
|
@ -16,7 +16,8 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import DiscoveryInfoType
|
from homeassistant.helpers.typing import DiscoveryInfoType
|
||||||
|
|
||||||
from . import LUTRON_CONTROLLER, LUTRON_DEVICES, LutronDevice
|
from . import LUTRON_CONTROLLER, LUTRON_DEVICES
|
||||||
|
from .entity import LutronDevice
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -14,7 +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 LUTRON_CONTROLLER, LUTRON_DEVICES, LutronDevice
|
from . import LUTRON_CONTROLLER, LUTRON_DEVICES
|
||||||
|
from .entity import LutronDevice
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
35
homeassistant/components/lutron/entity.py
Normal file
35
homeassistant/components/lutron/entity.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
"""Base class for Lutron devices."""
|
||||||
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
|
|
||||||
|
class LutronDevice(Entity):
|
||||||
|
"""Representation of a Lutron device entity."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
|
def __init__(self, area_name, lutron_device, controller) -> None:
|
||||||
|
"""Initialize the device."""
|
||||||
|
self._lutron_device = lutron_device
|
||||||
|
self._controller = controller
|
||||||
|
self._area_name = area_name
|
||||||
|
|
||||||
|
async def async_added_to_hass(self) -> None:
|
||||||
|
"""Register callbacks."""
|
||||||
|
self._lutron_device.subscribe(self._update_callback, None)
|
||||||
|
|
||||||
|
def _update_callback(self, _device, _context, _event, _params):
|
||||||
|
"""Run when invoked by pylutron when the device state changes."""
|
||||||
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> str:
|
||||||
|
"""Return the name of the device."""
|
||||||
|
return f"{self._area_name} {self._lutron_device.name}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Return a unique ID."""
|
||||||
|
# Temporary fix for https://github.com/thecynic/pylutron/issues/70
|
||||||
|
if self._lutron_device.uuid is None:
|
||||||
|
return None
|
||||||
|
return f"{self._controller.guid}_{self._lutron_device.uuid}"
|
@ -9,7 +9,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 LUTRON_CONTROLLER, LUTRON_DEVICES, LutronDevice
|
from . import LUTRON_CONTROLLER, LUTRON_DEVICES
|
||||||
|
from .entity import LutronDevice
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
@ -8,7 +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 LUTRON_CONTROLLER, LUTRON_DEVICES, LutronDevice
|
from . import LUTRON_CONTROLLER, LUTRON_DEVICES
|
||||||
|
from .entity import LutronDevice
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
@ -9,7 +9,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 LUTRON_CONTROLLER, LUTRON_DEVICES, LutronDevice
|
from . import LUTRON_CONTROLLER, LUTRON_DEVICES
|
||||||
|
from .entity import LutronDevice
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user