Skip to content

Commit

Permalink
feat: enhance number entity addition by checking ecoMAX360i controlle…
Browse files Browse the repository at this point in the history
…r compatibility
  • Loading branch information
jontofront committed Dec 17, 2024
1 parent 6fb64cb commit fbce942
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions custom_components/econet300/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,25 @@ async def async_set_native_value(self, value: float) -> None:
self.async_write_ha_state()


def can_add(key: str, coordinator: EconetDataCoordinator):
def can_add_number_entity(key: str, coordinator: EconetDataCoordinator):
"""Check if a given entity can be added based on the availability of data in the coordinator."""
try:
# Check for unsupported controllers
controller_id = coordinator.data.get("sysParams", {}).get("controllerID", "")
if controller_id == "ecoMAX360i":
_LOGGER.info(
"Skipping key '%s' because controller '%s' does not support paramsEdits",
key,
controller_id,
)
return False
# Check for paramsEdits availability for othr controllers
return (
coordinator.has_param_edit_data(key)
and coordinator.data["paramsEdits"][key]
)
except KeyError as e:
_LOGGER.error("KeyError in can_add: %s", e)
_LOGGER.error("KeyError in can_add_number_entity: %s", e)
return False


Expand Down Expand Up @@ -171,6 +181,15 @@ async def async_setup_entry(
coordinator = hass.data[DOMAIN][entry.entry_id][SERVICE_COORDINATOR]
api = hass.data[DOMAIN][entry.entry_id][SERVICE_API]

# Check the controller type before proceeding
controller_id = coordinator.data.get("sysParams", {}).get("controllerID", "")
if controller_id == "ecoMAX360i":
_LOGGER.info(
"Controller '%s' detected - skipping setup of number entities.",
controller_id,
)
return

entities: list[EconetNumber] = []

for key in NUMBER_MAP:
Expand All @@ -182,7 +201,7 @@ async def async_setup_entry(
)
continue

if can_add(key, coordinator):
if can_add_number_entity(key, coordinator):
entity_description = create_number_entity_description(key)
apply_limits(entity_description, number_limits)
entities.append(EconetNumber(entity_description, coordinator, api))
Expand Down

0 comments on commit fbce942

Please sign in to comment.