Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: unsupported operand type(s) for -: 'NoneType' and 'float' when a light device is unavailable #1738

Closed
robinhood-code opened this issue Mar 11, 2024 · 2 comments

Comments

@robinhood-code
Copy link

robinhood-code commented Mar 11, 2024

This form is for reporting bugs. If you have encountered a bug, you should
generally have some log messages or device diagnostics to show something is
going wrong. If your problem is more of a question or a request for help,
then Discussions is
probably a more suitable venue.

Describe the bug
A clear and concise description of what the bug is.

When a light device is unavailable and brightness setting is changed (via automation), the following error will be thrown. This seems to break the receive loop as well so Tuya Local cannot try reconnecting to the device:

Source: custom_components/tuya_local/device.py:218
integration: Tuya Local ([documentation](https://github.com/make-all/tuya-local), [issues](https://github.com/make-all/tuya-local/issues))
First occurred: March 11, 2024 at 10:32:44 PM (1 occurrences)
Last logged: March 11, 2024 at 10:32:44 PM

Front Garden Bed receive loop terminated by exception unsupported operand type(s) for -: 'NoneType' and 'float'
Traceback (most recent call last):
  File "/config/custom_components/tuya_local/device.py", line 218, in receive_loop
    entity.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 992, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1113, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1052, in __async_calculate_state
    attr.update(self.state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 1202, in state_attributes
    data[ATTR_BRIGHTNESS] = self.brightness
                            ^^^^^^^^^^^^^^^
  File "/config/custom_components/tuya_local/light.py", line 149, in brightness
    return self._white_brightness
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tuya_local/light.py", line 157, in _white_brightness
    val = color_util.value_to_brightness(r, val)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/color.py", line 782, in value_to_brightness
    max(1, round(scale_to_ranged_value(low_high_range, (1, 255), value))),
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/scaling.py", line 50, in scale_to_ranged_value
    return (value - source_offset) * (
            ~~~~~~^~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'
image

To Reproduce
Steps to reproduce the behavior including the device the issue was observed with:

  1. Make a light device unavailable
  2. run automation to change the brightness of the device
  3. error will be thrown

Expected behavior
A clear and concise description of what you expected to happen.

  1. None is checked / error is caught and doesn't prevent TL to try reconnecting to the device

Additional context
Add any other context about the problem here.

If the bug involves a device, then please include device diagnostics from
Settings / Devices & Services / Tuya Local (your device) / "1 device"

Please check if there are messages from Tuya Local in the Home
Assistant log (Settings / System / Logs), and include those too.

If applicable, add screenshots to help explain your problem.

@robinhood-code robinhood-code added the bug Something isn't working label Mar 11, 2024
make-all added a commit that referenced this issue Mar 13, 2024
If the brightness dp is not available, trying to get the light's
brightness will result in an exception. During startup this can cause the
light to fail initialisation, and remain unavailable even if the issue
resolves itself later.

Issue #1738 (related to earlier #1513 fix for fans)
@make-all make-all added awaiting confirmation Wating for confirmation the issue is solved unreleased Will be in next release labels Mar 13, 2024
@hellboy-wien
Copy link

Hello, i dont know, but i have FAN (Windcalm) after some Updates the device stays Unavailable:
Maybe it helps in that issue

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: custom_components.tuya_local.device
Quelle: custom_components/tuya_local/device.py:218
Integration: Tuya Local (Dokumentation, Probleme)
Erstmals aufgetreten: 13. März 2024 um 16:41:20 (1 Vorkommnisse)
Zuletzt protokolliert: 13. März 2024 um 16:41:20

Deckenventilator receive loop terminated by exception unsupported operand type(s) for -: 'NoneType' and 'float'
Traceback (most recent call last):
File "/config/custom_components/tuya_local/device.py", line 218, in receive_loop
entity.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 992, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1113, in _async_write_ha_state
state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1052, in __async_calculate_state
attr.update(self.state_attributes or {})
^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/fan/init.py", line 426, in state_attributes
data[ATTR_PERCENTAGE] = self.percentage
^^^^^^^^^^^^^^^
File "/config/custom_components/tuya_local/fan.py", line 121, in percentage
val = ranged_value_to_percentage(r, val)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/util/percentage.py", line 79, in ranged_value_to_percentage
return scale_ranged_value_to_int_range(low_high_range, (1, 100), value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/util/scaling.py", line 23, in scale_ranged_value_to_int_range
(value - source_offset)
~~~~~~^~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'

@make-all
Copy link
Owner

The fan issue was already fixed under #1513

@make-all make-all removed bug Something isn't working awaiting confirmation Wating for confirmation the issue is solved unreleased Will be in next release labels Mar 27, 2024
timlaing pushed a commit to timlaing/tuya-local that referenced this issue Aug 8, 2024
If the brightness dp is not available, trying to get the light's
brightness will result in an exception. During startup this can cause the
light to fail initialisation, and remain unavailable even if the issue
resolves itself later.

Issue make-all#1738 (related to earlier make-all#1513 fix for fans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants