Skip to content

Commit

Permalink
fix translation for value-list
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Oct 30, 2024
1 parent 506fb3a commit 466c9df
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions custom_components/xiaomi_miot/core/miot_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ def generate_entity_id(self, entity, suffix=None, domain=None):
return f'{domain}.{eid}'

def get_spec_translation(self, siid, piid=None, aiid=None, viid=None):
if viid is not None and not self.trans_options:
if viid != None and not self.trans_options:
return None
key = MiotSpec.spec_lang_key(siid, piid, aiid, viid)
key = MiotSpec.spec_lang_key(siid, piid=piid, aiid=aiid, viid=viid)
langs = get_translation_langs(self.hass, list(self.spec_translations.keys()))
for lang in langs:
dic = self.spec_translations.get(lang) or {}
val = dic.get(key)
if val is not None:
if val != None:
return val
return None

Expand Down Expand Up @@ -403,11 +403,11 @@ def unique_prop(siid, piid=None, aiid=None, eiid=None, valid=False):
@staticmethod
def spec_lang_key(siid, piid=None, aiid=None, viid=None):
key = f'service:{siid:03}'
if aiid is not None:
if aiid != None:
return f'{key}:action:{aiid:03}'
if piid is not None:
if piid != None:
key = f'{key}:property:{piid:03}'
if viid is not None:
if viid != None:
key = f'{key}:valuelist:{viid:03}'
return key

Expand Down Expand Up @@ -713,7 +713,14 @@ def generate_entity_id(self, entity, domain=None):
return eid

def get_spec_translation(self, viid=None):
return self.service.get_spec_translation(piid=self.iid, viid=viid)
if viid == None:
return self.service.get_spec_translation(piid=self.iid)
idx = 0
for v in self.value_list:
if viid == v.get('value'):
return self.service.get_spec_translation(piid=self.iid, viid=idx)
idx += 1
return None

@property
def translation_keys(self):
Expand Down Expand Up @@ -754,7 +761,7 @@ def list_value(self, des):
vde = v.get('description')
if des is None:
rls.append(val)
elif des in [vde, f'{vde}'.lower(), self.get_translation(vde)]:
elif des in [vde, f'{vde}'.lower(), self.get_translation(vde, viid=val)]:
return val
return rls if des is None else None

Expand Down Expand Up @@ -807,7 +814,7 @@ def list_search(self, *args, **kwargs):
des,
des.lower(),
self.format_name(des),
self.get_translation(des),
self.get_translation(des, viid=v.get('value', -1)),
]
for d in dls:
if d not in args:
Expand Down

0 comments on commit 466c9df

Please sign in to comment.