Skip to content

Commit

Permalink
Typing
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codechimp committed Oct 27, 2024
1 parent 7946837 commit 51c130c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions custom_components/hive_local_thermostat/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import abc
from dataclasses import dataclass
from typing import Any

from homeassistant.helpers.entity import DeviceInfo, Entity, EntityDescription

Expand All @@ -16,7 +17,7 @@ class HiveEntityDescription(EntityDescription):

entity_id: str | None = None
topic: str
entry_id: str | None = None
entry_id: str
model: str | None = None

class HiveEntity(Entity):
Expand All @@ -33,7 +34,7 @@ def __init__(
super().__init__()
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self.entity_description.entry_id)},
name=self.entity_description.name,
name=self.entity_description.name if isinstance(self.entity_description.name, str) else None,
model=self.entity_description.model,
manufacturer="Hive",
)
Expand All @@ -42,11 +43,11 @@ def __init__(
self.entity_id = description.entity_id

@abc.abstractmethod
def process_update(self, mqtt_data) -> None:
def process_update(self, mqtt_data: dict[str, Any]) -> float | 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 = None) -> float:
def get_entity_value(self, entity_key: str, default: float) -> float:
"""Get an entities value store in hass data."""
if self.entity_description.entry_id not in self.hass.data[DOMAIN]:
return default
Expand Down
4 changes: 2 additions & 2 deletions custom_components/hive_local_thermostat/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Any

from homeassistant.components.mqtt import client as mqtt_client
from homeassistant.components.select import SelectEntity, SelectEntityDescription
Expand Down Expand Up @@ -81,13 +82,12 @@ def __init__(
self._attr_has_entity_name = True
self._topic = entity_description.topic
self._attr_current_option = None
self._mqtt_data = None
if entity_description.options:
self._attr_options = entity_description.options

super().__init__(entity_description)

def process_update(self, mqtt_data) -> None:
def process_update(self, mqtt_data: dict[str, Any]) -> None:
"""Update the state of the sensor."""
self._mqtt_data = mqtt_data

Expand Down

0 comments on commit 51c130c

Please sign in to comment.