d03n3rfr1tz3 / hass-divoom

Divoom Integration for Home Assistant
MIT License
111 stars 9 forks source link

Setting Volume Throws an Error (AttributeError: 'float' object has no attribute 'to_bytes') #31

Closed Write closed 7 months ago

Write commented 7 months ago

Command such as :

service: notify.divoom_ditoo_plus_light
data:
  message: 'volume'
  data:
    volume: 100

Throws an Unknown Error :

The error

``` Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 794, in handle_execute_script script_result = await script_obj.async_run( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1713, in async_run return await asyncio.shield(create_eager_task(run.async_run())) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 457, in async_run await self._async_step(log_exceptions=False) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 509, in _async_step self._handle_exception( File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 539, in _handle_exception raise exception File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 507, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 736, in _async_call_service_step response_data = await self._async_run_long_action( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 699, in _async_run_long_action return await long_task ^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2543, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2580, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/notify/legacy.py", line 275, in _async_notify_message_service await self.async_send_message(**kwargs) File "/usr/src/homeassistant/homeassistant/components/notify/legacy.py", line 251, in async_send_message await self.hass.async_add_executor_job( 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/divoom/notify.py", line 194, in send_message self._device.send_volume(value=value) File "/config/custom_components/divoom/devices/divoom.py", line 322, in send_volume args += (value / 100 * 15).to_bytes(1, byteorder='big') ^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'float' object has no attribute 'to_bytes' ```

Workaround to set volume to 0 (where 0x00 is the volume)

service: notify.divoom_ditoo_plus_light
data:
  message: 'raw'
  data:
    raw: [0x08, 0x00]
d03n3rfr1tz3 commented 7 months ago

strange how that slipped through, but I could confirm it and fixed it right away. ☺️