8000 [Bug]: 0 is interpreted as None, this is incorrect. · Issue #652 · xZetsubou/hass-localtuya · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Bug]: 0 is interpreted as None, this is incorrect. #652

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

Open
3 tasks
mephdrac opened this issue May 16, 2025 · 1 comment
Open
3 tasks

[Bug]: 0 is interpreted as None, this is incorrect. #652

mephdrac opened this issue May 16, 2025 · 1 comment
Labels
bug Something isn't working master/next-release Fixed in master branch, Will be ready in the next release

Comments

@mephdrac
Copy link

LocalTuya Version

No response

Home Assistant Version

2025.5.1

Environment

  • Does the device work using the Home Assistant Tuya Cloud component?
  • Is this device connected to another local integration, including Home Assistant and any other tools?
  • The devices are within the same HA subnet, and they get discovered automatically when I add them

What happened?

0 is interpreted as None, this is incorrect.

In sensor.py, in the function "def status_updated(self):" is the code:

if (sub_sensor := getattr(self, "_attr_sub_sensor", None)) and (
  sub_state := self.decode_base64(state).get(sub_sensor)
  ):
     self._state = sub_state
else:
     self._state = state"

The following code is better. Because if a sensor returns 0, it must not be interpreted as None.

sub_sensor = getattr(self, "_attr_sub_sensor", None)
decoded = self.decode_base64(state)

if sub_sensor is not None and sub_sensor is in decoded:
  self._state = decoded[sub_sensor]
else:
   self._state = state

Steps to reproduce.

Add a sensor with base64 - Value. And change the Value to 0.

Relevant log output

Diagnostics information.

No response

@mephdrac mephdrac added the bug Something isn't working label May 16, 2025
@xZetsubou
Copy link
Owner

0 doesn't interpreted as None; tho both of them interpreted as false values, when I made then I never thought about 0 being an actual value of power, voltage or current

This will works
e.g.

            if None not in (
                sub_sensor := getattr(self, "_attr_sub_sensor"),
                sub_state := self.decode_base64(state).get(sub_sensor),
            ):
                self._state = sub_state
            else:
                self._state = state

Thanks for noticing/reporting this :)

@xZetsubou xZetsubou added the master/next-release Fixed in master branch, Will be ready in the next release label May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working master/next-release Fixed in master branch, Will be ready in the next release
Projects
None yet
Development

No branches or pull requests

2 participants
0