core: When a light group contains some bulbs that support colour and some that don't it calls services with parameters they don't support

The problem

Exception when calling light service (on/toggle) to a group of lights that contain lights that only support brightness (no color) and lights that support color.

light.kitchen_lights: RGB Light Strip White Bulb

calling light.toggle or light.turn_on with the following payload results in the below error:

service: light.turn_on
data:
  brightness_pct: 100
  kelvin: 3500
  entity_id:
    - light.kitchen_lights

What is version of Home Assistant Core has the issue?

core-2021.4.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

group

Link to integration documentation on our website

https://www.home-assistant.io/integrations/group/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2021-05-18 22:13:43 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140374063830784] Error handling message: Unknown error
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 18, in _handle_async_response
await func(hass, connection, msg)
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 439, in handle_execute_script
await script_obj.async_run(context=context)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1195, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 341, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 359, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 559, in _async_call_service_step
await service_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1515, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 206, in handle_service
await self.hass.helpers.service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 649, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 692, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 686, in _handle_entity_call
await result
File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 330, in async_handle_toggle_service
await async_handle_light_on_service(light, call)
File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 322, in async_handle_light_on_service
await light.async_turn_on(**params)
File "/usr/src/homeassistant/homeassistant/components/group/light.py", line 239, in async_turn_on
await self.hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1515, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 206, in handle_service
await self.hass.helpers.service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 649, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 692, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 686, in _handle_entity_call
await result
File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 322, in async_handle_light_on_service
await light.async_turn_on(**params)
File "/usr/src/homeassistant/homeassistant/components/homekit_controller/light.py", line 116, in async_turn_on
await self.async_put_characteristics(characteristics)
File "/usr/src/homeassistant/homeassistant/components/homekit_controller/__init__.py", line 97, in async_put_characteristics
payload = self.service.build_update(characteristics)
File "/usr/local/lib/python3.8/site-packages/aiohomekit/model/services/service.py", line 137, in build_update
char = self[char_type]
File "/usr/local/lib/python3.8/site-packages/aiohomekit/model/services/service.py", line 118, in __getitem__
return self.characteristics_by_type[key]
KeyError: '000000CE-0000-1000-8000-0026BB765291'

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (12 by maintainers)

Most upvoted comments

I can’t see what features your bulbs are exposing, so I can’t tell if homekit_controller has got them wrong 😄 You can check at /developer-tools/state though. Also, if the UI is wrong for those bulbs (outside of a group) that would be an indication their supported features are not getting enumerated properly. I see the UI I expect for my bulbs (some just have brightness, some have colour, etc).

I have hue bulbs and this is what I see in the dev tools part of HA:

Screenshot 2021-05-20 at 17 17 22

Screenshot 2021-05-20 at 17 18 16

Screenshot 2021-05-20 at 17 18 28

Which looks correct to me.

Regardless of whether that data is correct, I can’t see any code in light group that tries to be smart about which bulbs to foward which parameters to.

Here you can see it just combines ALL supported features:

https://github.com/home-assistant/core/blob/dev/homeassistant/components/group/light.py#L402

And you can also see colour is sent regardless here:

https://github.com/home-assistant/core/blob/dev/homeassistant/components/group/light.py#L239

There is an attempt to compnesate for different colour modes here:

https://github.com/home-assistant/core/blob/dev/homeassistant/components/group/light.py#L260

But I think it should not be sending any colours at all if no colour modes are supported by a group member, and I don’t think thats what the code I linked to is trying to do.

As for Hue, well it doesn’t attempt to deal with it either - see here:

https://github.com/home-assistant/core/blob/dev/homeassistant/components/hue/light.py#L464

HS and color temp just get passed straight through to the upstream API. I can only imagine the underlying Hue bridge just silently ignores commands it doesn’t understand, where as the HomeKit API is fiddly and strict enough that I can’t even generate an invalid request, much less send it and have it ignored.