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: object of type 'NoneType' has no len() #114

Closed
4 tasks done
ejpenney opened this issue Jan 25, 2024 · 8 comments
Closed
4 tasks done

TypeError: object of type 'NoneType' has no len() #114

ejpenney opened this issue Jan 25, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@ejpenney
Copy link

ejpenney commented Jan 25, 2024

The problem

Just upgraded to 2024.1.5 from 2023.12.1 and started seeing these errors when attempting to turn on a light:

TypeError: object of type 'NoneType' has no len()

Environment

  • Localtuya version: 3.2.4
  • Home Assistant Core version: 2024..1.5
  • Home Assistant Installtion Method: HAOS
  • Does the device work using the Home Assistant Tuya Cloud component ? Yes-ish, but not really. Device is configured in an unusable way
  • Does the device work using the Tinytuya (https://github.com/jasonacox/tinytuya) command line tool ? Yes
  • Was the device working with earlier versions of localtuya ? Which one? N/A I now suspect a configuration issue
  • Are you using the Tuya/SmartLife App in parallel ?

Steps to reproduce

  1. Call service light.turn_on
  2. Light doesn't turn on
  3. Error appears in log

DP dump

Provide Home Assistant traceback/logs

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:238
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 8:07:29 AM (3 occurrences)
Last logged: 8:10:23 AM

[140020412085824] object of type 'NoneType' has no len()
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 238, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2149, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2186, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/adaptive_lighting/hass_utils.py", line 61, in service_func_proxy
    await existing_service.job.target(call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 272, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 882, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 952, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 624, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/config/custom_components/localtuya/light.py", line 343, in async_turn_on
    if self.__is_color_rgb_encoded():
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/light.py", line 298, in __is_color_rgb_encoded
    return len(self.dp_value(CONF_COLOR)) > 12
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object of type 'NoneType' has no len()

Additional information

@ejpenney ejpenney added the bug Something isn't working label Jan 25, 2024
@ejpenney
Copy link
Author

I've been poking at this for about 2 hours, trying to understand what was wrong, and the light just started working again. I'm starting to suspect I have this device configured incorrectly, so maybe this is more of a "question" than a bug.

The tuyadebug package completely fails to connect to the device (I've closed all connections, but it just doesn't work)

3.4
INFO:localtuya:localtuya version 1.0.0
INFO:localtuya:Python 3.11.0rc1 (main, Aug 12 2022, 10:02:14) [GCC 11.2.0] on linux
INFO:localtuya:Using pytuya version '10.0.0'
INFO:localtuya:TIMEOUT: No response from device ebc16352d8cddbec2cglnv [192.168.86.165] after 2 attempts

tinytuya works, and does give a list of DPs:

  {
      "id": "ebc16352d8cddbec2cglnv",
      "ip": "192.168.86.165",
      "active": 2,
      "encrypt": true,
      "productKey": "key7pee5nc48yn4f",
      "token": true,
      "wf_cfg": true,
      "name": "Family Room Light",
      "key": "<REDACTED>",
      "mac": "a8:80:55:e3:ce:b1",
      "ability": 0,
      "dev_type": "default",
      "err": "",
      "type": "default",
      "dps": {
          "dps": {
              "20": true,
              "21": "white",
              "22": 318,
              "23": 884,
              "24": "00db01f6012b",
              "25": "010e0d0000000000000003e801f4",
              "26": 0,
              "34": false,
              "54": false,
              "55": "colour",
              "63": true
          }
      },
      "origin": "broadcast",
      "ver": "3.4"
  }

I have it configured like so in localtuya (from .storage/core.config_entries):

  "ebc16352d8cddbec2cglnv": {
    "friendly_name": "Family Room Light",
    "host": "192.168.86.165",
    "local_key": "<REDACTED>",
    "protocol_version": "3.4",
    "enable_debug": false,
    "manual_dps_strings": "27,28,52,54,56,57,61,63",
    "reset_dpids": "20,54,63",
    "entities": [
      {
        "friendly_name": "Family Room",
        "entity_category": "None",
        "brightness": "22",
        "color_temp": "23",
        "brightness_lower": 29,
        "brightness_upper": 1000,
        "color_mode": "21",
        "color_temp_min_kelvin": 2000,
        "color_temp_max_kelvin": 6535,
        "color_temp_reverse": false,
        "scene": "25",
        "music_mode": false,
        "id": "63",
        "platform": "light",
        "icon": ""
      },
      {
        "friendly_name": "Family Room Color",
        "entity_category": "None",
        "brightness_lower": 29,
        "brightness_upper": 1000,
        "color_mode": "55",
        "color": "24",
        "color_temp_min_kelvin": 2700,
        "color_temp_max_kelvin": 6500,
        "color_temp_reverse": false,
        "scene": "56",
        "music_mode": false,
        "id": "54",
        "platform": "light",
        "icon": ""
      },
      {
        "friendly_name": "Do Not Disturb",
        "entity_category": "None",
        "restore_on_reconnect": false,
        "is_passive_entity": false,
        "id": "34",
        "platform": "switch",
        "icon": ""
      }
    ],
    "model": "Smart Ceiling Light",
    "product_key": "key7pee5nc48yn4f",
    "device_id": "ebc16352d8cddbec2cglnv",
    "node_id": null,
    "dps_strings": [
      "20 (value: True)",
      "21 (value: white)",
      "22 (value: 273)",
      "23 (value: 997)",
      "24 (value: 016803e803e8)",
      "25 (value: 05464601000003e803e800000000464601007803e803e80000000046460100f003e803e800000000)",
      "26 (value: 0)",
      "34 (value: False)",
      "54 (value: False)",
      "55 (value: colour)",
      "63 (value: True)",
      "27 (value: -1)",
      "28 (value: -1)",
      "52 (value: -1)",
      "56 (value: -1)",
      "57 (value: -1)",
      "61 (value: -1)"
    ]
  },

This light has two individually controllable lights. One "main light" that is color_temp only, and one "auxiliary light" that is essentially an LED Strip. By default localtuya configures this as one light entity but then I can't properly control the light. With my custom configuration I get two light entities, one for the color_temp light, and another for the RGB light, and can control them correctly. I suspect the device is getting into a weird state and that's why it stopped working, my poking at it/debugging got it out of that state and things started working again.

Any insights would be much appreciated, I suspect I need to change my configuration.

@xZetsubou
Copy link
Owner

The tuyadebug package completely fails to connect to the device (I've closed all connections, but it just doesn't work)

This is probably because you're using the upstream tuyadebug, try this fork package.

wget https://github.com/xZetsubou/hass-localtuya/raw/master/tuyadebug.tgz
tar -zxvf tuyadebug.tgz && cd tuyadebug
python test.py "device_id" "host_ip" "localkey" "3.5" 

You seemed you aren't using cloud set-up with localtuya that's I'm guessing DPs codes not showing up.
which light were you trying to turn on? both or one of them

@ejpenney
Copy link
Author

ejpenney commented Jan 26, 2024

Hi, thanks for responding.

The forked version of tuyadebug does the same thing, no response after 2 attempts.

It was the white (color temperature only) light I was trying to use. That's correct, I'm not using the auto-setup. If I do, it creates one entity using DP 20 which in this case is an odd entity that only controls the last light that was used. Meaning you can't use it to control both/either light.

A little further investigation: before the light went into an odd state, my spouse was the color (auxiliary) light, it's an individually addressable LED strip around the base of the light. It was set to use a scene set from the app that was multiple colors in motion... Feels like there's a hint there. Again, I'm becoming more and more certain I have the configuration wrong.

@xZetsubou
Copy link
Owner

Can you post your entry diagnostics

@xZetsubou
Copy link
Owner

Thanks, btw, you haven't told which of the entities when turn it on it raises the error is it both?

I'm quite confused here because the logs error lines doesn't match the latest version of this fork not sure if the error. which seems it's outdated, can you re-check if this issue shows in 3.2.4 and post new logs.

@ejpenney
Copy link
Author

Thanks, btw, you haven't told which of the entities when turn it on it raises the error is it both?

Quoting myself from above:

It was the white (color temperature only) light I was trying to use.

I'm quite confused here because the logs error lines doesn't match the latest version of this fork not sure if the error. which seems it's outdated, can you re-check if this issue shows in 3.2.4 and post new logs

OK... I have 3.2.4 installed, I guess I could have HACS redownload? Not sure what's not matching in the logs, this line is throwing the error.

This is the manifest.json I've got:

{
  "domain": "localtuya",
  "name": "Local Tuya",
  "codeowners": [],
  "config_flow": true,
  "dependencies": [],
  "documentation": "https://github.com/xZetsubou/hass-localtuya/",
  "integration_type": "hub",
  "iot_class": "local_push",
  "issue_tracker": "https://github.com/xZetsubou/hass-localtuya/issues",
  "requirements": [],
  "version": "3.2.4"
}

@xZetsubou
Copy link
Owner

xZetsubou commented Jan 28, 2024

Not sure what's not matching in the logs, this line is throwing the error

Sorry, it seems my local "light.py" module is modified.

I don't know why it return false when it check if it's white mode or not unless DP 21 mode changed to colour.

if self.is_white_mode:
states[self._config.get(CONF_BRIGHTNESS)] = brightness
else:
if self.__is_color_rgb_encoded():

This is my guessing you specified a brightness value in turn_on service but the DP 21 is not white mode at the same time which raises this error because if_white_mode will return false. then it thought that the mode is colour and checked color value which it doesn't exists.

If my guess is right then turning the light with this, will works.

service: light.turn_on
data:
  color_temp: 407
target:
  entity_id: light.kamzai_smart_bulb

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

No branches or pull requests

2 participants