1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00
ha-core/homeassistant/components/xs1/sensor.py
epenet 26819d1132
Add sensor setup type hints [w-z] (#63308)
Co-authored-by: epenet <epenet@users.noreply.github.com>
2022-01-03 18:45:33 +01:00

58 lines
1.7 KiB
Python

"""Support for XS1 sensors."""
from __future__ import annotations
from xs1_api_client.api_constants import ActuatorType
from homeassistant.components.sensor import SensorEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import ACTUATORS, DOMAIN as COMPONENT_DOMAIN, SENSORS, XS1DeviceEntity
def setup_platform(
hass: HomeAssistant,
config: ConfigType,
add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the XS1 sensor platform."""
sensors = hass.data[COMPONENT_DOMAIN][SENSORS]
actuators = hass.data[COMPONENT_DOMAIN][ACTUATORS]
sensor_entities = []
for sensor in sensors:
belongs_to_climate_actuator = False
for actuator in actuators:
if (
actuator.type() == ActuatorType.TEMPERATURE
and actuator.name() in sensor.name()
):
belongs_to_climate_actuator = True
break
if not belongs_to_climate_actuator:
sensor_entities.append(XS1Sensor(sensor))
add_entities(sensor_entities)
class XS1Sensor(XS1DeviceEntity, SensorEntity):
"""Representation of a Sensor."""
@property
def name(self):
"""Return the name of the sensor."""
return self.device.name()
@property
def native_value(self):
"""Return the state of the sensor."""
return self.device.value()
@property
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return self.device.unit()