From 0cbcb9e0d6a82463f1bc9cbe65508743091825f5 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 23 May 2021 05:32:41 +0200 Subject: [PATCH] Fix Hue overriding property methods, remove ignored typing (#50976) --- homeassistant/components/hue/binary_sensor.py | 2 +- homeassistant/components/hue/sensor.py | 27 ++++++------------- homeassistant/components/hue/sensor_base.py | 5 +++- mypy.ini | 3 --- script/hassfest/mypy_config.py | 1 - 5 files changed, 13 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/hue/binary_sensor.py b/homeassistant/components/hue/binary_sensor.py index d5c6953700d..c675544503c 100644 --- a/homeassistant/components/hue/binary_sensor.py +++ b/homeassistant/components/hue/binary_sensor.py @@ -27,7 +27,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): class HuePresence(GenericZLLSensor, BinarySensorEntity): """The presence sensor entity for a Hue motion sensor device.""" - device_class = DEVICE_CLASS_MOTION + _attr_device_class = DEVICE_CLASS_MOTION @property def is_on(self): diff --git a/homeassistant/components/hue/sensor.py b/homeassistant/components/hue/sensor.py index 75d31fb61ce..0f1fa418287 100644 --- a/homeassistant/components/hue/sensor.py +++ b/homeassistant/components/hue/sensor.py @@ -41,8 +41,8 @@ class GenericHueGaugeSensorEntity(GenericZLLSensor, SensorEntity): class HueLightLevel(GenericHueGaugeSensorEntity): """The light level sensor entity for a Hue motion sensor device.""" - device_class = DEVICE_CLASS_ILLUMINANCE - unit_of_measurement = LIGHT_LUX + _attr_device_class = DEVICE_CLASS_ILLUMINANCE + _attr_unit_of_measurement = LIGHT_LUX @property def state(self): @@ -76,8 +76,9 @@ class HueLightLevel(GenericHueGaugeSensorEntity): class HueTemperature(GenericHueGaugeSensorEntity): """The temperature sensor entity for a Hue motion sensor device.""" - device_class = DEVICE_CLASS_TEMPERATURE - unit_of_measurement = TEMP_CELSIUS + _attr_device_class = DEVICE_CLASS_TEMPERATURE + _attr_state_class = STATE_CLASS_MEASUREMENT + _attr_unit_of_measurement = TEMP_CELSIUS @property def state(self): @@ -87,15 +88,13 @@ class HueTemperature(GenericHueGaugeSensorEntity): return self.sensor.temperature / 100 - @property - def state_class(self): - """Return the state class of the sensor.""" - return STATE_CLASS_MEASUREMENT - class HueBattery(GenericHueSensor, SensorEntity): """Battery class for when a batt-powered device is only represented as an event.""" + _attr_device_class = DEVICE_CLASS_BATTERY + _attr_unit_of_measurement = PERCENTAGE + @property def unique_id(self): """Return a unique identifier for this device.""" @@ -106,16 +105,6 @@ class HueBattery(GenericHueSensor, SensorEntity): """Return the state of the battery.""" return self.sensor.battery - @property - def device_class(self): - """Return the class of the sensor.""" - return DEVICE_CLASS_BATTERY - - @property - def unit_of_measurement(self): - """Return the unit of measurement of this entity.""" - return PERCENTAGE - SENSOR_CONFIG_MAP.update( { diff --git a/homeassistant/components/hue/sensor_base.py b/homeassistant/components/hue/sensor_base.py index bb527c63b2a..824f8cf42dc 100644 --- a/homeassistant/components/hue/sensor_base.py +++ b/homeassistant/components/hue/sensor_base.py @@ -1,6 +1,9 @@ """Support for the Philips Hue sensors as a platform.""" +from __future__ import annotations + from datetime import timedelta import logging +from typing import Any from aiohue import AiohueException, Unauthorized from aiohue.sensors import TYPE_ZLL_PRESENCE @@ -16,7 +19,7 @@ from .helpers import remove_devices from .hue_event import EVENT_CONFIG_MAP from .sensor_device import GenericHueDevice -SENSOR_CONFIG_MAP = {} +SENSOR_CONFIG_MAP: dict[str, Any] = {} _LOGGER = logging.getLogger(__name__) diff --git a/mypy.ini b/mypy.ini index bb75b29fa6d..2cb4d318962 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1012,9 +1012,6 @@ ignore_errors = true [mypy-homeassistant.components.honeywell.*] ignore_errors = true -[mypy-homeassistant.components.hue.*] -ignore_errors = true - [mypy-homeassistant.components.huisbaasje.*] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index 1b49dd023f7..f5337d8e5ed 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -91,7 +91,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.homekit_controller.*", "homeassistant.components.homematicip_cloud.*", "homeassistant.components.honeywell.*", - "homeassistant.components.hue.*", "homeassistant.components.huisbaasje.*", "homeassistant.components.humidifier.*", "homeassistant.components.iaqualink.*",