Improve type hints in xs1 entities (#145299)

This commit is contained in:
epenet
2025-05-20 10:44:34 +02:00
committed by GitHub
parent 15915680b5
commit 7f9b454922
3 changed files with 15 additions and 10 deletions

View File

@@ -2,6 +2,8 @@
import asyncio
from xs1_api_client.device import XS1Device
from homeassistant.helpers.entity import Entity
# Lock used to limit the amount of concurrent update requests
@@ -13,7 +15,7 @@ UPDATE_LOCK = asyncio.Lock()
class XS1DeviceEntity(Entity):
"""Representation of a base XS1 device."""
def __init__(self, device):
def __init__(self, device: XS1Device) -> None:
"""Initialize the XS1 device."""
self.device = device

View File

@@ -3,6 +3,8 @@
from __future__ import annotations
from xs1_api_client.api_constants import ActuatorType
from xs1_api_client.device.actuator import XS1Actuator
from xs1_api_client.device.sensor import XS1Sensor
from homeassistant.components.sensor import SensorEntity
from homeassistant.core import HomeAssistant
@@ -20,8 +22,8 @@ def setup_platform(
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the XS1 sensor platform."""
sensors = hass.data[DOMAIN][SENSORS]
actuators = hass.data[DOMAIN][ACTUATORS]
sensors: list[XS1Sensor] = hass.data[DOMAIN][SENSORS]
actuators: list[XS1Actuator] = hass.data[DOMAIN][ACTUATORS]
sensor_entities = []
for sensor in sensors:
@@ -35,16 +37,16 @@ def setup_platform(
break
if not belongs_to_climate_actuator:
sensor_entities.append(XS1Sensor(sensor))
sensor_entities.append(XS1SensorEntity(sensor))
add_entities(sensor_entities)
class XS1Sensor(XS1DeviceEntity, SensorEntity):
class XS1SensorEntity(XS1DeviceEntity, SensorEntity):
"""Representation of a Sensor."""
@property
def name(self):
def name(self) -> str:
"""Return the name of the sensor."""
return self.device.name()
@@ -54,6 +56,6 @@ class XS1Sensor(XS1DeviceEntity, SensorEntity):
return self.device.value()
@property
def native_unit_of_measurement(self):
def native_unit_of_measurement(self) -> str:
"""Return the unit of measurement."""
return self.device.unit()

View File

@@ -5,6 +5,7 @@ from __future__ import annotations
from typing import Any
from xs1_api_client.api_constants import ActuatorType
from xs1_api_client.device.actuator import XS1Actuator
from homeassistant.components.switch import SwitchEntity
from homeassistant.core import HomeAssistant
@@ -22,7 +23,7 @@ def setup_platform(
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the XS1 switch platform."""
actuators = hass.data[DOMAIN][ACTUATORS]
actuators: list[XS1Actuator] = hass.data[DOMAIN][ACTUATORS]
add_entities(
XS1SwitchEntity(actuator)
@@ -36,12 +37,12 @@ class XS1SwitchEntity(XS1DeviceEntity, SwitchEntity):
"""Representation of a XS1 switch actuator."""
@property
def name(self):
def name(self) -> str:
"""Return the name of the device if any."""
return self.device.name()
@property
def is_on(self):
def is_on(self) -> bool:
"""Return true if switch is on."""
return self.device.value() == 100