skrashevich / homeassistant-mikrotik_router

Mikrotik router integration for Home Assistant. 7.13+ compatible
Apache License 2.0
3 stars 0 forks source link

[Bug] Environemnt variables not showing up #4

Open glmnet opened 1 month ago

glmnet commented 1 month ago

Describe the issue

Environment sensor not showing up

How to reproduce the issue

Expected behavior

Screenshots

Software versions

Diagnostics data

"Download diagnostics" on the ... menu give this

 { data: { tracker: { 
...
       "environment": {
        "ActiveISP": {
          "name": "ActiveISP",
          "value": "Gigared"
        },
        "hyundai49": {
          "name": "hyundai49",
          "value": "waiting"
        },
        "hyundai55": {
          "name": "hyundai55",
          "value": "waiting"
        }

Traceback/Error logs

this shows up on HA logs

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:361
integration: Sensor (documentation, issues)
First occurred: 15:34:22 (5 occurrences)
Last logged: 16:04:50

Error while setting up mikrotik_router platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 361, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/mikrotik_router/sensor.py", line 45, in async_setup_entry
    await async_add_entities(hass, config_entry, dispatcher)
  File "/config/custom_components/mikrotik_router/entity.py", line 158, in async_add_entities
    await async_update_controller(
  File "/config/custom_components/mikrotik_router/entity.py", line 154, in async_update_controller
    await async_check_exist(obj, coordinator, uid)
  File "/config/custom_components/mikrotik_router/entity.py", line 117, in async_check_exist
    unique_id = f"{obj._inst.lower()}-{obj.entity_description.key}-{slugify(str(obj._data[obj.entity_description.data_reference]).lower())}"
                                                                                ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'name'

Additional context

glmnet commented 1 week ago

I've found that this line https://github.com/skrashevich/homeassistant-mikrotik_router/blob/832baeb33c96c35908a4d502d59ed030245160de/custom_components/mikrotik_router/sensor.py#L64 is overriding _data and that is causing the environment to not load properly.