-
Notifications
You must be signed in to change notification settings - Fork 5
Feature for sms and embded nr701 #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
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
There was a problem hiding this 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.
custom_components/ha_zyxel/sensor.py
Outdated
| 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.""" |
There was a problem hiding this comment.
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
custom_components/ha_zyxel/sensor.py
Outdated
|
|
||
|
|
||
| async def async_added_to_hass(self): | ||
| """Chiamato quando viene aggiunto a Home Assistant.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
English
custom_components/ha_zyxel/sensor.py
Outdated
| """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) |
There was a problem hiding this comment.
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)
custom_components/ha_zyxel/sensor.py
Outdated
| """Return the icon.""" | ||
| return "mdi:router-wireless" | ||
| def extra_state_attributes(self): | ||
| """Aggiunge attributi extra al bottone.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
English
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.""" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Hi. i have edited it and you can merge :)