StyraHem / ShellyForHASS

Shelly smart home platform for Home Assistant
MIT License
616 stars 111 forks source link

fix exception in remove_handler #687

Closed peterus closed 1 year ago

peterus commented 2 years ago

fixing issue https://github.com/StyraHem/ShellyForHASS/issues/678

tomasbedrich commented 2 years ago

I can read the code.. But out of curiosity – can you please provide a little explanation of what led you to this solution? In other words, can you please explain why this is needed?

peterus commented 2 years ago

no problem ;)

So i was taking a look in which module the issue is coming from: https://github.com/StyraHem/ShellyForHASS/blob/9afec14d4ac0f535ad68616edcf30eab61a6e53c/custom_components/shelly/block.py#L59

Than I was taking a look into the stack trace, and took a look into the home assistant code: https://github.com/home-assistant/core/blob/c0482bdbfd5b49da904b3920af6ed17c8aafe8ec/homeassistant/helpers/entity_platform.py#L548 I have seen that just before the function call is a debug output. So I activated logging for this part as well:

logger:
  default: info
  logs:
    homeassistant.components.binary_sensor: debug
    custom_components.shelly: debug
    pyShelly: debug

and now I could see this output:

2022-06-20 20:01:57 DEBUG (MainThread) [homeassistant.components.binary_sensor] Not adding entity Technikraum-SW - MQTT connected because it's disabled

Now I know: it is a disabled binary sensor (which I disabled in HA). I was taking a look now on other examples and most of them are removing or adding something to a list. As the parameter which should be removed is not in the list, I decided to just check if the element is in the list and than remove it if it is.

Now that I just remembered, I will check the other components as well (sensor, etc.)

peterus commented 2 years ago

other sensors, switches etc. can be disabled now without an issue.