set_dpsUsed turned into add_dps_to_request ; used it when setting up entities
This commit is contained in:
@@ -55,7 +55,6 @@ def prepare_setup_entities(config_entry, platform):
|
|||||||
config_entry.data[CONF_LOCAL_KEY],
|
config_entry.data[CONF_LOCAL_KEY],
|
||||||
)
|
)
|
||||||
device.set_version(float(config_entry.data[CONF_PROTOCOL_VERSION]))
|
device.set_version(float(config_entry.data[CONF_PROTOCOL_VERSION]))
|
||||||
device.set_dpsUsed({})
|
|
||||||
return device, entities_to_setup
|
return device, entities_to_setup
|
||||||
|
|
||||||
|
|
||||||
|
@@ -86,12 +86,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
if not entities_to_setup:
|
if not entities_to_setup:
|
||||||
return
|
return
|
||||||
|
|
||||||
# TODO: keeping for now but should be removed
|
|
||||||
dps = {}
|
|
||||||
|
|
||||||
covers = []
|
covers = []
|
||||||
for device_config in entities_to_setup:
|
for device_config in entities_to_setup:
|
||||||
dps[device_config[CONF_ID]] = None
|
# this has to be done in case the device type is type_0d
|
||||||
|
device.add_dps_to_request(device_config[CONF_ID])
|
||||||
|
|
||||||
covers.append(
|
covers.append(
|
||||||
LocaltuyaCover(
|
LocaltuyaCover(
|
||||||
TuyaCache(device, config_entry.data[CONF_FRIENDLY_NAME]),
|
TuyaCache(device, config_entry.data[CONF_FRIENDLY_NAME]),
|
||||||
@@ -100,7 +99,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
device.set_dpsUsed(dps)
|
|
||||||
async_add_entities(covers, True)
|
async_add_entities(covers, True)
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
@@ -61,6 +61,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
|
|
||||||
lights = []
|
lights = []
|
||||||
for device_config in entities_to_setup:
|
for device_config in entities_to_setup:
|
||||||
|
# this has to be done in case the device type is type_0d
|
||||||
|
device.add_dps_to_request(device_config[CONF_ID])
|
||||||
|
|
||||||
lights.append(
|
lights.append(
|
||||||
LocaltuyaLight(
|
LocaltuyaLight(
|
||||||
TuyaCache(device, config_entry.data[CONF_FRIENDLY_NAME]),
|
TuyaCache(device, config_entry.data[CONF_FRIENDLY_NAME]),
|
||||||
|
@@ -20,8 +20,8 @@
|
|||||||
json = status() # returns json payload
|
json = status() # returns json payload
|
||||||
set_version(version) # 3.1 [default] or 3.3
|
set_version(version) # 3.1 [default] or 3.3
|
||||||
detect_available_dps() # returns a list of available dps provided by the device
|
detect_available_dps() # returns a list of available dps provided by the device
|
||||||
set_dpsUsed(dpsUsed)
|
add_dps_to_request(dps_index) # adds dps_index to the list of dps used by the device (to be queried in the payload)
|
||||||
set_dps(on, dps_index) # Set int value of any dps index.
|
set_dps(on, dps_index) # Set value of any dps index.
|
||||||
set_timer(num_secs):
|
set_timer(num_secs):
|
||||||
|
|
||||||
|
|
||||||
@@ -194,6 +194,7 @@ class TuyaDevice(object):
|
|||||||
self.connection_timeout = connection_timeout
|
self.connection_timeout = connection_timeout
|
||||||
self.version = 3.1
|
self.version = 3.1
|
||||||
self.dev_type = 'type_0a'
|
self.dev_type = 'type_0a'
|
||||||
|
self.dps_to_request = {}
|
||||||
|
|
||||||
self.port = 6668 # default - do not expect caller to pass in
|
self.port = 6668 # default - do not expect caller to pass in
|
||||||
|
|
||||||
@@ -248,7 +249,9 @@ class TuyaDevice(object):
|
|||||||
detected_dps = {}
|
detected_dps = {}
|
||||||
|
|
||||||
# dps 1 must always be sent, otherwise it might fail in case no dps is found in the requested range
|
# dps 1 must always be sent, otherwise it might fail in case no dps is found in the requested range
|
||||||
self.set_dpsUsed({ str(dps): None for dps in chain(range(1,2), range(2, 11)) })
|
self.dps_to_request = {"1": None}
|
||||||
|
for dps in range(2, 11):
|
||||||
|
self.add_dps_to_request(dps)
|
||||||
try:
|
try:
|
||||||
data = self.status()
|
data = self.status()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -259,7 +262,9 @@ class TuyaDevice(object):
|
|||||||
if self.dev_type == "type_0a":
|
if self.dev_type == "type_0a":
|
||||||
return detected_dps
|
return detected_dps
|
||||||
|
|
||||||
self.set_dpsUsed({ str(dps): None for dps in chain(range(1,2), range(11, 21)) })
|
self.dps_to_request = {"1": None}
|
||||||
|
for dps in range(11, 21):
|
||||||
|
self.add_dps_to_request(dps)
|
||||||
try:
|
try:
|
||||||
data = self.status()
|
data = self.status()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -267,7 +272,9 @@ class TuyaDevice(object):
|
|||||||
raise CannotConnect
|
raise CannotConnect
|
||||||
detected_dps.update( data["dps"] )
|
detected_dps.update( data["dps"] )
|
||||||
|
|
||||||
self.set_dpsUsed({ str(dps): None for dps in chain(range(1,2), range(21, 31)) })
|
self.dps_to_request = {"1": None}
|
||||||
|
for dps in range(21, 31):
|
||||||
|
self.add_dps_to_request(dps)
|
||||||
try:
|
try:
|
||||||
data = self.status()
|
data = self.status()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -275,7 +282,9 @@ class TuyaDevice(object):
|
|||||||
raise CannotConnect
|
raise CannotConnect
|
||||||
detected_dps.update( data["dps"] )
|
detected_dps.update( data["dps"] )
|
||||||
|
|
||||||
self.set_dpsUsed({ str(dps): None for dps in chain(range(1,2), range(100, 111)) })
|
self.dps_to_request = {"1": None}
|
||||||
|
for dps in range(100, 111):
|
||||||
|
self.add_dps_to_request(dps)
|
||||||
try:
|
try:
|
||||||
data = self.status()
|
data = self.status()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -286,8 +295,8 @@ class TuyaDevice(object):
|
|||||||
|
|
||||||
return detected_dps
|
return detected_dps
|
||||||
|
|
||||||
def set_dpsUsed(self, dpsUsed):
|
def add_dps_to_request(self, dps_index):
|
||||||
self.dpsUsed = dpsUsed
|
self.dps_to_request[str(dps_index)] = None
|
||||||
|
|
||||||
def generate_payload(self, command, data=None):
|
def generate_payload(self, command, data=None):
|
||||||
"""
|
"""
|
||||||
@@ -314,8 +323,8 @@ class TuyaDevice(object):
|
|||||||
if data is not None:
|
if data is not None:
|
||||||
json_data['dps'] = data
|
json_data['dps'] = data
|
||||||
if command_hb == '0d':
|
if command_hb == '0d':
|
||||||
json_data['dps'] = self.dpsUsed
|
json_data['dps'] = self.dps_to_request
|
||||||
# log.info('******** COMMAND IS %r', self.dpsUsed)
|
# log.info('******** COMMAND IS %r', self.dps_to_request)
|
||||||
|
|
||||||
# Create byte buffer from hex data
|
# Create byte buffer from hex data
|
||||||
json_payload = json.dumps(json_data)
|
json_payload = json.dumps(json_data)
|
||||||
|
@@ -101,6 +101,15 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
|
|
||||||
switches = []
|
switches = []
|
||||||
for device_config in entities_to_setup:
|
for device_config in entities_to_setup:
|
||||||
|
# this has to be done in case the device type is type_0d
|
||||||
|
device.add_dps_to_request(device_config[CONF_ID])
|
||||||
|
if device_config[CONF_CURRENT] != "-1":
|
||||||
|
device.add_dps_to_request(device_config[CONF_CURRENT])
|
||||||
|
if device_config[CONF_CURRENT_CONSUMPTION] != "-1":
|
||||||
|
device.add_dps_to_request(device_config[CONF_CURRENT_CONSUMPTION])
|
||||||
|
if device_config[CONF_VOLTAGE] != "-1":
|
||||||
|
device.add_dps_to_request(device_config[CONF_VOLTAGE])
|
||||||
|
|
||||||
switches.append(
|
switches.append(
|
||||||
LocaltuyaSwitch(
|
LocaltuyaSwitch(
|
||||||
TuyaCache(device, config_entry.data[CONF_FRIENDLY_NAME]),
|
TuyaCache(device, config_entry.data[CONF_FRIENDLY_NAME]),
|
||||||
|
Reference in New Issue
Block a user