diff --git a/homeassistant/components/lupusec/__init__.py b/homeassistant/components/lupusec/__init__.py index 7493059e9e9effb1790e1abe50d97bf9d4c90130..bf7c30845a3cb71099b4d80fc041504f521c6897 100644 --- a/homeassistant/components/lupusec/__init__.py +++ b/homeassistant/components/lupusec/__init__.py @@ -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) diff --git a/homeassistant/components/lupusec/alarm_control_panel.py b/homeassistant/components/lupusec/alarm_control_panel.py index 2a904c34410d600e660df747c86cf7f6af34f01d..2e4ca5cab63cc232523834aa66d5bf7ea8f02212 100644 --- a/homeassistant/components/lupusec/alarm_control_panel.py +++ b/homeassistant/components/lupusec/alarm_control_panel.py @@ -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 diff --git a/homeassistant/components/lupusec/binary_sensor.py b/homeassistant/components/lupusec/binary_sensor.py index 06a07c070c6b953b8b332fa7724bbe6298042aec..ecff9a6266d024ab59f9bfd609d4c7dee5657876 100644 --- a/homeassistant/components/lupusec/binary_sensor.py +++ b/homeassistant/components/lupusec/binary_sensor.py @@ -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 diff --git a/homeassistant/components/lupusec/entity.py b/homeassistant/components/lupusec/entity.py index 208a0edafaac005f83eae40a4c16816115120902..6237e5dd16b1646b5a85c68521012512e9c6ec96 100644 --- a/homeassistant/components/lupusec/entity.py +++ b/homeassistant/components/lupusec/entity.py @@ -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) diff --git a/homeassistant/components/lupusec/switch.py b/homeassistant/components/lupusec/switch.py index 7b87b2cac55a8e1bec09fc33667f6fd3d65683f3..a2b3796ef5bb7e26b5fa9925f1ecea677b235b6f 100644 --- a/homeassistant/components/lupusec/switch.py +++ b/homeassistant/components/lupusec/switch.py @@ -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