diff --git a/custom_components/hive_mqtt_orchestrator/__init__.py b/custom_components/hive_mqtt_orchestrator/__init__.py index d60be2d..c61719a 100644 --- a/custom_components/hive_mqtt_orchestrator/__init__.py +++ b/custom_components/hive_mqtt_orchestrator/__init__.py @@ -13,12 +13,9 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.typing import ConfigType from homeassistant.helpers import config_validation as cv -from homeassistant.exceptions import ConfigEntryAuthFailed from homeassistant.const import __version__ as HA_VERSION # noqa: N812 -from homeassistant.components.mqtt import valid_subscribe_topic from homeassistant.components.mqtt import client as mqtt_client from homeassistant.components.mqtt.models import ReceiveMessage diff --git a/custom_components/hive_mqtt_orchestrator/climate.py b/custom_components/hive_mqtt_orchestrator/climate.py index c166171..73751da 100644 --- a/custom_components/hive_mqtt_orchestrator/climate.py +++ b/custom_components/hive_mqtt_orchestrator/climate.py @@ -13,7 +13,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.components.mqtt import client as mqtt_client from homeassistant.components.climate import ( - ATTR_HVAC_MODE, PRESET_BOOST, PRESET_NONE, ClimateEntity, @@ -27,6 +26,8 @@ Platform ) +from .entity import HiveEntity, HiveEntityDescription + from .const import ( DOMAIN, LOGGER, @@ -44,10 +45,6 @@ PRESET_BOOST: HIVE_BOOST, } -from .entity import HiveEntity, HiveEntityDescription - -from datetime import timedelta - @dataclass class HiveClimateEntityDescription( HiveEntityDescription, diff --git a/custom_components/hive_mqtt_orchestrator/config_flow.py b/custom_components/hive_mqtt_orchestrator/config_flow.py index 702b4da..da594ce 100644 --- a/custom_components/hive_mqtt_orchestrator/config_flow.py +++ b/custom_components/hive_mqtt_orchestrator/config_flow.py @@ -2,7 +2,7 @@ from __future__ import annotations from collections.abc import Mapping -from typing import Any, Dict, cast +from typing import Any, dict, cast import voluptuous as vol from homeassistant.const import CONF_NAME diff --git a/custom_components/hive_mqtt_orchestrator/const.py b/custom_components/hive_mqtt_orchestrator/const.py index 590fe50..71a7800 100644 --- a/custom_components/hive_mqtt_orchestrator/const.py +++ b/custom_components/hive_mqtt_orchestrator/const.py @@ -41,4 +41,4 @@ WATER_MODES: Final = ["auto", "heat", "off", "emergency_heat"] -ICON_UNKNOWN = "mdi:help" \ No newline at end of file +ICON_UNKNOWN = "mdi:help" diff --git a/custom_components/hive_mqtt_orchestrator/entity.py b/custom_components/hive_mqtt_orchestrator/entity.py index 4884f7c..c1853f8 100644 --- a/custom_components/hive_mqtt_orchestrator/entity.py +++ b/custom_components/hive_mqtt_orchestrator/entity.py @@ -8,7 +8,7 @@ from homeassistant.helpers.entity import DeviceInfo, EntityDescription -from .const import DOMAIN, NAME, VERSION, MANUFACTURER +from .const import DOMAIN, VERSION, MANUFACTURER @dataclass @@ -46,9 +46,11 @@ def __init__( @abc.abstractmethod def process_update(self, mqtt_data) -> None: + """To be implemented by entities to process updates from MQTT.""" raise NotImplementedError('users must define process_update to use this base class') def get_entity_value(self, entity_key: str, default: float = None) -> float: + """Get an entities value store in hass data.""" if not self.entity_description.entry_id in self.hass.data[DOMAIN]: return default diff --git a/custom_components/hive_mqtt_orchestrator/number.py b/custom_components/hive_mqtt_orchestrator/number.py index fc90a60..05ce51e 100644 --- a/custom_components/hive_mqtt_orchestrator/number.py +++ b/custom_components/hive_mqtt_orchestrator/number.py @@ -2,7 +2,6 @@ from __future__ import annotations -from typing import Any, cast from dataclasses import dataclass from homeassistant.core import HomeAssistant @@ -11,7 +10,6 @@ from homeassistant.helpers.entity import DeviceInfo, EntityCategory from homeassistant.components.number import ( NumberEntityDescription, - NumberExtraStoredData, NumberMode, RestoreNumber, NumberDeviceClass, @@ -21,9 +19,6 @@ from homeassistant.util.dt import utcnow from homeassistant.const import ( Platform, - UnitOfInformation, - CONF_NAME, - CONF_ENTITIES, STATE_UNAVAILABLE, STATE_UNKNOWN, ) @@ -190,7 +185,7 @@ async def async_added_to_hass(self) -> None: else: self._state = self.entity_description.default_value - if not self.entity_description.entry_id in self.hass.data[DOMAIN]: + if self.entity_description.entry_id not in self.hass.data[DOMAIN]: self.hass.data[DOMAIN][self.entity_description.entry_id] = [] self.hass.data[DOMAIN][self.entity_description.entry_id][self.entity_description.key] = self._state @@ -207,7 +202,7 @@ async def async_set_native_value(self, value: float) -> None: self._state = value self._last_updated = utcnow() - if not self.entity_description.entry_id in self.hass.data[DOMAIN]: + if self.entity_description.entry_id not in self.hass.data[DOMAIN]: self.hass.data[DOMAIN][self.entity_description.entry_id] = [] self.hass.data[DOMAIN][self.entity_description.entry_id][self.entity_description.key] = value diff --git a/custom_components/hive_mqtt_orchestrator/select.py b/custom_components/hive_mqtt_orchestrator/select.py index ab3f1e0..7c40a80 100644 --- a/custom_components/hive_mqtt_orchestrator/select.py +++ b/custom_components/hive_mqtt_orchestrator/select.py @@ -7,17 +7,11 @@ from homeassistant.core import HomeAssistant from homeassistant.config_entries import ConfigEntry from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.entity import DeviceInfo, EntityCategory from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.components.select import SelectEntity, SelectEntityDescription from homeassistant.components.mqtt import client as mqtt_client -from homeassistant.core import callback -from homeassistant.util import slugify from homeassistant.const import ( Platform, - UnitOfInformation, - CONF_NAME, - CONF_ENTITIES, ) from .entity import HiveEntity, HiveEntityDescription @@ -30,7 +24,6 @@ DEFAULT_WATER_BOOST_MINUTES, CONF_MODEL, MODEL_SLR1, - MODEL_SLR2, ) @dataclass @@ -119,12 +112,12 @@ def process_update(self, mqtt_data) -> None: @property def options(self): - "Return the list of possible options." + """Return the list of possible options.""" return self._attr_options @property def current_option(self): - "Return the currently selected option" + """Return the currently selected option.""" return self._attr_current_option async def async_added_to_hass(self) -> None: diff --git a/custom_components/hive_mqtt_orchestrator/sensor.py b/custom_components/hive_mqtt_orchestrator/sensor.py index 6cfbb88..86516e6 100644 --- a/custom_components/hive_mqtt_orchestrator/sensor.py +++ b/custom_components/hive_mqtt_orchestrator/sensor.py @@ -7,22 +7,15 @@ from homeassistant.core import HomeAssistant from homeassistant.config_entries import ConfigEntry from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.entity import DeviceInfo, EntityCategory from homeassistant.components.sensor import SensorEntity, SensorEntityDescription -from homeassistant.core import callback -from homeassistant.util import slugify from homeassistant.const import ( Platform, - UnitOfInformation, - CONF_NAME, - CONF_ENTITIES, ) from .entity import HiveEntity, HiveEntityDescription from .const import ( DOMAIN, - LOGGER, CONF_MQTT_TOPIC, ICON_UNKNOWN, CONF_MODEL, diff --git a/custom_components/hive_mqtt_orchestrator/utils/attributes.py b/custom_components/hive_mqtt_orchestrator/utils/attributes.py index c322620..42a78b7 100644 --- a/custom_components/hive_mqtt_orchestrator/utils/attributes.py +++ b/custom_components/hive_mqtt_orchestrator/utils/attributes.py @@ -4,9 +4,10 @@ attribute_keys_to_skip = ['mpan', 'mprn'] def dict_to_typed_dict(data: dict, keys_to_ignore = []): + """Convert a dict to a typed dict.""" if data is not None: - if isinstance(data, dict) == False: + if not isinstance(data, dict): return data new_data = data.copy() @@ -31,14 +32,13 @@ def dict_to_typed_dict(data: dict, keys_to_ignore = []): continue # Check for dates - is_date = True try: data_as_datetime = datetime.fromisoformat(new_data[key].replace('Z', '+00:00')) new_data[key] = data_as_datetime continue - except: + except: # pylint: disable=E722 # Do nothing - is_date = False + continue elif isinstance(new_data[key], dict): new_data[key] = dict_to_typed_dict(new_data[key]) @@ -50,5 +50,3 @@ def dict_to_typed_dict(data: dict, keys_to_ignore = []): new_data[key] = new_array return new_data - - return None \ No newline at end of file