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