diff --git a/custom_components/localtuya/cover.py b/custom_components/localtuya/cover.py index bdb0b20..17221d3 100644 --- a/custom_components/localtuya/cover.py +++ b/custom_components/localtuya/cover.py @@ -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, diff --git a/custom_components/localtuya/pytuya/__init__.py b/custom_components/localtuya/pytuya/__init__.py index 8e2a01c..7caad0a 100644 --- a/custom_components/localtuya/pytuya/__init__.py +++ b/custom_components/localtuya/pytuya/__init__.py @@ -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) diff --git a/custom_components/localtuya/switch.py b/custom_components/localtuya/switch.py index 67a8931..0a597a9 100644 --- a/custom_components/localtuya/switch.py +++ b/custom_components/localtuya/switch.py @@ -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) )