Skip to content

Commit

Permalink
📺 improve for mitv (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Jan 6, 2022
1 parent 844f85a commit 514feb8
Showing 1 changed file with 36 additions and 29 deletions.
65 changes: 36 additions & 29 deletions custom_components/xiaomi_miot/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,35 +394,7 @@ async def async_added_to_hass(self):
'select_option': self.press_key,
})
add_selects([self._subs[sub]], update_before_add=False)

if self._state_attrs.get('6095_state', True):
pms = {
'action': 'getinstalledapp',
'count': 999,
'changeIcon': 1,
}
rdt = await self.async_request_mitv_api('controller', params=pms)
if lst := rdt.get('AppInfo', []):
ias = {
a.get('PackageName'): a.get('AppName')
for a in lst
}
als = [
f'{v} - {k}'
for k, v in ias.items()
]
add_selects = self._add_entities.get('select')
sub = 'apps'
if sub in self._subs:
self._subs[sub].update_options(als)
self._subs[sub].update()
elif add_selects:
from .select import SelectSubEntity
self._subs[sub] = SelectSubEntity(self, 'app_current', option={
'options': als,
'select_option': self.start_app,
})
add_selects([self._subs[sub]], update_before_add=False)
await self.async_update_apps()

async def async_update(self):
await super().async_update()
Expand All @@ -433,6 +405,7 @@ async def async_update(self):
'action': 'capturescreen',
'compressrate': 100,
})
prev_6095 = self._state_attrs.get('6095_state')
rdt = await self.async_request_mitv_api('controller', params=pms)
if 'url' in rdt:
url = rdt.get('url', '')
Expand All @@ -451,6 +424,40 @@ async def async_update(self):
})
self._state_attrs.update(adt)

if prev_6095 != self._state_attrs.get('6095_state'):
await self.async_update_apps()

async def async_update_apps(self):
if not self._state_attrs.get('6095_state', True):
return
pms = {
'action': 'getinstalledapp',
'count': 999,
'changeIcon': 1,
}
rdt = await self.async_request_mitv_api('controller', params=pms)
if lst := rdt.get('AppInfo', []):
ias = {
a.get('PackageName'): a.get('AppName')
for a in lst
}
als = [
f'{v} - {k}'
for k, v in ias.items()
]
add_selects = self._add_entities.get('select')
sub = 'apps'
if sub in self._subs:
self._subs[sub].update_options(als)
self._subs[sub].update()
elif add_selects:
from .select import SelectSubEntity
self._subs[sub] = SelectSubEntity(self, 'app_current', option={
'options': als,
'select_option': self.start_app,
})
add_selects([self._subs[sub]], update_before_add=False)

@property
def state(self):
sta = super().state
Expand Down

0 comments on commit 514feb8

Please sign in to comment.