mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +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:
|
||||
lupusec_system = await hass.async_add_executor_job(
|
||||
LupusecSystem,
|
||||
username,
|
||||
password,
|
||||
host,
|
||||
lupupy.Lupusec, username, password, host
|
||||
)
|
||||
|
||||
except LupusecException:
|
||||
_LOGGER.error("Failed to connect to Lupusec device at %s", host)
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
import lupupy
|
||||
|
||||
from homeassistant.components.alarm_control_panel import (
|
||||
AlarmControlPanelEntity,
|
||||
AlarmControlPanelEntityFeature,
|
||||
@ -32,9 +34,7 @@ async def async_setup_entry(
|
||||
"""Set up an alarm control panel for a Lupusec device."""
|
||||
data = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
alarm_devices = [
|
||||
LupusecAlarm(data, data.lupusec.get_alarm(), config_entry.entry_id)
|
||||
]
|
||||
alarm_devices = [LupusecAlarm(data, data.get_alarm(), config_entry.entry_id)]
|
||||
|
||||
async_add_devices(alarm_devices)
|
||||
|
||||
@ -49,15 +49,17 @@ class LupusecAlarm(LupusecDevice, AlarmControlPanelEntity):
|
||||
| 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."""
|
||||
super().__init__(data, device, entry_id)
|
||||
super().__init__(device)
|
||||
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}",
|
||||
model=f"Lupusec-XT{data.model}",
|
||||
)
|
||||
|
||||
@property
|
||||
|
@ -34,8 +34,8 @@ async def async_setup_entry(
|
||||
device_types = CONST.TYPE_OPENING + CONST.TYPE_SENSOR
|
||||
|
||||
sensors = []
|
||||
for device in data.lupusec.get_devices(generic_type=device_types):
|
||||
sensors.append(LupusecBinarySensor(data, device, config_entry.entry_id))
|
||||
for device in data.get_devices(generic_type=device_types):
|
||||
sensors.append(LupusecBinarySensor(device, config_entry.entry_id))
|
||||
|
||||
async_add_devices(sensors)
|
||||
|
||||
@ -46,12 +46,12 @@ class LupusecBinarySensor(LupusecBaseSensor, BinarySensorEntity):
|
||||
_attr_name = None
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
def is_on(self) -> bool:
|
||||
"""Return True if the binary sensor is on."""
|
||||
return self._device.is_on
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
def device_class(self) -> BinarySensorDeviceClass | None:
|
||||
"""Return the class of the binary sensor."""
|
||||
if self._device.generic_type not in (
|
||||
item.value for item in BinarySensorDeviceClass
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Provides the Lupusec entity for Home Assistant."""
|
||||
import lupupy
|
||||
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
@ -10,9 +12,8 @@ class LupusecDevice(Entity):
|
||||
|
||||
_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."""
|
||||
self._data = data
|
||||
self._device = device
|
||||
self._attr_unique_id = device.device_id
|
||||
|
||||
@ -24,9 +25,9 @@ class LupusecDevice(Entity):
|
||||
class LupusecBaseSensor(LupusecDevice):
|
||||
"""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."""
|
||||
super().__init__(data, device, entry_id)
|
||||
super().__init__(device)
|
||||
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, device.device_id)},
|
||||
@ -37,6 +38,6 @@ class LupusecBaseSensor(LupusecDevice):
|
||||
via_device=(DOMAIN, entry_id),
|
||||
)
|
||||
|
||||
def get_type_name(self):
|
||||
def get_type_name(self) -> str:
|
||||
"""Return the type of the sensor."""
|
||||
return TYPE_TRANSLATION.get(self._device.type, self._device.type)
|
||||
|
@ -29,8 +29,8 @@ async def async_setup_entry(
|
||||
device_types = CONST.TYPE_SWITCH
|
||||
|
||||
switches = []
|
||||
for device in data.lupusec.get_devices(generic_type=device_types):
|
||||
switches.append(LupusecSwitch(data, device, config_entry.entry_id))
|
||||
for device in data.get_devices(generic_type=device_types):
|
||||
switches.append(LupusecSwitch(device, config_entry.entry_id))
|
||||
|
||||
async_add_devices(switches)
|
||||
|
||||
@ -49,6 +49,6 @@ class LupusecSwitch(LupusecBaseSensor, SwitchEntity):
|
||||
self._device.switch_off()
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if device is on."""
|
||||
return self._device.is_on
|
||||
|
Loading…
x
Reference in New Issue
Block a user