v.1.0.1: sending only dps actually used in request payload

This commit is contained in:
rospogrigio
2020-08-06 11:32:33 +02:00
parent 5e29b2218c
commit 98508a347a
3 changed files with 38 additions and 8 deletions

View File

@@ -39,7 +39,7 @@ _LOGGER = logging.getLogger(__name__)
DEFAULT_NAME = 'localtuyacover'
REQUIREMENTS = ['pytuya==7.0.7']
REQUIREMENTS = ['pytuya==7.0.8']
CONF_DEVICE_ID = 'device_id'
CONF_LOCAL_KEY = 'local_key'
@@ -67,10 +67,15 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
from . import pytuya
covers = []
localtuyadevice = pytuya.CoverEntity(config.get(CONF_DEVICE_ID), config.get(CONF_HOST), config.get(CONF_LOCAL_KEY))
localtuyadevice.set_version(float(config.get(CONF_PROTOCOL_VERSION)))
pytuyadevice = pytuya.CoverEntity(config.get(CONF_DEVICE_ID), config.get(CONF_HOST), config.get(CONF_LOCAL_KEY))
pytuyadevice.set_version(float(config.get(CONF_PROTOCOL_VERSION)))
dps = {}
dps[config.get(CONF_ID)]=None
dps["101"]=None
dps["102"]=None
pytuyadevice.set_dpsUsed(dps)
cover_device = TuyaCoverCache(localtuyadevice)
cover_device = TuyaCoverCache(pytuyadevice)
covers.append(
TuyaDevice(
cover_device,

View File

@@ -28,7 +28,7 @@ except ImportError:
import pyaes # https://github.com/ricmoo/pyaes
version_tuple = (7, 0, 7)
version_tuple = (7, 0, 8)
version = version_string = __version__ = '%d.%d.%d' % version_tuple
__author__ = 'rospogrigio'
@@ -218,6 +218,9 @@ class XenonDevice(object):
def set_version(self, version):
self.version = version
def set_dpsUsed(self, dpsUsed):
self.dpsUsed = dpsUsed
def generate_payload(self, command, data=None):
"""
Generate the payload to send.
@@ -243,7 +246,8 @@ class XenonDevice(object):
if data is not None:
json_data['dps'] = data
if command_hb == '0d':
json_data['dps'] = {"1": None,"101": None,"102": None}
json_data['dps'] = self.dpsUsed
# log.info('******** COMMAND IS %r', self.dpsUsed)
# Create byte buffer from hex data
json_payload = json.dumps(json_data)

View File

@@ -35,7 +35,7 @@ from threading import Lock
_LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['pytuya==7.0.7']
REQUIREMENTS = ['pytuya==7.0.8']
CONF_DEVICE_ID = 'device_id'
CONF_LOCAL_KEY = 'local_key'
@@ -89,6 +89,16 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
if len(devices) > 0:
for object_id, device_config in devices.items():
dps = {}
dps[device_config.get(CONF_ID)]=None
if device_config.get(CONF_CURRENT) != '-1':
dps[device_config.get(CONF_CURRENT)]=None
if device_config.get(CONF_CURRENT_CONSUMPTION) != '-1':
dps[device_config.get(CONF_CURRENT_CONSUMPTION)]=None
if device_config.get(CONF_VOLTAGE) != '-1':
dps[device_config.get(CONF_VOLTAGE)]=None
pytuyadevice.set_dpsUsed(dps)
outlet_device = TuyaCache(pytuyadevice)
switches.append(
TuyaDevice(
@@ -102,9 +112,19 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
device_config.get(CONF_VOLTAGE)
)
)
print('Setup localtuya subswitch [{}] with device ID [{}] '.format(device_config.get(CONF_FRIENDLY_NAME, object_id), device_config.get(CONF_ID)))
_LOGGER.info("Setup localtuya subswitch %s with device ID %s ", device_config.get(CONF_FRIENDLY_NAME, object_id), config.get(CONF_ID) )
_LOGGER.info("Setup localtuya subswitch %s with device ID %s ", device_config.get(CONF_FRIENDLY_NAME, object_id), device_config.get(CONF_ID) )
else:
dps = {}
dps[config.get(CONF_ID)]=None
if config.get(CONF_CURRENT) != '-1':
dps[config.get(CONF_CURRENT)]=None
if config.get(CONF_CURRENT_CONSUMPTION) != '-1':
dps[config.get(CONF_CURRENT_CONSUMPTION)]=None
if config.get(CONF_VOLTAGE) != '-1':
dps[config.get(CONF_VOLTAGE)]=None
pytuyadevice.set_dpsUsed(dps)
outlet_device = TuyaCache(pytuyadevice)
switches.append(
TuyaDevice(
@@ -118,6 +138,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
config.get(CONF_VOLTAGE)
)
)
print('Setup localtuya switch [{}] with device ID [{}] '.format(config.get(CONF_FRIENDLY_NAME), config.get(CONF_ID)))
_LOGGER.info("Setup localtuya switch %s with device ID %s ", config.get(CONF_FRIENDLY_NAME), config.get(CONF_ID) )