Add device info to lupusec (#108910)
* added device info and unique id * removed wrong attribute * added base entity * rename domain * added entity.py to coveragerc * added base entity for sensors and alarm panel * add generic type translation * rename functions * rename device name to device model * set _attr_name = None * pass in only the entry_id instead of the full config_entry * set unique id to device_id or entry id * use deviceinfo class * moved _attr_name = None to entities * Update homeassistant/components/lupusec/alarm_control_panel.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/lupusec/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/lupusec/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * remove DOMAIN from unique id * removed redundant function * Update homeassistant/components/lupusec/alarm_control_panel.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/lupusec/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> --------- Co-authored-by: suaveolent <suaveolent@users.noreply.github.com> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
9413d15c25
commit
f2100f80c4
7 changed files with 107 additions and 28 deletions
|
@ -709,6 +709,7 @@ omit =
|
|||
homeassistant/components/lupusec/__init__.py
|
||||
homeassistant/components/lupusec/alarm_control_panel.py
|
||||
homeassistant/components/lupusec/binary_sensor.py
|
||||
homeassistant/components/lupusec/entity.py
|
||||
homeassistant/components/lupusec/switch.py
|
||||
homeassistant/components/lutron/__init__.py
|
||||
homeassistant/components/lutron/binary_sensor.py
|
||||
|
|
|
@ -17,7 +17,6 @@ from homeassistant.const import (
|
|||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
|
@ -139,21 +138,3 @@ class LupusecSystem:
|
|||
def __init__(self, username, password, ip_address) -> None:
|
||||
"""Initialize the system."""
|
||||
self.lupusec = lupupy.Lupusec(username, password, ip_address)
|
||||
|
||||
|
||||
class LupusecDevice(Entity):
|
||||
"""Representation of a Lupusec device."""
|
||||
|
||||
def __init__(self, data, device) -> None:
|
||||
"""Initialize a sensor for Lupusec device."""
|
||||
self._data = data
|
||||
self._device = device
|
||||
|
||||
def update(self):
|
||||
"""Update automation state."""
|
||||
self._device.refresh()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._device.name
|
||||
|
|
|
@ -15,9 +15,11 @@ from homeassistant.const import (
|
|||
STATE_ALARM_TRIGGERED,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import DOMAIN as LUPUSEC_DOMAIN, LupusecDevice
|
||||
from . import DOMAIN
|
||||
from .entity import LupusecDevice
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=2)
|
||||
|
||||
|
@ -28,9 +30,11 @@ async def async_setup_entry(
|
|||
async_add_devices: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up an alarm control panel for a Lupusec device."""
|
||||
data = hass.data[LUPUSEC_DOMAIN][config_entry.entry_id]
|
||||
data = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
alarm_devices = [LupusecAlarm(data, data.lupusec.get_alarm())]
|
||||
alarm_devices = [
|
||||
LupusecAlarm(data, data.lupusec.get_alarm(), config_entry.entry_id)
|
||||
]
|
||||
|
||||
async_add_devices(alarm_devices)
|
||||
|
||||
|
@ -38,12 +42,24 @@ async def async_setup_entry(
|
|||
class LupusecAlarm(LupusecDevice, AlarmControlPanelEntity):
|
||||
"""An alarm_control_panel implementation for Lupusec."""
|
||||
|
||||
_attr_name = None
|
||||
_attr_icon = "mdi:security"
|
||||
_attr_supported_features = (
|
||||
AlarmControlPanelEntityFeature.ARM_HOME
|
||||
| AlarmControlPanelEntityFeature.ARM_AWAY
|
||||
)
|
||||
|
||||
def __init__(self, data, device, entry_id) -> None:
|
||||
"""Initialize the LupusecAlarm class."""
|
||||
super().__init__(data, device, entry_id)
|
||||
self._attr_unique_id = entry_id
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, entry_id)},
|
||||
name=device.name,
|
||||
manufacturer="Lupus Electronics",
|
||||
model=f"Lupusec-XT{data.lupusec.model}",
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
"""Return the state of the device."""
|
||||
|
|
|
@ -14,7 +14,8 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import DOMAIN, LupusecDevice
|
||||
from . import DOMAIN
|
||||
from .entity import LupusecBaseSensor
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=2)
|
||||
|
||||
|
@ -34,14 +35,16 @@ async def async_setup_entry(
|
|||
|
||||
sensors = []
|
||||
for device in data.lupusec.get_devices(generic_type=device_types):
|
||||
sensors.append(LupusecBinarySensor(data, device))
|
||||
sensors.append(LupusecBinarySensor(data, device, config_entry.entry_id))
|
||||
|
||||
async_add_devices(sensors)
|
||||
|
||||
|
||||
class LupusecBinarySensor(LupusecDevice, BinarySensorEntity):
|
||||
class LupusecBinarySensor(LupusecBaseSensor, BinarySensorEntity):
|
||||
"""A binary sensor implementation for Lupusec device."""
|
||||
|
||||
_attr_name = None
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return True if the binary sensor is on."""
|
||||
|
|
|
@ -1,6 +1,39 @@
|
|||
"""Constants for the Lupusec component."""
|
||||
|
||||
from lupupy.constants import (
|
||||
TYPE_CONTACT_XT,
|
||||
TYPE_DOOR,
|
||||
TYPE_INDOOR_SIREN_XT,
|
||||
TYPE_KEYPAD_V2,
|
||||
TYPE_OUTDOOR_SIREN_XT,
|
||||
TYPE_POWER_SWITCH,
|
||||
TYPE_POWER_SWITCH_1_XT,
|
||||
TYPE_POWER_SWITCH_2_XT,
|
||||
TYPE_SMOKE,
|
||||
TYPE_SMOKE_XT,
|
||||
TYPE_WATER,
|
||||
TYPE_WATER_XT,
|
||||
TYPE_WINDOW,
|
||||
)
|
||||
|
||||
DOMAIN = "lupusec"
|
||||
|
||||
INTEGRATION_TITLE = "Lupus Electronics LUPUSEC"
|
||||
ISSUE_PLACEHOLDER = {"url": "/config/integrations/dashboard/add?domain=lupusec"}
|
||||
|
||||
|
||||
TYPE_TRANSLATION = {
|
||||
TYPE_WINDOW: "Fensterkontakt",
|
||||
TYPE_DOOR: "Türkontakt",
|
||||
TYPE_SMOKE: "Rauchmelder",
|
||||
TYPE_WATER: "Wassermelder",
|
||||
TYPE_POWER_SWITCH: "Steckdose",
|
||||
TYPE_CONTACT_XT: "Fenster- / Türkontakt V2",
|
||||
TYPE_WATER_XT: "Wassermelder V2",
|
||||
TYPE_SMOKE_XT: "Rauchmelder V2",
|
||||
TYPE_POWER_SWITCH_1_XT: "Funksteckdose",
|
||||
TYPE_POWER_SWITCH_2_XT: "Funksteckdose V2",
|
||||
TYPE_KEYPAD_V2: "Keypad V2",
|
||||
TYPE_INDOOR_SIREN_XT: "Innensirene",
|
||||
TYPE_OUTDOOR_SIREN_XT: "Außensirene V2",
|
||||
}
|
||||
|
|
42
homeassistant/components/lupusec/entity.py
Normal file
42
homeassistant/components/lupusec/entity.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
"""Provides the Lupusec entity for Home Assistant."""
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from .const import DOMAIN, TYPE_TRANSLATION
|
||||
|
||||
|
||||
class LupusecDevice(Entity):
|
||||
"""Representation of a Lupusec device."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, data, device, entry_id) -> None:
|
||||
"""Initialize a sensor for Lupusec device."""
|
||||
self._data = data
|
||||
self._device = device
|
||||
self._attr_unique_id = device.device_id
|
||||
|
||||
def update(self):
|
||||
"""Update automation state."""
|
||||
self._device.refresh()
|
||||
|
||||
|
||||
class LupusecBaseSensor(LupusecDevice):
|
||||
"""Lupusec Sensor base entity."""
|
||||
|
||||
def __init__(self, data, device, entry_id) -> None:
|
||||
"""Initialize the LupusecBaseSensor."""
|
||||
super().__init__(data, device, entry_id)
|
||||
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, device.device_id)},
|
||||
name=device.name,
|
||||
manufacturer="Lupus Electronics",
|
||||
serial_number=device.device_id,
|
||||
model=TYPE_TRANSLATION.get(device.type, device.type),
|
||||
via_device=(DOMAIN, entry_id),
|
||||
)
|
||||
|
||||
def get_type_name(self):
|
||||
"""Return the type of the sensor."""
|
||||
return TYPE_TRANSLATION.get(self._device.type, self._device.type)
|
|
@ -11,7 +11,8 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import DOMAIN, LupusecDevice
|
||||
from . import DOMAIN
|
||||
from .entity import LupusecBaseSensor
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=2)
|
||||
|
||||
|
@ -29,14 +30,16 @@ async def async_setup_entry(
|
|||
|
||||
switches = []
|
||||
for device in data.lupusec.get_devices(generic_type=device_types):
|
||||
switches.append(LupusecSwitch(data, device))
|
||||
switches.append(LupusecSwitch(data, device, config_entry.entry_id))
|
||||
|
||||
async_add_devices(switches)
|
||||
|
||||
|
||||
class LupusecSwitch(LupusecDevice, SwitchEntity):
|
||||
class LupusecSwitch(LupusecBaseSensor, SwitchEntity):
|
||||
"""Representation of a Lupusec switch."""
|
||||
|
||||
_attr_name = None
|
||||
|
||||
def turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn on the device."""
|
||||
self._device.switch_on()
|
||||
|
|
Loading…
Add table
Reference in a new issue