Skip to content

Commit

Permalink
fix type error of 2024.01 by inverting application logic (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
LavermanJJ authored Jan 10, 2024
1 parent 89e3c8b commit e2c61c5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
check: check-pylint check-ruff

check-pylint:
@poetry run pylint custom_components/*
@poetry run pylint custom_components/* --fix

check-ruff:
@poetry run ruff check custom_components/*
Expand Down
4 changes: 2 additions & 2 deletions custom_components/solarfocus/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ def is_on(self):
key="door_contact",
device_class=BinarySensorDeviceClass.DOOR,
on_state="1",
supported_systems=[Systems.THERMINATOR],
unsupported_systems=[Systems.ECOTOP, Systems.VAMPAIR],
),
SolarfocusBinarySensorEntityDescription(
key="door_contact",
device_class=BinarySensorDeviceClass.DOOR,
on_state="0",
supported_systems=[Systems.ECOTOP],
unsupported_systems=[Systems.THERMINATOR, Systems.VAMPAIR],
),
]
3 changes: 2 additions & 1 deletion custom_components/solarfocus/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def __init__(self, hass, entry, api: SolarfocusAPI) -> None:
"""Init the Solarfocus data object."""

self.api = api
self.api.connect()
if not self.api.connect():
_LOGGER.error("Failed to connect to modbus")

self.name = entry.title
self._entry = entry
Expand Down
28 changes: 14 additions & 14 deletions custom_components/solarfocus/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import copy
from dataclasses import dataclass, field
from dataclasses import dataclass
import logging

from packaging import version
Expand All @@ -18,18 +18,16 @@
_LOGGER = logging.getLogger(__name__)


@dataclass
@dataclass(kw_only=True)
class SolarfocusEntityDescription(EntityDescription):
"""Description of a Solarfocus entity."""

item: str = None
component: str = None
component_prefix: str = None
component_idx: str = None
item: str | None = None
component: str | None = None
component_prefix: str | None = None
component_idx: str | None = None
min_required_version: str = "21.140"
supported_systems: list = field(
default_factory=lambda: [Systems.VAMPAIR, Systems.THERMINATOR, Systems.ECOTOP]
)
unsupported_systems: list[Systems] | None = None


def create_description(
Expand Down Expand Up @@ -82,18 +80,20 @@ def filterVersionAndSystem(config_entry: ConfigEntry, entities):
"""Filter entities not compatible to version or system."""
api_version = version.parse(config_entry.options[CONF_API_VERSION])

version_filtered_entities = filter(
filtered_entities = filter(
lambda entity: version.parse(entity.entity_description.min_required_version)
<= api_version,
entities,
)

current_system = config_entry.data[CONF_SOLARFOCUS_SYSTEM]

filtered_entities = filter(
lambda entity: current_system in entity.entity_description.supported_systems,
version_filtered_entities,
)
for entity in filtered_entities:
unsupported_systems = entity.entity_description.unsupported_systems
if unsupported_systems is None:
yield entity
elif current_system not in unsupported_systems:
yield entity

return filtered_entities

Expand Down
10 changes: 5 additions & 5 deletions custom_components/solarfocus/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def native_value(self):
icon="mdi:thermometer-high",
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
supported_systems=[Systems.THERMINATOR, Systems.ECOTOP],
unsupported_systems=[Systems.VAMPAIR],
),
SolarfocusSensorEntityDescription(
key="external_top_temperature_x44",
Expand Down Expand Up @@ -573,30 +573,30 @@ def native_value(self):
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.ENUM,
options=list(range(0, 6)),
supported_systems=[Systems.THERMINATOR],
unsupported_systems=[Systems.VAMPAIR, Systems.ECOTOP],
),
SolarfocusSensorEntityDescription(
key="octoplus_buffer_temperature_bottom",
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
icon="mdi:thermometer-low",
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
supported_systems=[Systems.THERMINATOR],
unsupported_systems=[Systems.VAMPAIR, Systems.ECOTOP],
),
SolarfocusSensorEntityDescription(
key="octoplus_buffer_temperature_top",
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
icon="mdi:thermometer",
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
supported_systems=[Systems.THERMINATOR],
unsupported_systems=[Systems.VAMPAIR, Systems.ECOTOP],
),
SolarfocusSensorEntityDescription(
key="log_wood",
icon="mdi:format-list-bulleted",
device_class=SensorDeviceClass.ENUM,
options=list(range(0, 2)),
supported_systems=[Systems.THERMINATOR],
unsupported_systems=[Systems.VAMPAIR, Systems.ECOTOP],
),
SolarfocusSensorEntityDescription(
key="pellet_usage_last_fill",
Expand Down

0 comments on commit e2c61c5

Please sign in to comment.