mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Improve type hints in xs1 entities (#145299)
This commit is contained in:
parent
15915680b5
commit
7f9b454922
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
from xs1_api_client.device import XS1Device
|
||||||
|
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
# Lock used to limit the amount of concurrent update requests
|
# Lock used to limit the amount of concurrent update requests
|
||||||
@ -13,7 +15,7 @@ UPDATE_LOCK = asyncio.Lock()
|
|||||||
class XS1DeviceEntity(Entity):
|
class XS1DeviceEntity(Entity):
|
||||||
"""Representation of a base XS1 device."""
|
"""Representation of a base XS1 device."""
|
||||||
|
|
||||||
def __init__(self, device):
|
def __init__(self, device: XS1Device) -> None:
|
||||||
"""Initialize the XS1 device."""
|
"""Initialize the XS1 device."""
|
||||||
self.device = device
|
self.device = device
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from xs1_api_client.api_constants import ActuatorType
|
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.components.sensor import SensorEntity
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -20,8 +22,8 @@ def setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the XS1 sensor platform."""
|
"""Set up the XS1 sensor platform."""
|
||||||
sensors = hass.data[DOMAIN][SENSORS]
|
sensors: list[XS1Sensor] = hass.data[DOMAIN][SENSORS]
|
||||||
actuators = hass.data[DOMAIN][ACTUATORS]
|
actuators: list[XS1Actuator] = hass.data[DOMAIN][ACTUATORS]
|
||||||
|
|
||||||
sensor_entities = []
|
sensor_entities = []
|
||||||
for sensor in sensors:
|
for sensor in sensors:
|
||||||
@ -35,16 +37,16 @@ def setup_platform(
|
|||||||
break
|
break
|
||||||
|
|
||||||
if not belongs_to_climate_actuator:
|
if not belongs_to_climate_actuator:
|
||||||
sensor_entities.append(XS1Sensor(sensor))
|
sensor_entities.append(XS1SensorEntity(sensor))
|
||||||
|
|
||||||
add_entities(sensor_entities)
|
add_entities(sensor_entities)
|
||||||
|
|
||||||
|
|
||||||
class XS1Sensor(XS1DeviceEntity, SensorEntity):
|
class XS1SensorEntity(XS1DeviceEntity, SensorEntity):
|
||||||
"""Representation of a Sensor."""
|
"""Representation of a Sensor."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self) -> str:
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self.device.name()
|
return self.device.name()
|
||||||
|
|
||||||
@ -54,6 +56,6 @@ class XS1Sensor(XS1DeviceEntity, SensorEntity):
|
|||||||
return self.device.value()
|
return self.device.value()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_unit_of_measurement(self):
|
def native_unit_of_measurement(self) -> str:
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
return self.device.unit()
|
return self.device.unit()
|
||||||
|
@ -5,6 +5,7 @@ from __future__ import annotations
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from xs1_api_client.api_constants import ActuatorType
|
from xs1_api_client.api_constants import ActuatorType
|
||||||
|
from xs1_api_client.device.actuator import XS1Actuator
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -22,7 +23,7 @@ def setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the XS1 switch platform."""
|
"""Set up the XS1 switch platform."""
|
||||||
actuators = hass.data[DOMAIN][ACTUATORS]
|
actuators: list[XS1Actuator] = hass.data[DOMAIN][ACTUATORS]
|
||||||
|
|
||||||
add_entities(
|
add_entities(
|
||||||
XS1SwitchEntity(actuator)
|
XS1SwitchEntity(actuator)
|
||||||
@ -36,12 +37,12 @@ class XS1SwitchEntity(XS1DeviceEntity, SwitchEntity):
|
|||||||
"""Representation of a XS1 switch actuator."""
|
"""Representation of a XS1 switch actuator."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self) -> str:
|
||||||
"""Return the name of the device if any."""
|
"""Return the name of the device if any."""
|
||||||
return self.device.name()
|
return self.device.name()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self) -> bool:
|
||||||
"""Return true if switch is on."""
|
"""Return true if switch is on."""
|
||||||
return self.device.value() == 100
|
return self.device.value() == 100
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user