tomaae / homeassistant-mikrotik_router

Mikrotik router integration for Home Assistant
Apache License 2.0
311 stars 55 forks source link

1.6: All entities are unavailable #91

Closed kbalint closed 3 years ago

kbalint commented 3 years ago

After upgrading HACS to 1.10 and Mikrotik Router to 1.6, all previously working entities are 'unavailable'. The log is empty, the router is working as it was for the last 30+ days. Could you please guide me with any checks / logging / debugging? Thanks.

image

tomaae commented 3 years ago

You just need to enable which sensors you want in integration options. Only port switches and System sensors are enabled by default.

tjorim commented 3 years ago

Also, check the Home Assistant logs. It's possible the account you're using for this integration has not enough access rights, causing it to error and stop loading entities.

Op di 19 jan. 2021 18:05 schreef Tomaae notifications@github.com:

You just need to enable which sensors you want in integration options. Only port switches and System sensors are enabled by default.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tomaae/homeassistant-mikrotik_router/issues/91#issuecomment-762983194, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJ4EHBGIXU4JEEOHW7P7PTS2W3WVANCNFSM4WJA4KTA .

kbalint commented 3 years ago

hi, thanks for your reply. I've checked the logs, everything is working OK, the user has all required rights (used by another app too).

Where do I found any options for enabling sensors? Under settings > Integrations > Options I see this:

image

And with system options just this:

image

kbalint commented 3 years ago

OK, sorry - found it. I have never ever thought in my life that there's a second 'options' page after submitting the basic options. Is this a requirement to have it this way? :)

kbalint commented 3 years ago

OK, I've found something in the logs:

2021-01-19 20:02:14 ERROR (MainThread) [homeassistant.util.logging] Exception in update_controller when dispatching 'mikrotik_router-update-Mikrotik': ()

Traceback (most recent call last):

  File "/config/custom_components/mikrotik_router/sensor.py", line 210, in update_controller

    update_items(

  File "/config/custom_components/mikrotik_router/sensor.py", line 274, in update_items

    mikrotik_controller.data[SENSOR_TYPES[sensor][ATTR_PATH]][

KeyError: 'temperature'

All of the entities first came up, then everything went to 'unavailable'.

tomaae commented 3 years ago

Can you give me full debugs?

kbalint commented 3 years ago

Okay, I've found some things: 1) my hass group on the router did not have the 'policy' setting checked. 2) I have created DEBUG flagged logs (I can send you privately). 3) According to the logs, I've modified sensors.py to have a try: except: where it had an exception. 4) after several restarts, some things started working. I've created an 'auto-generated' lovelace page, to compare it with my hand made one. There I have all entries as duplicate, for example:

image

these entites are named switch.mikrotik_nat_tcp_22222_2 and switch.mikrotik_nat_tcp_22222 accordingly. So for some reason, the 'original' entities does not work anymore, all had been renamed to _2.

How could I reset everything to have it auto-rediscovered (and hopefully re-named to the previous name)? Thank you.

5) Further investigation shows, that previous named _rx/_tx sensors (see all in the original screenshot) are nowhere to be found, only the wifi's WLANs, ether1...5, and pppoe_out are showing up. All original sensors are 'restored', but unavailable.

For example, I have my Raspberry named RASPI. There's a device_tracker.raspi_2, but no sensor.raspi_2_wan_rx and sensor.raspi_2_wan_tx (neither the original sensor.raspi_wan_rx, sensor.raspi_wan_tx).

tomaae commented 3 years ago
  1. Ah yeah, missing policy will crash environment query and everything after wont run. Someone already had that.
  2. Adding that is not a good idea, it will cause issue elsewhere. It should be fine now since you added correct access right.
  3. Arent those from before update to 1.6? You can reset it by removing your router from integration and readding it.
  4. Something else could be crashing, check the log. Just restore everything to default, including change you did to code and do debugs again.
kbalint commented 3 years ago

Hi. On the weekend I've removed and reinstalled the component. The duplicates are gone, but the previously working sensors are missing still, only ether[1...5], pppoe and wlan[1..3] are populated. However device_tracker has all the standalone devices. I see no errors in the logfile. What can I debug further? Thanks.

tomaae commented 3 years ago

have you enabled sensors you are looking for in integration options? if so, what are you missing?

kbalint commented 3 years ago

image

Are there any more settings?

_"For example, I have my Raspberry named RASPI. There's a device_tracker.raspi_2, but no sensor.raspi_2_wan_rx and sensor.raspi_2_wan_tx (neither the original sensor.raspi_wan_rx, sensor.raspi_wantx)."

I want all my rx/tx sensors back for all my devices. In my understanding this component had these sensors. I use UPnP also, but that has different naming conventions.

kbalint commented 3 years ago

ok, restarted the stack a millionth time, and here's an error, right after populating all SCRIPTS:

2021-01-25 11:06:52 DEBUG (MainThread) [custom_components.mikrotik_router.switch] New switch Mikrotik (script mikrotik-cloud-backup) 2021-01-25 11:06:52 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform mikrotik_router File "/config/custom_components/mikrotik_router/sensor.py", line 531, in device_info 2021-01-25 11:06:52 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up mikrotik_router platform for sensor File "/config/custom_components/mikrotik_router/sensor.py", line 531, in device_info

kbalint commented 3 years ago

I've added debug here line 531:

@property
    def device_info(self) -> Dict[str, Any]:
        """Return a description for device registry."""
        info = {
            "connections": {(CONNECTION_NETWORK_MAC, self._data["mac-address"])},
            "default_name": self._data["host-name"],
        }
        _LOGGER.debug('itt')
        _LOGGER.debug(self._data)

        if self._data["manufacturer"] != "":
            info["manufacturer"] = self._data["manufacturer"]

        return info

2021-01-25 11:24:47 DEBUG (MainThread) [custom_components.mikrotik_router.sensor] itt 2021-01-25 11:24:47 DEBUG (MainThread) [custom_components.mikrotik_router.sensor] {'address': '192.168.1.xxx', 'mac-address': 'xx:yy:zz:hh:ee:ff', 'host-name': 'ubuntu', 'tx-rx-attr': 'Kbps', 'available': True, 'local_accounting': False, 'wan-tx': 0.0, 'wan-rx': 0.0}

none of the entities has a 'manufacturer' attribute. I don't know how python handles json, but i guess there should be a null check here instead of a string empty check?

edit:

by explicitly setting info["manufacturer"] = "" all missing entities returned, so this is a bug.

tomaae commented 3 years ago

ah yes, try installing master. that accounting issue is already fixed.

Pavel-Vovk commented 3 years ago

I've encountered the same issue

image Now I Can solve it ? where I need to enable old functionality?

tomaae commented 3 years ago

Did you checked everything in this issue and applied it?

Pavel-Vovk commented 3 years ago

I'll try to find these settings... but now I've restored the old version. where all sensors were available. Maybe on weekend, I'll try to configure out how I can resolve it? image Where I'll need to find this new configuration? On 1 or on 2. Sorry - I'm from Ukraine and in my home Ukrainian language more useful for my family. Do you have some scenarios (steps) of how I could resolve it? Or I need to do it by code? Or I need to reinstall it from the master branch? If the last one is correct, maybe I'll wait for a new release where this issue will be fixed (according to your last comment: "ah yes, try installing master. that accounting issue is already fixed." ).

tomaae commented 3 years ago

Its in options, same as with all integrations. Not sure how its called in your language, but most likely the second option at bottom of integration window. image

You can just install master, if you are affected by same issue. Its related only to accounting, so if you dont use accounting, it does not matter.

Pavel-Vovk commented 3 years ago

Ok. I'll try at the weekend. The manual installation process is:

  1. Download the master branch (pull)
  2. Copy/Replace files from /custom_components/mikrotik_router to HA_config
  3. Restart the HA

Do I need some other else?

tomaae commented 3 years ago

Just change version to master in HACS, no need to do anything manually.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.