sanjoyg / dirigera_platform

HomeAssistant Integration for Dirigera Platform
MIT License
72 stars 8 forks source link

LightAttributes object has no attribute hue #3

Closed Axioms closed 4 months ago

Axioms commented 4 months ago

Hi, I'm getting the following error about LightAttributes not containing the object hue while trying to setup my TRADFRI light bulbs.

Logger: homeassistant.components.light
Source: helpers/entity_platform.py:533
Integration: Light (documentation, issues)
First occurred: 10:55:03 PM (1 occurrences)
Last logged: 10:55:03 PM

Error adding entities for domain light with platform dirigera_platform
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/entity_platform.py", line 533, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/entity_platform.py", line 782, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/entity.py", line 1325, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/entity.py", line 989, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/entity.py", line 1110, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/entity.py", line 1049, in __async_calculate_state
    attr.update(self.state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/components/light/__init__.py", line 1121, in state_attributes
    color_mode = self._light_internal_color_mode if _is_on else None
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/components/light/__init__.py", line 903, in _light_internal_color_mode
    if ColorMode.HS in supported and self.hs_color is not None:
                                     ^^^^^^^^^^^^^
  File "/config/custom_components/dirigera_platform/light.py", line 117, in hs_color
    return (self._json_data.attributes.hue, self._json_data.attributes.saturation)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'LightAttributes' object has no attribute 'hue'
sanjoyg commented 4 months ago

Looks like the IKEA bulb doesnt support hue/saturation. Would be able to do the following steps and paste the JSON output

# Go to Developer -> Service and invoke dirigera_platform.dump_data without any parameters
#Look at the HASS log which would have the JSON.
Axioms commented 4 months ago

Here is the json dump

2024-02-23 10:09:44.192 INFO (SyncWorker_8) [custom_components.dirigera_platform] === START Devices JSON ===
2024-02-23 10:09:44.192 INFO (SyncWorker_8) [custom_components.dirigera_platform] --------------
2024-02-23 10:09:44.443 INFO (SyncWorker_8) [custom_components.dirigera_platform] [{'id': '1ae30251-8c7f-478e-bde0-cae79938104a_1', 'type': 'light', 'deviceType': 'light', 'createdAt': '2024-02-03T15:17:58.000Z', 'isReachable': True, 'lastSeen': '2024-02-23T14:49:15.000Z', 'attributes': {'customName': '', 'model': 'TRADFRI bulb E26 CWS 800lm', 'manufacturer': 'IKEA of Sweden', 'firmwareVersion': '1.0.021', 'hardwareVersion': '1', 'serialNumber': 'A46DD4FFFE678726', 'productCode': 'LED1924G9NA', 'isOn': True, 'startupOnOff': 'startOn', 'lightLevel': 40, 'colorHue': 29.99584508731573, 'colorSaturation': 0.47515790646310396, 'colorTemperature': 2702, 'colorTemperatureMin': 4000, 'colorTemperatureMax': 2202, 'startupTemperature': -1, 'colorMode': 'color', 'identifyStarted': '2000-01-01T00:00:00.000Z', 'identifyPeriod': 0, 'permittingJoin': False, 'otaStatus': 'upToDate', 'otaState': 'readyToCheck', 'otaProgress': 0, 'otaPolicy': 'autoUpdate', 'otaScheduleStart': '00:00', 'otaScheduleEnd': '00:00'}, 'capabilities': {'canSend': [], 'canReceive': ['customName', 'isOn', 'lightLevel', 'colorTemperature', 'colorHue', 'colorSaturation']}, 'room': {'id': 'c6e5987e-7005-4dfb-822c-0349a3e7b79f', 'name': 'Bedroom', 'color': 'ikea_yellow_no_24', 'icon': 'rooms_bed'}, 'deviceSet': [], 'remoteLinks': [], 'isHidden': False}, {'id': '2efd9ef7-1590-47d7-ba26-3305601b5134_1', 'relationId': '2efd9ef7-1590-47d7-ba26-3305601b5134', 'type': 'gateway', 'deviceType': 'gateway', 'createdAt': '2023-12-14T15:10:41.613Z', 'isReachable': True, 'lastSeen': '2024-02-23T15:09:00.786Z', 'attributes': {'customName': 'axiom', 'model': 'DIRIGERA Hub for smart products', 'manufacturer': 'IKEA of Sweden', 'firmwareVersion': '2.505.2', 'hardwareVersion': 'P2.5', 'serialNumber': '2efd9ef7-1590-47d7-ba26-3305601b5134', 'identifyStarted': '2024-02-23T03:27:28.000Z', 'identifyPeriod': 4, 'otaStatus': 'upToDate', 'otaState': 'readyToCheck', 'otaProgress': 100, 'otaPolicy': 'autoDownload', 'otaScheduleStart': '00:00', 'otaScheduleEnd': '00:00', 'permittingJoin': False, 'backendConnected': True, 'backendConnectionPersistent': True, 'backendOnboardingComplete': True, 'backendRegion': 'us-east-1', 'backendCountryCode': 'US', 'userConsents': [{'name': 'analytics', 'value': 'disabled'}, {'name': 'diagnostics', 'value': 'enabled'}], 'logLevel': 3, 'coredump': False, 'timezone': 'America/New_York', 'nextSunSet': None, 'nextSunRise': None, 'homestateValue': 'home', 'homestateLastChanged': '2023-12-14T10:10:41-05:00', 'countryCode': 'XZ', 'isOn': False}, 'capabilities': {'canSend': [], 'canReceive': ['customName', 'permittingJoin', 'userConsents', 'logLevel', 'time', 'timezone', 'countryCode', 'coordinates']}, 'deviceSet': [], 'remoteLinks': []}, {'id': '9b8ebc55-c4e8-4fbd-9789-2f826926ebbc_1', 'type': 'light', 'deviceType': 'light', 'createdAt': '2024-02-03T15:18:02.000Z', 'isReachable': True, 'lastSeen': '2024-02-23T14:49:11.000Z', 'attributes': {'customName': '', 'model': 'TRADFRI bulb E26 CWS 800lm', 'manufacturer': 'IKEA of Sweden', 'firmwareVersion': '1.0.021', 'hardwareVersion': '1', 'serialNumber': '3410F4FFFEFCD16F', 'productCode': 'LED1924G9NA', 'isOn': True, 'startupOnOff': 'startOn', 'lightLevel': 40, 'colorHue': 29.99584508731573, 'colorSaturation': 0.47515790646310396, 'colorTemperature': 2702, 'colorTemperatureMin': 4000, 'colorTemperatureMax': 2202, 'startupTemperature': -1, 'colorMode': 'color', 'identifyStarted': '2000-01-01T00:00:00.000Z', 'identifyPeriod': 0, 'permittingJoin': False, 'otaStatus': 'upToDate', 'otaState': 'readyToCheck', 'otaProgress': 0, 'otaPolicy': 'autoUpdate', 'otaScheduleStart': '00:00', 'otaScheduleEnd': '00:00'}, 'capabilities': {'canSend': [], 'canReceive': ['customName', 'isOn', 'lightLevel', 'colorTemperature', 'colorHue', 'colorSaturation']}, 'room': {'id': 'c6e5987e-7005-4dfb-822c-0349a3e7b79f', 'name': 'Bedroom', 'color': 'ikea_yellow_no_24', 'icon': 'rooms_bed'}, 'deviceSet': [], 'remoteLinks': [], 'isHidden': False}, {'id': 'd9f5315a-5eb8-45d4-a9f0-cea612a82e1a_1', 'type': 'light', 'deviceType': 'light', 'createdAt': '2024-02-03T15:17:57.000Z', 'isReachable': True, 'lastSeen': '2024-02-23T14:46:46.000Z', 'attributes': {'customName': '', 'model': 'TRADFRI bulb E26 CWS 800lm', 'manufacturer': 'IKEA of Sweden', 'firmwareVersion': '1.0.021', 'hardwareVersion': '1', 'serialNumber': '3410F4FFFEFD272C', 'productCode': 'LED1924G9NA', 'isOn': True, 'startupOnOff': 'startOn', 'lightLevel': 40, 'colorHue': 29.99584508731573, 'colorSaturation': 0.47515790646310396, 'colorTemperature': 2702, 'colorTemperatureMin': 4000, 'colorTemperatureMax': 2202, 'startupTemperature': -1, 'colorMode': 'color', 'identifyStarted': '2000-01-01T00:00:00.000Z', 'identifyPeriod': 0, 'permittingJoin': False, 'otaStatus': 'upToDate', 'otaState': 'readyToCheck', 'otaProgress': 0, 'otaPolicy': 'autoUpdate', 'otaScheduleStart': '00:00', 'otaScheduleEnd': '00:00'}, 'capabilities': {'canSend': [], 'canReceive': ['customName', 'isOn', 'lightLevel', 'colorTemperature', 'colorHue', 'colorSaturation']}, 'room': {'id': 'c6e5987e-7005-4dfb-822c-0349a3e7b79f', 'name': 'Bedroom', 'color': 'ikea_yellow_no_24', 'icon': 'rooms_bed'}, 'deviceSet': [], 'remoteLinks': [], 'isHidden': False}, {'id': '12c751ff-7eef-4e7e-a40a-d03bbd112f8b_1', 'type': 'speaker', 'deviceType': 'speaker', 'createdAt': '2024-02-21T15:16:13.697Z', 'isReachable': True, 'lastSeen': '2024-02-23T00:18:30.948Z', 'attributes': {'customName': 'Bedroom', 'model': 'SYMFONISK Bookshelf S33 ColorBlack', 'manufacturer': 'Sonos, Inc.', 'firmwareVersion': '77.4-49290', 'hardwareVersion': '1.34.3.9-1.2', 'serialNumber': '38-42-0B-99-17-80:9', 'productCode': 'S33Black', 'identifyStarted': '2024-02-21T15:16:13.697Z', 'identifyPeriod': 0, 'playback': 'playbackPaused', 'playbackLastChangedTimestamp': '2024-02-23T00:18:30.947Z', 'playbackAudio': {'serviceType': 'sonos', 'providerType': 'Spotify', 'playItem': {'id': 'eyJhY2NvdW50VHlwZSI6InNvbm9zIiwiY29udGVudFR5cGUiOiJjb250YWluZXIiLCJjb250ZW50Ijp7ImNvbnRhaW5lciI6eyJhY2NvdW50SWQiOiJzbl8yIiwib2JqZWN0SWQiOiJzcG90aWZ5OnRyYWNrOjN6OU9uc252TTZTRk4yZHpyU0RkVk8iLCJzZXJ2aWNlSWQiOiIxMiIsInR5cGUiOiJ0cmFjayJ9fX0=', 'title': 'Love Like You (feat. Rebecca Sugar) - End Credits', 'artist': 'Steven Universe', 'album': 'Steven Universe, Vol. 1 (Original Soundtrack)', 'imageURL': 'https://i.scdn.co/image/ab67616d0000b273e18ff29a2fe8e9c0df309fa6', 'duration': 144000}, 'nextPlayItem': {'title': 'Medicine', 'artist': 'Robinson', 'album': 'Medicine'}}, 'playbackPosition': {'position': 46000, 'timestamp': '2024-02-23T00:18:30.946Z'}, 'playbackAvailableActions': {'crossfade': False, 'pause': False, 'repeat': ['off', 'playItem', 'playlist'], 'seek': True, 'shuffle': True, 'playbackNext': True, 'playbackPrev': True}, 'playbackModes': {'crossfade': False, 'repeat': 'off', 'shuffle': True}, 'volume': 26, 'isMuted': False, 'audioGroup': '3abca259-448f-42a6-8519-cb684d39eeb1'}, 'capabilities': {'canSend': [], 'canReceive': ['playback', 'playbackAudio', 'volume', 'isMuted']}, 'deviceSet': [], 'remoteLinks': [], 'isHidden': True}]
2024-02-23 10:09:44.443 INFO (SyncWorker_8) [custom_components.dirigera_platform] --------------
2024-02-23 10:09:44.443 INFO (SyncWorker_8) [custom_components.dirigera_platform] === END Devices JSON ===
sanjoyg commented 4 months ago

Great, looks like this bulb returns colorHue, colorSaturation in the JSON instead of just hue & saturation. Will write up a fix later today and post it for you to try it out.

sanjoyg commented 4 months ago

Fix in the new release do check and let me know

Axioms commented 4 months ago

Everything seems to be working, thank you!

Light brightness and temp work but rgb color is not. will send error in a minute

Axioms commented 4 months ago

here is the python stack trace

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:240
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 1:39:00 PM (12 occurrences)
Last logged: 1:40:51 PM

[139782950284224] (TypeError('Light.set_color_temperature() takes 2 positional arguments but 3 were given'), 'dirigera_platform', 'hub_exception')
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/homeassistant/components/websocket_api/commands.py", line 240, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/core.py", line 2279, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/core.py", line 2316, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 892, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 962, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/components/light/__init__.py", line 628, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/usr/local/lib/python3.12/site-packages/homeassistant/components/group/light.py", line 174, in async_turn_on
    await self.hass.services.async_call(
  File "/usr/local/lib/python3.12/site-packages/homeassistant/core.py", line 2279, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/core.py", line 2316, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 917, in entity_service_call
    raise result from None
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/entity.py", line 1540, in async_request_call
    return await coro
           ^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 962, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/components/light/__init__.py", line 628, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/entity.py", line 1615, in async_turn_on
    await self.hass.async_add_executor_job(ft.partial(self.turn_on, **kwargs))
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dirigera_platform/light.py", line 169, in turn_on
    raise HomeAssistantError(ex,DOMAIN,"hub_exception")
homeassistant.exceptions.HomeAssistantError: (TypeError('Light.set_color_temperature() takes 2 positional arguments but 3 were given'), 'dirigera_platform', 'hub_exception')
sanjoyg commented 4 months ago

would you enable debug on the integration and send the log as well

Axioms commented 4 months ago

home-assistant_2024-02-23T18-54-17.816Z.log

sanjoyg commented 4 months ago

Silly mistake, dont have a RGB bulb caused the issue. Try release 1.2.3 should work now.

Axioms commented 4 months ago

im getting saturation value error now

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:240
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 2:12:01 PM (11 occurrences)
Last logged: 2:14:33 PM

[139827725635520] (ValueError('saturation must be a value between 0.0 and 1.0'), 'dirigera_platform', 'hub_exception')
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/homeassistant/components/websocket_api/commands.py", line 240, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/core.py", line 2279, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/core.py", line 2316, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 892, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 962, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/components/light/__init__.py", line 628, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/usr/local/lib/python3.12/site-packages/homeassistant/components/group/light.py", line 174, in async_turn_on
    await self.hass.services.async_call(
  File "/usr/local/lib/python3.12/site-packages/homeassistant/core.py", line 2279, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/core.py", line 2316, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 917, in entity_service_call
    raise result from None
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/entity.py", line 1540, in async_request_call
    return await coro
           ^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 962, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/components/light/__init__.py", line 628, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/entity.py", line 1615, in async_turn_on
    await self.hass.async_add_executor_job(ft.partial(self.turn_on, **kwargs))
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dirigera_platform/light.py", line 169, in turn_on
    raise HomeAssistantError(ex,DOMAIN,"hub_exception")
homeassistant.exceptions.HomeAssistantError: (ValueError('saturation must be a value between 0.0 and 1.0'), 'dirigera_platform', 'hub_exception')

home-assistant_2024-02-23T19-19-08.352Z.log

sanjoyg commented 4 months ago

So IKEA Color Bulbs take saturation value between 0-1 while HASS has the range of 0-100. Mapped it and pushed a new release 1.2.5. Hopefully works now

sanjoyg commented 4 months ago

My bad try release 1.2.6

sanjoyg commented 4 months ago

My bad try release 1.2.6

I meant to write 1.2.7

Axioms commented 4 months ago

yep, RGB works now! one last thing. Im not sure if this is how home assistant works or if this is a bug. but then I open the light controls the brightness is always set to 0 in the gui instead of being at what the lights are at. if this is intended behavior then im good with closing then issue. Screenshot_20240223_145213

sanjoyg commented 4 months ago

Great catch, the brightness was not been returned. Fixed it with 1.2.8 release

Axioms commented 4 months ago

Everything seems to be working, thank you!