Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codechimp committed Apr 9, 2024
1 parent 06d530a commit 7b71d07
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 40 deletions.
3 changes: 0 additions & 3 deletions custom_components/hive_mqtt_orchestrator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 2 additions & 5 deletions custom_components/hive_mqtt_orchestrator/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,6 +26,8 @@
Platform
)

from .entity import HiveEntity, HiveEntityDescription

from .const import (
DOMAIN,
LOGGER,
Expand All @@ -44,10 +45,6 @@
PRESET_BOOST: HIVE_BOOST,
}

from .entity import HiveEntity, HiveEntityDescription

from datetime import timedelta

@dataclass
class HiveClimateEntityDescription(
HiveEntityDescription,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hive_mqtt_orchestrator/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hive_mqtt_orchestrator/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@

WATER_MODES: Final = ["auto", "heat", "off", "emergency_heat"]

ICON_UNKNOWN = "mdi:help"
ICON_UNKNOWN = "mdi:help"
4 changes: 3 additions & 1 deletion custom_components/hive_mqtt_orchestrator/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
9 changes: 2 additions & 7 deletions custom_components/hive_mqtt_orchestrator/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

from typing import Any, cast
from dataclasses import dataclass

from homeassistant.core import HomeAssistant
Expand All @@ -11,7 +10,6 @@
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
from homeassistant.components.number import (
NumberEntityDescription,
NumberExtraStoredData,
NumberMode,
RestoreNumber,
NumberDeviceClass,
Expand All @@ -21,9 +19,6 @@
from homeassistant.util.dt import utcnow
from homeassistant.const import (
Platform,
UnitOfInformation,
CONF_NAME,
CONF_ENTITIES,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 2 additions & 9 deletions custom_components/hive_mqtt_orchestrator/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,7 +24,6 @@
DEFAULT_WATER_BOOST_MINUTES,
CONF_MODEL,
MODEL_SLR1,
MODEL_SLR2,
)

@dataclass
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 0 additions & 7 deletions custom_components/hive_mqtt_orchestrator/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions custom_components/hive_mqtt_orchestrator/utils/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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])
Expand All @@ -50,5 +50,3 @@ def dict_to_typed_dict(data: dict, keys_to_ignore = []):
new_data[key] = new_array

return new_data

return None

0 comments on commit 7b71d07

Please sign in to comment.