Skip to content

Commit

Permalink
Add back HDMI control
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Jun 7, 2020
1 parent fa358c0 commit dc9a29f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,12 @@ script:

## Звук Яндекс.Станции по HDMI

Больше не поддерживается. Яндекс его поломал! :(
Функция переключения выхода звука находится у Яндекса в бете. И работает **не у всех пользователей** (как повезёт)! Поэтому включается опционально в конфиге:

```yaml
yandex_station:
control_hdmi: true
```

## Несколько TTS в конфиге

Expand Down
5 changes: 5 additions & 0 deletions custom_components/yandex_station/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

CONF_TTS_NAME = 'tts_service_name'
CONF_INTENTS = 'intents'
CONF_HDMI = 'control_hdmi'
CONF_DEBUG = 'debug'

CONFIG_SCHEMA = vol.Schema({
Expand All @@ -30,6 +31,7 @@
vol.Optional(CONF_TOKEN): cv.string,
vol.Optional(CONF_TTS_NAME, default='yandex_station_say'): cv.string,
vol.Optional(CONF_INTENTS): dict,
vol.Optional(CONF_HDMI, default=False): cv.boolean,
vol.Optional(CONF_DEBUG, default=False): cv.boolean,
}, extra=vol.ALLOW_EXTRA),
}, extra=vol.ALLOW_EXTRA)
Expand Down Expand Up @@ -173,6 +175,9 @@ async def found_local_device(info: dict):
'platform': device['platform']}
_LOGGER.debug(f"Инициализация: {info}")

device['hdmi'] = (config[CONF_HDMI] and
device['platform'] == 'yandexstation')

hass.async_create_task(discovery.async_load_platform(
hass, DOMAIN_MP, DOMAIN, device, hass_config))

Expand Down
48 changes: 46 additions & 2 deletions custom_components/yandex_station/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
SUPPORT_VOLUME_SET, SUPPORT_PREVIOUS_TRACK, \
SUPPORT_NEXT_TRACK, SUPPORT_PLAY, SUPPORT_TURN_OFF, \
SUPPORT_VOLUME_STEP, SUPPORT_VOLUME_MUTE, SUPPORT_PLAY_MEDIA, \
SUPPORT_SEEK, SUPPORT_SELECT_SOUND_MODE, SUPPORT_TURN_ON
SUPPORT_SEEK, SUPPORT_SELECT_SOUND_MODE, SUPPORT_TURN_ON, DEVICE_CLASS_TV, \
SUPPORT_SELECT_SOURCE
from homeassistant.const import STATE_PLAYING, STATE_PAUSED, STATE_IDLE
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.util import dt
Expand Down Expand Up @@ -54,7 +55,10 @@
def setup_platform(hass, config, add_entities, discovery_info=None):
if isinstance(discovery_info, dict):
quasar = hass.data[DOMAIN]
add_entities([YandexStation(quasar, discovery_info)])
if discovery_info.get('hdmi'):
add_entities([YandexStationHDMI(quasar, discovery_info)])
else:
add_entities([YandexStation(quasar, discovery_info)])
else:
add_entities([YandexIntents(discovery_info)])

Expand Down Expand Up @@ -439,3 +443,43 @@ async def async_turn_on(self):

async def async_turn_off(self):
pass


SOURCE_STATION = 'Станция'
SOURCE_HDMI = 'HDMI'


# noinspection PyAbstractClass
class YandexStationHDMI(YandexStation):
device_config = None

async def async_added_to_hass(self) -> None:
await super().async_added_to_hass()
self.device_config = await self.quasar.get_device_config(self.device)

@property
def device_class(self) -> Optional[str]:
return DEVICE_CLASS_TV

@property
def supported_features(self):
return super().supported_features | SUPPORT_SELECT_SOURCE

@property
def source(self):
return SOURCE_HDMI if self.device_config.get('hdmiAudio') \
else SOURCE_STATION

@property
def source_list(self):
return [SOURCE_STATION, SOURCE_HDMI]

async def async_select_source(self, source):
if source == SOURCE_STATION:
self.device_config.pop('hdmiAudio', None)
else:
self.device_config['hdmiAudio'] = True

await self.quasar.set_device_config(self.device, self.device_config)

self.async_schedule_update_ha_state()
21 changes: 21 additions & 0 deletions custom_components/yandex_station/yandex_quasar.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,24 @@ async def load_local_speakers(self, token: str):
except:
_LOGGER.exception("Load local speakers")
return None

async def get_device_config(self, device: dict) -> dict:
payload = {'device_id': device['device_id'],
'platform': device['platform']}
r = await self.session.get(
'https://quasar.yandex.ru/get_device_config',
params=payload)
resp = await r.json()
assert resp['status'] == 'ok', resp
return resp['config']

async def set_device_config(self, device: dict, device_config: dict):
_LOGGER.debug(f"Меняем конфиг станции: {device_config}")

payload = {'device_id': device['device_id'],
'platform': device['platform']}
r = await self.session.request(
'post', 'https://quasar.yandex.ru/set_device_config',
params=payload, json=device_config)
resp = await r.json()
assert resp['status'] == 'ok', resp

0 comments on commit dc9a29f

Please sign in to comment.