rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.74k stars 533 forks source link

Error while setting up the number platform after update #1005

Open DeerMaximum opened 1 year ago

DeerMaximum commented 1 year ago

The problem

After the update to 4.0.2, entities with the platform number can no longer be created. This is because the update changed the configuration keys from min_value to native_min_value and max_value to native_max_value without fixing the values in existing configurations and without mentioning it in the changelogs.

Environment

Steps to reproduce

  1. Update
  2. Home Assistant

Configuration configuration.yaml or config_flow

"device_config": {
      "friendly_name": "AC",
      "host": "xxxxx",
      "local_key": "xxxxx",
      "protocol_version": "3.3",
      "entities": [
        {
          "friendly_name": "AC Status",
          "id": 1,
          "platform": "switch"
        },
        {
          "friendly_name": "AC Zieltemperatur Number",
          "id": 2,
          "device_class": "temperature",
          "min_value": 0,
          "max_value": 300,
          "platform": "number"
        },
        {
          "friendly_name": "AC Aktuelle Temperatur",
          "device_class": "temperature",
          "scaling": 0.1,
          "unit_of_measurement": "\u00b0C",
          "id": 3,
          "platform": "sensor"
        },
        {
          "friendly_name": "AC Modus",
          "select_options": "auto;cold;wet;hot;wind",
          "select_options_friendly": "Auto;cool;dry;heat;fan_only_only",
          "id": 4,
          "platform": "select"
        },
        {
          "friendly_name": "AC L\u00fcfterst\u00e4rke",
          "select_options": "auto;mute;low;mid;high;strength",
          "select_options_friendly": "Auto;Mute;Low;Mid;High;Full",
          "id": 5,
          "platform": "select"
        },
        {
          "friendly_name": "AC Display",
          "id": 13,
          "platform": "switch"
        },
        {
          "friendly_name": "AC ECO",
          "id": 8,
          "platform": "switch"
        }
      ],
      "device_id": "xxxxx",
      "dps_strings": [
        "1 (value: True)",
        "2 (value: 280)",
        "3 (value: 260)",
        "4 (value: cold)",
        "5 (value: mute)",
        "8 (value: False)",
        "12 (value: False)",
        "13 (value: True)",
        "14 (value: False)",
        "19 (value: C)",
        "28 (value: 0)",
        "33 (value: False)",
        "102 (value: False)",
        "103 (value: False)",
        "104 (value: False)",
        "105 (value: False)",
        "106 (value: False)",
        "107 (value: 0)",
        "108 (value: 14)",
        "109 (value: False)",
        "110 (value: False)",
        "111 (value: 0)",
        "112 (value: 0)",
        "114 (value: False)"
      ],
      "product_key": "xxxxx"
    }

DP dump

Provide Home Assistant taceback/logs

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 571, in _async_add_entity
    capabilities=entity.capability_attributes,
  File "/usr/src/homeassistant/homeassistant/components/number/__init__.py", line 253, in capability_attributes
    ATTR_STEP: self.step,
  File "/usr/src/homeassistant/homeassistant/components/number/__init__.py", line 339, in step
    value_range = abs(self.max_value - self.min_value)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

Additional information

timnolte commented 1 year ago

This is a major problem as now all of my number entities are broken and unavailable. I don't understand how 4.0.2 was considered a fix for the number entity when in fact it broke them, at least for me.

timnolte commented 1 year ago

Seems there should have been conversion code in place for this last fix. My data looks like this:

  "data": {
    "region": "us",
    "username": "localtuya",
    "no_cloud": true,
    "client_id": "...",
    "client_secret": "...",
    "user_id": "...",
    "devices": {
      "xxxxxxxxxxxxxxxxx": {
        "friendly_name": "Coffee Maker",
        "host": "xxx.xx.xx.xxx",
        "local_key": "c29...eb7",
        "protocol_version": "3.3",
        "entities": [
          {
            "friendly_name": "Coffee Maker Start/Pause",
            "current": 101,
            "id": 101,
            "platform": "switch"
          },
          {
            "friendly_name": "Coffee Maker Working Mode",
            "id": 102,
            "platform": "sensor"
          },
          {
            "friendly_name": "Coffee Maker Reservation",
            "min_value": 0.0,
            "max_value": 1440.0,
            "id": 103,
            "platform": "number"
          },
          {
            "friendly_name": "Coffee Maker Timer Functon Switch",
            "min_value": 0.0,
            "max_value": 1.0,
            "id": 109,
            "platform": "number"
          },
          {
            "friendly_name": "Coffee Maker Suspend",
            "current": 108,
            "id": 108,
            "platform": "switch"
          },
          {
            "friendly_name": "Coffee Maker Material Selection",
            "select_options": "chroma_1;chroma_2;chroma_3",
            "select_options_friendly": "Regular;Medium;Strong",
            "id": 107,
            "platform": "select"
          },
          {
            "friendly_name": "Coffee Maker Material Selection State",
            "id": 106,
            "platform": "sensor"
          },
          {
            "friendly_name": "Coffee Maker Status",
            "id": 105,
            "platform": "sensor"
          }
        ],
        "device_id": "xxxxxxxxxxxxxxxxx",
        "dps_strings": [
          "101 (value: False)",
          "102 (value: auto)",
          "103 (value: 720)",
          "105 (value: 0)",
          "106 (value: chroma_3)",
          "107 (value: chroma_3)",
          "108 (value: False)",
          "109 (value: False)"
        ],
        "product_key": "xxxxxxxxxxxxxxxxx"
      }
    },
    "updated_at": "1659294529659",
    "cloud_devices": {}
  }
timnolte commented 1 year ago

@DeerMaximum out of curiosity I tried editing my device and setting up the entities again. This appears to have fixed the issue with the stored configuration having min_value & max_value instead of native_min_value & native_max_value.

DeerMaximum commented 1 year ago

Yes, changing the values manually also solved the problem for me.

megarch2021 commented 1 year ago

@timnolte Can you please show where you updated this? is it /config/.storage/core.config_entries? I cant find anything within /config/custom_components/localtuya/ Thanks

timnolte commented 1 year ago

@megarch2021 I did this via the device Configuration in the Home Assistant UI, not via any configuration file. I chose the option to edit an existing device.