Radioh / ha_twitch_helix

Home Assistant custom component to integrate with Twitch helix api.
MIT License
21 stars 2 forks source link

twitch_helix sensor didn't update to "streaming" #19

Closed NicciZar closed 2 years ago

NicciZar commented 2 years ago
Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:719
Integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 02:39:40 (478 occurrences)
Last logged: 18:33:40

Updating twitch_helix sensor took longer than the scheduled update interval 0:02:00

Some sensors seem to be not really accurate at the moment on my server.. My colleague streamed today and it was not picked up by the sensor (1h stream)

I also get these

Logger: homeassistant.helpers.entity
Source: helpers/entity.py:747
First occurred: 02:37:50 (3 occurrences)
Last logged: 02:42:41

Update of sensor.derkatzenkiller is taking over 10 seconds
Update of sensor.dashducks is taking over 10 seconds
Update of sensor.cryptzar is taking over 10 seconds

as one example of the sensor (no stream)

image

example with stream running

image (dashducks streams 24/7 so it shouldn't show any "not streaming" part)

config.yaml

  - platform: twitch_helix
    client_id: XXXX
    client_secret: XXXX
    own_channel: "CryptZar"
    channels:
      - "DerKatzenKiller" # DerKatzenKiller - 107123013
      - "DashDucks" # DashDucks - 277624494
      - "CryptZar" # CryptZar - 124131318
      - "t0biehh" # t0biehh - 123327884
      - "Firehero_TTV" # Firehero_TTV - 546917774
Radioh commented 2 years ago

Hi. I'm not sure why this would happen on your box. It really shouldn't take very long to do a few API calls for a sensor, so a guess would be that the API is timing out. You could try to add some extra logging to the sensor.py script by using _LOGGER.error()

You could also just try to straight up restart your Home Assistant box and see if that gets it rolling again.

NicciZar commented 2 years ago

Okay I've restarted my box and I'm now waiting for my logs to tell me stuff.

It may just need some time. Also no one started streaming yet (to see the change in the entity)

I got the error below but I think it was just the general startup of the box that lead to this

Logger: homeassistant.components.sensor
Source: /usr/local/lib/python3.9/asyncio/events.py:80
Integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 07:04:14 (1 occurrences)
Last logged: 07:04:14

Setup of sensor platform twitch_helix is taking over 10 seconds.
NicciZar commented 2 years ago

The issue above seems to be resolved.


I got an error when enabling the opt out list though..

This is my current working config

  - platform: twitch_helix
    client_id: XXXX
    client_secret: XXXX
    own_channel: "CryptZar"
    channels:
      - "DerKatzenKiller" # DerKatzenKiller - 107123013
      - "DashDucks" # DashDucks - 277624494
      - "CryptZar" # CryptZar - 124131318
      - "t0biehh" # t0biehh - 123327884
      - "Firehero_TTV" # Firehero_TTV - 546917774

Which seems to be working fine. image

Now I wanted to opt out off of some api calls via

    api_opt_outs:
      - subscription_user
      - follow_user

But this breaks the config.. The config seems to be valid and after restarting the logs show the following

Logger: homeassistant.components.sensor
Source: custom_components/twitch_helix/sensor.py:218
Integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 22:16:52 (5 occurrences)
Last logged: 22:16:58

twitch_helix: Error on device update!
Traceback (most recent call last):
  File "/config/custom_components/twitch_helix/sensor.py", line 216, in update
    self._follow[ATTR_FOLLOWERS_COUNT] = total_follows["total"]
TypeError: 'NoneType' object does not support item assignment

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 737, in async_device_update
    await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/twitch_helix/sensor.py", line 218, in update
    self._follow[ATTR_FOLLOWERS_COUNT] = None
TypeError: 'NoneType' object does not support item assignment

image

Removing the 3 lines of code restores it back

I also tried removing the

- follow_user

This worked and I can now see the streams again.


So the - follow_user seems to be broken somehow

Radioh commented 2 years ago

Thank you @NicciZar for investigating the issue. I could reproduce the error. It happens because an object hasn't been initialized properly when the follow_user is opted out, which would make the follow_total fail, because it was relying on follow_user to initialize an object.

That issue should now be fixed in the latest release: https://github.com/Radioh/ha_twitch_helix/releases/tag/v.0.5.4

NicciZar commented 2 years ago

Hi Radioh the issue is now fixed.

Thanks for the quick update :)