jomwells / ambilights

Custom Home Assistant (Light) Component for Ambilight LED's on Philips Android TV's
48 stars 20 forks source link

TypeError: 'NoneType' object is not subscriptable #13

Closed aegjoyce closed 3 years ago

aegjoyce commented 4 years ago

Minor issue with the Ambilight component - if the Ambilight is already off and a light.turn_off service is passed to it, the following error occurs:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 125, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1281, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1316, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 208, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 454, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 595, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 485, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 630, in async_turn_off
    await self.hass.async_add_executor_job(ft.partial(self.turn_off, **kwargs))
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/philips_ambilight/light.py", line 182, in turn_off
    OLD_STATE = [self._hs[0], self._hs[1], self._brightness, self._effect]
TypeError: 'NoneType' object is not subscriptable

This appears to be an issue with the Ambilight component and the way it handles light service calls - for any other light, if it is already switched off and a light.turn_off service is called, no error occurs.

This is running on HA 113.2 on an rPi 4 using HassOS.

Unfortunately this breaks a few automations for me - I have an automatically-generated group.all_lights which won't accept a homeassistant.turn_off command because of the ambilight error.

Otherwise an excellent component that works perfectly with the Wakelock app on my 55OLED804. Many thanks!

jomwells commented 3 years ago

Sorry for the late response, I have been a long way from all my smart home gear since the start of lockdown! It seems like this would be a pretty easy fix; just checking the state in the Python command for turning the light on. If you are confident with Python I would happily accept a working pull request, otherwise I can have a go reasonably soon, though I would need to send the code to you for testing before pushing out the update, as I have no way of testing it myself at the moment

aegjoyce commented 3 years ago

Hmm... weirdly enough, testing it today on 0.114.3, I can't seem to replicate the error - looks like there has been a backend fix for it! I'll close this for now and reopen if it starts happening again.