mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Use attributes in smarty fan (#73895)
This commit is contained in:
parent
03f0916e7c
commit
0df0533cd4
@ -3,6 +3,8 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from pysmarty import Smarty
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorDeviceClass,
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
@ -24,8 +26,8 @@ async def async_setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Smarty Binary Sensor Platform."""
|
"""Set up the Smarty Binary Sensor Platform."""
|
||||||
smarty = hass.data[DOMAIN]["api"]
|
smarty: Smarty = hass.data[DOMAIN]["api"]
|
||||||
name = hass.data[DOMAIN]["name"]
|
name: str = hass.data[DOMAIN]["name"]
|
||||||
|
|
||||||
sensors = [
|
sensors = [
|
||||||
AlarmSensor(name, smarty),
|
AlarmSensor(name, smarty),
|
||||||
@ -41,18 +43,23 @@ class SmartyBinarySensor(BinarySensorEntity):
|
|||||||
|
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, name, device_class, smarty):
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
device_class: BinarySensorDeviceClass | None,
|
||||||
|
smarty: Smarty,
|
||||||
|
) -> None:
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
self._attr_name = name
|
self._attr_name = name
|
||||||
self._attr_device_class = device_class
|
self._attr_device_class = device_class
|
||||||
self._smarty = smarty
|
self._smarty = smarty
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Call to update."""
|
"""Call to update."""
|
||||||
async_dispatcher_connect(self.hass, SIGNAL_UPDATE_SMARTY, self._update_callback)
|
async_dispatcher_connect(self.hass, SIGNAL_UPDATE_SMARTY, self._update_callback)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _update_callback(self):
|
def _update_callback(self) -> None:
|
||||||
"""Call update method."""
|
"""Call update method."""
|
||||||
self.async_schedule_update_ha_state(True)
|
self.async_schedule_update_ha_state(True)
|
||||||
|
|
||||||
@ -60,7 +67,7 @@ class SmartyBinarySensor(BinarySensorEntity):
|
|||||||
class BoostSensor(SmartyBinarySensor):
|
class BoostSensor(SmartyBinarySensor):
|
||||||
"""Boost State Binary Sensor."""
|
"""Boost State Binary Sensor."""
|
||||||
|
|
||||||
def __init__(self, name, smarty):
|
def __init__(self, name: str, smarty: Smarty) -> None:
|
||||||
"""Alarm Sensor Init."""
|
"""Alarm Sensor Init."""
|
||||||
super().__init__(name=f"{name} Boost State", device_class=None, smarty=smarty)
|
super().__init__(name=f"{name} Boost State", device_class=None, smarty=smarty)
|
||||||
|
|
||||||
@ -73,7 +80,7 @@ class BoostSensor(SmartyBinarySensor):
|
|||||||
class AlarmSensor(SmartyBinarySensor):
|
class AlarmSensor(SmartyBinarySensor):
|
||||||
"""Alarm Binary Sensor."""
|
"""Alarm Binary Sensor."""
|
||||||
|
|
||||||
def __init__(self, name, smarty):
|
def __init__(self, name: str, smarty: Smarty) -> None:
|
||||||
"""Alarm Sensor Init."""
|
"""Alarm Sensor Init."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
name=f"{name} Alarm",
|
name=f"{name} Alarm",
|
||||||
@ -90,7 +97,7 @@ class AlarmSensor(SmartyBinarySensor):
|
|||||||
class WarningSensor(SmartyBinarySensor):
|
class WarningSensor(SmartyBinarySensor):
|
||||||
"""Warning Sensor."""
|
"""Warning Sensor."""
|
||||||
|
|
||||||
def __init__(self, name, smarty):
|
def __init__(self, name: str, smarty: Smarty) -> None:
|
||||||
"""Warning Sensor Init."""
|
"""Warning Sensor Init."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
name=f"{name} Warning",
|
name=f"{name} Warning",
|
||||||
|
@ -5,6 +5,8 @@ import logging
|
|||||||
import math
|
import math
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from pysmarty import Smarty
|
||||||
|
|
||||||
from homeassistant.components.fan import FanEntity, FanEntityFeature
|
from homeassistant.components.fan import FanEntity, FanEntityFeature
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
@ -32,8 +34,8 @@ async def async_setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Smarty Fan Platform."""
|
"""Set up the Smarty Fan Platform."""
|
||||||
smarty = hass.data[DOMAIN]["api"]
|
smarty: Smarty = hass.data[DOMAIN]["api"]
|
||||||
name = hass.data[DOMAIN]["name"]
|
name: str = hass.data[DOMAIN]["name"]
|
||||||
|
|
||||||
async_add_entities([SmartyFan(name, smarty)], True)
|
async_add_entities([SmartyFan(name, smarty)], True)
|
||||||
|
|
||||||
@ -41,29 +43,16 @@ async def async_setup_platform(
|
|||||||
class SmartyFan(FanEntity):
|
class SmartyFan(FanEntity):
|
||||||
"""Representation of a Smarty Fan."""
|
"""Representation of a Smarty Fan."""
|
||||||
|
|
||||||
|
_attr_icon = "mdi:air-conditioner"
|
||||||
|
_attr_should_poll = False
|
||||||
_attr_supported_features = FanEntityFeature.SET_SPEED
|
_attr_supported_features = FanEntityFeature.SET_SPEED
|
||||||
|
|
||||||
def __init__(self, name, smarty):
|
def __init__(self, name, smarty):
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
self._name = name
|
self._attr_name = name
|
||||||
self._smarty_fan_speed = 0
|
self._smarty_fan_speed = 0
|
||||||
self._smarty = smarty
|
self._smarty = smarty
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Do not poll."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the fan."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Return the icon to use in the frontend."""
|
|
||||||
return "mdi:air-conditioner"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return state of the fan."""
|
"""Return state of the fan."""
|
||||||
@ -116,7 +105,7 @@ class SmartyFan(FanEntity):
|
|||||||
self._smarty_fan_speed = 0
|
self._smarty_fan_speed = 0
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Call to update fan."""
|
"""Call to update fan."""
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
@ -125,7 +114,7 @@ class SmartyFan(FanEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _update_callback(self):
|
def _update_callback(self) -> None:
|
||||||
"""Call update method."""
|
"""Call update method."""
|
||||||
_LOGGER.debug("Updating state")
|
_LOGGER.debug("Updating state")
|
||||||
self._smarty_fan_speed = self._smarty.fan_speed
|
self._smarty_fan_speed = self._smarty.fan_speed
|
||||||
|
@ -4,6 +4,8 @@ from __future__ import annotations
|
|||||||
import datetime as dt
|
import datetime as dt
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from pysmarty import Smarty
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||||
from homeassistant.const import TEMP_CELSIUS
|
from homeassistant.const import TEMP_CELSIUS
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
@ -24,8 +26,8 @@ async def async_setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Smarty Sensor Platform."""
|
"""Set up the Smarty Sensor Platform."""
|
||||||
smarty = hass.data[DOMAIN]["api"]
|
smarty: Smarty = hass.data[DOMAIN]["api"]
|
||||||
name = hass.data[DOMAIN]["name"]
|
name: str = hass.data[DOMAIN]["name"]
|
||||||
|
|
||||||
sensors = [
|
sensors = [
|
||||||
SupplyAirTemperatureSensor(name, smarty),
|
SupplyAirTemperatureSensor(name, smarty),
|
||||||
@ -45,8 +47,12 @@ class SmartySensor(SensorEntity):
|
|||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, name: str, device_class: str, smarty, unit_of_measurement: str = ""
|
self,
|
||||||
):
|
name: str,
|
||||||
|
device_class: SensorDeviceClass | None,
|
||||||
|
smarty: Smarty,
|
||||||
|
unit_of_measurement: str | None,
|
||||||
|
) -> None:
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
self._attr_name = name
|
self._attr_name = name
|
||||||
self._attr_native_value = None
|
self._attr_native_value = None
|
||||||
@ -54,12 +60,12 @@ class SmartySensor(SensorEntity):
|
|||||||
self._attr_native_unit_of_measurement = unit_of_measurement
|
self._attr_native_unit_of_measurement = unit_of_measurement
|
||||||
self._smarty = smarty
|
self._smarty = smarty
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Call to update."""
|
"""Call to update."""
|
||||||
async_dispatcher_connect(self.hass, SIGNAL_UPDATE_SMARTY, self._update_callback)
|
async_dispatcher_connect(self.hass, SIGNAL_UPDATE_SMARTY, self._update_callback)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _update_callback(self):
|
def _update_callback(self) -> None:
|
||||||
"""Call update method."""
|
"""Call update method."""
|
||||||
self.async_schedule_update_ha_state(True)
|
self.async_schedule_update_ha_state(True)
|
||||||
|
|
||||||
@ -67,7 +73,7 @@ class SmartySensor(SensorEntity):
|
|||||||
class SupplyAirTemperatureSensor(SmartySensor):
|
class SupplyAirTemperatureSensor(SmartySensor):
|
||||||
"""Supply Air Temperature Sensor."""
|
"""Supply Air Temperature Sensor."""
|
||||||
|
|
||||||
def __init__(self, name, smarty):
|
def __init__(self, name: str, smarty: Smarty) -> None:
|
||||||
"""Supply Air Temperature Init."""
|
"""Supply Air Temperature Init."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
name=f"{name} Supply Air Temperature",
|
name=f"{name} Supply Air Temperature",
|
||||||
@ -85,7 +91,7 @@ class SupplyAirTemperatureSensor(SmartySensor):
|
|||||||
class ExtractAirTemperatureSensor(SmartySensor):
|
class ExtractAirTemperatureSensor(SmartySensor):
|
||||||
"""Extract Air Temperature Sensor."""
|
"""Extract Air Temperature Sensor."""
|
||||||
|
|
||||||
def __init__(self, name, smarty):
|
def __init__(self, name: str, smarty: Smarty) -> None:
|
||||||
"""Supply Air Temperature Init."""
|
"""Supply Air Temperature Init."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
name=f"{name} Extract Air Temperature",
|
name=f"{name} Extract Air Temperature",
|
||||||
@ -103,7 +109,7 @@ class ExtractAirTemperatureSensor(SmartySensor):
|
|||||||
class OutdoorAirTemperatureSensor(SmartySensor):
|
class OutdoorAirTemperatureSensor(SmartySensor):
|
||||||
"""Extract Air Temperature Sensor."""
|
"""Extract Air Temperature Sensor."""
|
||||||
|
|
||||||
def __init__(self, name, smarty):
|
def __init__(self, name: str, smarty: Smarty) -> None:
|
||||||
"""Outdoor Air Temperature Init."""
|
"""Outdoor Air Temperature Init."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
name=f"{name} Outdoor Air Temperature",
|
name=f"{name} Outdoor Air Temperature",
|
||||||
@ -121,7 +127,7 @@ class OutdoorAirTemperatureSensor(SmartySensor):
|
|||||||
class SupplyFanSpeedSensor(SmartySensor):
|
class SupplyFanSpeedSensor(SmartySensor):
|
||||||
"""Supply Fan Speed RPM."""
|
"""Supply Fan Speed RPM."""
|
||||||
|
|
||||||
def __init__(self, name, smarty):
|
def __init__(self, name: str, smarty: Smarty) -> None:
|
||||||
"""Supply Fan Speed RPM Init."""
|
"""Supply Fan Speed RPM Init."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
name=f"{name} Supply Fan Speed",
|
name=f"{name} Supply Fan Speed",
|
||||||
@ -139,7 +145,7 @@ class SupplyFanSpeedSensor(SmartySensor):
|
|||||||
class ExtractFanSpeedSensor(SmartySensor):
|
class ExtractFanSpeedSensor(SmartySensor):
|
||||||
"""Extract Fan Speed RPM."""
|
"""Extract Fan Speed RPM."""
|
||||||
|
|
||||||
def __init__(self, name, smarty):
|
def __init__(self, name: str, smarty: Smarty) -> None:
|
||||||
"""Extract Fan Speed RPM Init."""
|
"""Extract Fan Speed RPM Init."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
name=f"{name} Extract Fan Speed",
|
name=f"{name} Extract Fan Speed",
|
||||||
@ -157,7 +163,7 @@ class ExtractFanSpeedSensor(SmartySensor):
|
|||||||
class FilterDaysLeftSensor(SmartySensor):
|
class FilterDaysLeftSensor(SmartySensor):
|
||||||
"""Filter Days Left."""
|
"""Filter Days Left."""
|
||||||
|
|
||||||
def __init__(self, name, smarty):
|
def __init__(self, name: str, smarty: Smarty) -> None:
|
||||||
"""Filter Days Left Init."""
|
"""Filter Days Left Init."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
name=f"{name} Filter Days Left",
|
name=f"{name} Filter Days Left",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user