rospogrigio / localtuya

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

Cover give error message #423

Closed indyucoder closed 3 years ago

indyucoder commented 3 years ago

Hi, I'm using local tuya to control a 2 switch cover motor using a MOES wi-fi curtain module with Home Assistant 2021.3.4 in a PI 4 2GB installed using IOTStack scripts It works fine except for a bug when use the MOES switch, thuis happens either when use HA to control the curtain either when I control the curtain by pressing 'real' switch. I've done some debug and my undertanding is that when switch sent an update to local tuya to signal that curtain is open/close is called def status_updated(self) in cover.py and and sel._current_cover_position is updated to 'stop' from DPS 1 instead using data from DPS 2

Here the code

change = "stopped" if self._state == self._stop_cmd else "inverted" self.debug("cover postion %s diff %s", self._current_cover_position, pos_diff ) <-- Added to aid debug self._current_cover_position = min( 100, max(0, self._current_cover_position + pos_diff) )

Below the log file

`021-03-28 22:06:12 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...aab] Dispatching message TuyaMessage(seqno=0, cmd=8, retcode=0, payload=b

2021-03-28 22:06:12 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...aab] Got status update
2021-03-28 22:06:12 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...aab] Decrypted payload: {"dps":{"1":"stop","2":100},"t":1616961972}
2021-03-28 22:06:12 DEBUG (SyncWorker_5) [custom_components.localtuya.cover] [bf4...aab] cover postion stop diff 92
2021-03-28 22:06:12 ERROR (SyncWorker_5) [homeassistant.util.logging] Exception in _update_handler when dispatching 'localtuya_bf40f6a902be66b958uaab': ({'1 Traceback (most recent call last):
File "/config/custom_components/localtuya/common.py", line 239, in _update_handler
self.status_updated()
File "/config/custom_components/localtuya/cover.py", line 224, in status_updated
100, max(0, int(self._current_cover_position) + int(pos_diff))
ValueError: invalid literal for int() with base 10: 'stop'

2021-03-28 22:06:13 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...aab] Sending command heartbeat (device type: type_0a)
2021-03-28 22:06:13 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...aab] Send payload: b'{}'
2021-03-28 22:06:13 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...aab] Waiting for sequence number -100
2021-03-28 22:06:13 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...aab] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b 2021-03-28 22:06:13 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...aab] Got heartbeat response `

indyucoder commented 3 years ago

Debugged, It was my error during DP configuration for position fields ...