Skip to content

How to realize attribute reporting of array type #4607

@Qiu-A-Qiu

Description

@Qiu-A-Qiu

I got an error trying to write an array to a property
The following error reports occur

  File "/usr/local/lib/python3.13/site-packages/zigpy/zcl/__init__.py", line 687, in write_attributes
    return await self.write_attributes_raw(attrs, manufacturer, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/zha-device-handlers/zhaquirks/sonoff/swv.py", line 114, in write_attributes_raw
    values = Array[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]
             ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: type 'Array' is not subscriptable

This is my implementation code. Can someone explain how to send/implement sending arrays and how I should modify them

ACTION_ID_MAPPING = [0xFF01, 0xFF02, 0xFF04, 0xFF05, 0xFF06, 0xFF07]
signle_irrigation_time = ZCLAttributeDef(
            id=0x501D,
            type=Array,
            is_manufacturer_specific=True,
        )

  async def write_attributes_raw(
          self,
          attributes: list[foundation.Attribute],
          manufacturer: int | None = None,
          **kwargs,
      ):
          values = Array[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]
          
          # arrayValue = Array(values)
          arrayValue = ArrayType(values)
          for attr in attributes:
              if attr.attrid in ACTION_ID_MAPPING:
                  attr.attrid = 0x501D
                  attr.value = arrayValue
          
          return await super().write_attributes_raw(
              attributes, manufacturer=manufacturer, **kwargs
          )

Metadata

Metadata

Assignees

No one assigned

    Labels

    manufacturerThis request was made by the device's manufacturer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions