iMicknl / ha-tahoma

Custom component for Home Assistant to interact with smart devices via Somfy TaHoma or other OverKiz based API's.
MIT License
151 stars 30 forks source link

Datatype errors when get state #387

Closed tillstaff closed 3 years ago

tillstaff commented 3 years ago

Describe the bug There are repeated errors in the logs when ha-Tahoma get states from some Cozytouch Devices (Atlantic Optimocosy in my case)

Logger: custom_components.tahoma
Source: custom_components/tahoma/coordinator.py:150
Integration: Somfy TaHoma (documentation, issues)
First occurred: 11:36:45 (92 occurrences)
Last logged: 18:48:26

Unexpected error fetching events data: 'NoneType' object is not callable
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 149, in async_refresh
    self.data = await self._async_update_data()
  File "/config/custom_components/tahoma/coordinator.py", line 120, in _async_update_data
    device.states[state.name].value = self._get_state(state)
  File "/config/custom_components/tahoma/coordinator.py", line 150, in _get_state
    return caster(state.value)
TypeError: 'NoneType' object is not callable

To Reproduce I made some investigations and the error is due to several Datatype not initialized in this object : https://github.com/iMicknl/ha-tahoma/blob/0612a5ba3e3cc7282923b2d7baf98e6d75897e6a/custom_components/tahoma/coordinator.py#L20-L27

The state values that make errors are :

type: DataType.JSON_OBJECT, value {"outside": false,"co2": false,"outlet": {"newAir": false,"exhaustAir": false},"inlet": {"newAir": false,"exhaustAir": false}}
type: DataType.JSON_ARRAY, value [54,53,53,54,57,56,57,57,56,56,55,55,54,58,55,51,55,56,56,55,56,56,56,56,57,57,59,56,52,50,49,48,47,46,46,46,46,45,45,45,44,45,45,44,45,45,50,53,59,63,58,57,56,56,57,57,58,58,53,48,45,51,53,53,54,54,56,61,62,59,59,59,59,59,58,55,53,52,51,49,48,47,47,46,46,45,45,46,46,46,46,51,54,53,55,54,52,51,50,49,49,51,52,54,54,52,51,51,49,48,49,51,54,54,55,56,56,57,55,55,55,56,57,53,50,47,46,45,44,44,44,44,43,43,44,44,44,44,45,50,51,53,51,57,22]

Expected behavior Could you add the Datatypes missing?

The following code solved my problem :

TYPES = {
    DataType.NONE: None,
    DataType.INTEGER: int,
    DataType.DATE: int,
    DataType.STRING: str,
    DataType.FLOAT: float,
    DataType.BOOLEAN: bool,
    DataType.JSON_ARRAY: str,
    DataType.JSON_OBJECT: str,
}

According to the list of DataTypes available, maybe "DataType.BLOB" could be added too.

vlebourl commented 3 years ago

I do love an issue that's already almost resolved ^^ I'm not sure that casting to a str is the right thing to do though... Any idea how this state is used? If some or all elements of the dict or the list should be used as the actual state to be returned, str would not cut it...

vlebourl commented 3 years ago

Any idea what a BLOB is?

iMicknl commented 3 years ago

Any idea what a BLOB is?

I haven't seen any example of a BLOB in this event context yet. Normally, a blob represents a file-like object of immutable, raw data. Via the mime type you are able to understand how to render the blob.

For now, I would just leave those out. I haven't seen any events using blobs yet. Perhaps they are used for camera's.

tillstaff commented 3 years ago

@vlebourl I don't have any idea about BLOB.

But for the two states linked, here are the references :

            "name": "io:SensorsErrorState",
            "type": 11,
            "value": {
              "outside": false,
              "co2": false,
              "outlet": {
                "newAir": false,
                "exhaustAir": false
              },
              "inlet": {
                "newAir": false,
                "exhaustAir": false
              }
            }
          {
            "name": "io:CO2HistoryState",
            "type": 10,
            "value": [54,53,53,54,57,56,57,57,56,56,55,55,54,58,55,51,55,56,56,55,56,56,56,56,57,57,59,56,52,50,49,48,47,46,46,46,46,45,45,45,44,45,45,44,45,45,50,53,59,63,58,57,56,56,57,57,58,58,53,48,45,51,53,53,54,54,56,61,62,59,59,59,59,59,58,55,53,52,51,49,48,47,47,46,46,45,45,46,46,46,46,51,54,53,55,54,52,51,50,49,49,51,52,54,54,52,51,51,49,48,49,51,54,54,55,56,56,57,55,55,55,56,57,53,50,47,46,45,44,44,44,44,43,43,44,44,44,44,45,50,51,53,51,57,22]
          },
vlebourl commented 3 years ago

Could you try this branch: https://github.com/iMicknl/ha-tahoma/archive/fix/missing_datatype.zip before it's released?

tillstaff commented 3 years ago

@vlebourl I just tested this build and it's ok, thanks for your help.

Although, the debug logs show always "state: None -> None"? Is that normal?

2021-02-17 14:46:23 DEBUG (MainThread) [custom_components.tahoma.coordinator] EventName.DEVICE_STATE_CHANGED/None (device: io://xxxx-xxxx-xxxx/15021786#1, state: None -> None)
2021-02-17 14:47:23 DEBUG (MainThread) [custom_components.tahoma.coordinator] EventName.DEVICE_STATE_CHANGED/None (device: io://xxxx-xxxx-xxxx/15021786#1, state: None -> None)
vlebourl commented 3 years ago

yeah, that's normal I think. @iMicknl do you confirm?

iMicknl commented 3 years ago

Yes, this is normal behavior. Currently that only shows the execution state, thus that logging is quite limited still.

2021-02-12 17:52:39 DEBUG (MainThread) [custom_components.tahoma.coordinator] EventName.EXECUTION_STATE_CHANGED/xxxxxxxx-ac10-3e01-0169-e76212d8c5a3 (device: None, state: ExecutionState.INITIALIZED -> ExecutionState.NOT_TRANSMITTED)
tillstaff commented 3 years ago

Ok, it's good to know!