Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MappedDevice Phase II #370

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
8 changes: 6 additions & 2 deletions tinytuya/Cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def _build_mapping( src, dst ):
if dp_id in dst:
continue
data = { 'code': code, 'type': mapp['type'] }
if mapp['type'].lower() == 'string':
if (mapp['type'].lower() == 'string') and (mapp['values'][0] != '{' or mapp['values'][-1] != '}'):
values = mapp['values']
else:
try:
Expand All @@ -827,7 +827,7 @@ def getmapping( self, productid, deviceid=None ):
if not self.mappings:
self.mappings = {} #load_mappings()

if productid in self.mappings:
if productid and (productid in self.mappings):
# already have this product id, so just return it
return self.mappings[productid]

Expand All @@ -844,10 +844,14 @@ def getmapping( self, productid, deviceid=None ):
self._build_mapping( result['status'], dps )
if 'functions' in result:
self._build_mapping( result['functions'], dps )
if not productid:
return dps
self.mappings[productid] = dps
log.debug( 'Downloaded mapping for device %r: %r', deviceid, dps)
elif ('code' in result and result['code'] == 2009) or ('msg' in result and result['msg'] == 'not support this device'):
# this device does not have any DPs!
if not productid:
return {}
self.mappings[productid] = {}

if productid in self.mappings:
Expand Down
Loading