Skip to content
Snippets Groups Projects
Unverified Commit 5818b614 authored by suaveolent's avatar suaveolent Committed by GitHub
Browse files

Added type information to lupusec (#109004)

parent 6ef0b9bf
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
"""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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment