Skip to content

Conversation

@davideciarmiello
Copy link

Hi. i have edited it and you can merge :)

@zulufoxtrot
Copy link
Owner

Good job! I'll review it as soon as possible.

using entry.runtime_data for save coordinator
add all entities as disabled for default
added restart time sensor
Copy link
Owner

@zulufoxtrot zulufoxtrot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ciao! I left a few comments. Overall very nice work.

name_parts = self._key.split(".")
return f"Zyxel {'.'.join(name_parts)}"
class LastRestartSensor(RestoreEntity, ZyxelBaseEntity, SensorEntity):
"""Sensore che mostra la data/ora dell'ultimo riavvio."""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be English



async def async_added_to_hass(self):
"""Chiamato quando viene aggiunto a Home Assistant."""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English

"""Chiamato quando viene aggiunto a Home Assistant."""
await super().async_added_to_hass()
if (last_state := await self.async_get_last_state()) is not None:
# Recupera stato (data)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English (more inline comments in Italian below)

"""Return the icon."""
return "mdi:router-wireless"
def extra_state_attributes(self):
"""Aggiunge attributi extra al bottone."""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the license is no issue (must check) we might as well rename the library with a more generic name (like: RouterAPI or something) and move it to project root. What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think that is a good idea, changing a name . now i have converted it in async version

async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! What is the use case for this / how can I use it in HA?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in device management, when you click on your configured zyxel, allow to download diagnostic, is a json with all informations :)


def __init__(self, coordinator):
super().__init__(coordinator, "device.DeviceInfo.UpTime", None)
self._attr_name = "Last Restart"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this can be localized? Unsure if it's a good idea. Otherwise English is fine

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes can be localized... but for now all sensors are in english

# Process all keys in the JSON and create sensors for them
# We'll use a flat structure for simplicity
for key, value in _flatten_dict(coordinator.data).items():
for key, value in coordinator.data.items():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in coordinator, save directly the flatten dict, then all type of sensor can use directly, without recall _flatten_dict, and accessing at value directly with a single key and not with a key to split with dot.

sensor_config
)
)
sensor_config = KNOWN_SENSORS.get(key, KNOWN_SENSORS.get(key.split(".")[-1], None))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one? Does it cause any changes in output? I'm a little scared of breaking entities since they depend on this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't break it. If an entity is defined with the full path, it uses that; otherwise, it only searches for the final part of the name, as it did before.

# Create a configured sensor for known types
sensors.append(ZyxelSensorEntity(coordinator, key, sensor_config))

class AbstractZyxelSensor(CoordinatorEntity, SensorEntity):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what is going on here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creates the sensor with the sensor_config settings, if it does not exist in the list of known ones, creates it as disabled by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants