mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Added type information to lupusec (#109004)
Co-authored-by: suaveolent <suaveolent@users.noreply.github.com>
This commit is contained in:
parent
6ef0b9bf97
commit
5818b6141a
@ -109,11 +109,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
lupusec_system = await hass.async_add_executor_job(
|
lupusec_system = await hass.async_add_executor_job(
|
||||||
LupusecSystem,
|
lupupy.Lupusec, username, password, host
|
||||||
username,
|
|
||||||
password,
|
|
||||||
host,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
except LupusecException:
|
except LupusecException:
|
||||||
_LOGGER.error("Failed to connect to Lupusec device at %s", host)
|
_LOGGER.error("Failed to connect to Lupusec device at %s", host)
|
||||||
return False
|
return False
|
||||||
@ -130,11 +128,3 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class LupusecSystem:
|
|
||||||
"""Lupusec System class."""
|
|
||||||
|
|
||||||
def __init__(self, username, password, ip_address) -> None:
|
|
||||||
"""Initialize the system."""
|
|
||||||
self.lupusec = lupupy.Lupusec(username, password, ip_address)
|
|
||||||
|
@ -3,6 +3,8 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
import lupupy
|
||||||
|
|
||||||
from homeassistant.components.alarm_control_panel import (
|
from homeassistant.components.alarm_control_panel import (
|
||||||
AlarmControlPanelEntity,
|
AlarmControlPanelEntity,
|
||||||
AlarmControlPanelEntityFeature,
|
AlarmControlPanelEntityFeature,
|
||||||
@ -32,9 +34,7 @@ async def async_setup_entry(
|
|||||||
"""Set up an alarm control panel for a Lupusec device."""
|
"""Set up an alarm control panel for a Lupusec device."""
|
||||||
data = hass.data[DOMAIN][config_entry.entry_id]
|
data = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
|
||||||
alarm_devices = [
|
alarm_devices = [LupusecAlarm(data, data.get_alarm(), config_entry.entry_id)]
|
||||||
LupusecAlarm(data, data.lupusec.get_alarm(), config_entry.entry_id)
|
|
||||||
]
|
|
||||||
|
|
||||||
async_add_devices(alarm_devices)
|
async_add_devices(alarm_devices)
|
||||||
|
|
||||||
@ -49,15 +49,17 @@ class LupusecAlarm(LupusecDevice, AlarmControlPanelEntity):
|
|||||||
| AlarmControlPanelEntityFeature.ARM_AWAY
|
| AlarmControlPanelEntityFeature.ARM_AWAY
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, data, device, entry_id) -> None:
|
def __init__(
|
||||||
|
self, data: lupupy.Lupusec, device: lupupy.devices.LupusecAlarm, entry_id: str
|
||||||
|
) -> None:
|
||||||
"""Initialize the LupusecAlarm class."""
|
"""Initialize the LupusecAlarm class."""
|
||||||
super().__init__(data, device, entry_id)
|
super().__init__(device)
|
||||||
self._attr_unique_id = entry_id
|
self._attr_unique_id = entry_id
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, entry_id)},
|
identifiers={(DOMAIN, entry_id)},
|
||||||
name=device.name,
|
name=device.name,
|
||||||
manufacturer="Lupus Electronics",
|
manufacturer="Lupus Electronics",
|
||||||
model=f"Lupusec-XT{data.lupusec.model}",
|
model=f"Lupusec-XT{data.model}",
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -34,8 +34,8 @@ async def async_setup_entry(
|
|||||||
device_types = CONST.TYPE_OPENING + CONST.TYPE_SENSOR
|
device_types = CONST.TYPE_OPENING + CONST.TYPE_SENSOR
|
||||||
|
|
||||||
sensors = []
|
sensors = []
|
||||||
for device in data.lupusec.get_devices(generic_type=device_types):
|
for device in data.get_devices(generic_type=device_types):
|
||||||
sensors.append(LupusecBinarySensor(data, device, config_entry.entry_id))
|
sensors.append(LupusecBinarySensor(device, config_entry.entry_id))
|
||||||
|
|
||||||
async_add_devices(sensors)
|
async_add_devices(sensors)
|
||||||
|
|
||||||
@ -46,12 +46,12 @@ class LupusecBinarySensor(LupusecBaseSensor, BinarySensorEntity):
|
|||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self) -> bool:
|
||||||
"""Return True if the binary sensor is on."""
|
"""Return True if the binary sensor is on."""
|
||||||
return self._device.is_on
|
return self._device.is_on
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self) -> BinarySensorDeviceClass | None:
|
||||||
"""Return the class of the binary sensor."""
|
"""Return the class of the binary sensor."""
|
||||||
if self._device.generic_type not in (
|
if self._device.generic_type not in (
|
||||||
item.value for item in BinarySensorDeviceClass
|
item.value for item in BinarySensorDeviceClass
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Provides the Lupusec entity for Home Assistant."""
|
"""Provides the Lupusec entity for Home Assistant."""
|
||||||
|
import lupupy
|
||||||
|
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
@ -10,9 +12,8 @@ class LupusecDevice(Entity):
|
|||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(self, data, device, entry_id) -> None:
|
def __init__(self, device: lupupy.devices.LupusecDevice) -> None:
|
||||||
"""Initialize a sensor for Lupusec device."""
|
"""Initialize a sensor for Lupusec device."""
|
||||||
self._data = data
|
|
||||||
self._device = device
|
self._device = device
|
||||||
self._attr_unique_id = device.device_id
|
self._attr_unique_id = device.device_id
|
||||||
|
|
||||||
@ -24,9 +25,9 @@ class LupusecDevice(Entity):
|
|||||||
class LupusecBaseSensor(LupusecDevice):
|
class LupusecBaseSensor(LupusecDevice):
|
||||||
"""Lupusec Sensor base entity."""
|
"""Lupusec Sensor base entity."""
|
||||||
|
|
||||||
def __init__(self, data, device, entry_id) -> None:
|
def __init__(self, device: lupupy.devices.LupusecDevice, entry_id: str) -> None:
|
||||||
"""Initialize the LupusecBaseSensor."""
|
"""Initialize the LupusecBaseSensor."""
|
||||||
super().__init__(data, device, entry_id)
|
super().__init__(device)
|
||||||
|
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, device.device_id)},
|
identifiers={(DOMAIN, device.device_id)},
|
||||||
@ -37,6 +38,6 @@ class LupusecBaseSensor(LupusecDevice):
|
|||||||
via_device=(DOMAIN, entry_id),
|
via_device=(DOMAIN, entry_id),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_type_name(self):
|
def get_type_name(self) -> str:
|
||||||
"""Return the type of the sensor."""
|
"""Return the type of the sensor."""
|
||||||
return TYPE_TRANSLATION.get(self._device.type, self._device.type)
|
return TYPE_TRANSLATION.get(self._device.type, self._device.type)
|
||||||
|
@ -29,8 +29,8 @@ async def async_setup_entry(
|
|||||||
device_types = CONST.TYPE_SWITCH
|
device_types = CONST.TYPE_SWITCH
|
||||||
|
|
||||||
switches = []
|
switches = []
|
||||||
for device in data.lupusec.get_devices(generic_type=device_types):
|
for device in data.get_devices(generic_type=device_types):
|
||||||
switches.append(LupusecSwitch(data, device, config_entry.entry_id))
|
switches.append(LupusecSwitch(device, config_entry.entry_id))
|
||||||
|
|
||||||
async_add_devices(switches)
|
async_add_devices(switches)
|
||||||
|
|
||||||
@ -49,6 +49,6 @@ class LupusecSwitch(LupusecBaseSensor, SwitchEntity):
|
|||||||
self._device.switch_off()
|
self._device.switch_off()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self) -> bool:
|
||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
return self._device.is_on
|
return self._device.is_on
|
||||||
|
Loading…
x
Reference in New Issue
Block a user