def test_volume(): """ Test volume functions.""" try: afsapi = AFSAPI(URL, PIN, TIMEOUT) set_power = yield from afsapi.set_power(True) print('Set power succeeded? - %s' % set_power) power = yield from afsapi.get_power() print('Power on: %s' % power) volume = yield from afsapi.get_volume() print('Volume: %s' % volume) set_volume = yield from afsapi.set_volume(3) print('Set volume succeeded? - %s' % set_volume) volume_steps = yield from afsapi.get_volume_steps() print('Volume steps: % s' % volume_steps) mute = yield from afsapi.get_mute() print('Is muted: %s' % mute) power = yield from afsapi.set_power(False) print('Set power succeeded? - %s' % set_power) power = yield from afsapi.get_power() print('Power on: %s' % power) except Exception as e: logging.error(traceback.format_exc())
def test_play(): """ Test play functions.""" try: afsapi = AFSAPI(URL, PIN, TIMEOUT) status = yield from afsapi.get_play_status() print('Status: %s' % status) forward = yield from afsapi.forward() print('Next succeeded? - %s' % forward) rewind = yield from afsapi.rewind() print('Prev succeeded? - %s' % rewind) except Exception as e: logging.error(traceback.format_exc())
async def test_finally_read(): try: api = AFSAPI(URL, PIN, TIMEOUT) await test_reads(api) except Exception: logging.error(traceback.format_exc()) finally: await api.close()
def fs_device(self): """ Create a fresh fsapi session. A new session is created for each request in case someone else connected to the device in between the updates and invalidated the existing session (i.e UNDOK). """ return AFSAPI(self._device_url, self._password)
async def test_set_play(): async with AFSAPI(URL, PIN, TIMEOUT) as api: try: status = await api.get_play_status() print(f'Status: {status}') forward = await api.forward() print(f'Next succeeded? - {forward}') await asyncio.sleep(5) rewind = await api.rewind() print(f'Prev succeeded? - {rewind}') except Exception: logging.error(traceback.format_exc())
async def async_setup_platform( hass: HomeAssistant, config: ConfigType, async_add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the Frontier Silicon platform.""" if discovery_info is not None: webfsapi_url = await AFSAPI.get_webfsapi_endpoint( discovery_info["ssdp_description"] ) afsapi = AFSAPI(webfsapi_url, DEFAULT_PIN) name = await afsapi.get_friendly_name() async_add_entities( [AFSAPIDevice(name, afsapi)], True, ) return host = config.get(CONF_HOST) port = config.get(CONF_PORT) password = config.get(CONF_PASSWORD) name = config.get(CONF_NAME) try: webfsapi_url = await AFSAPI.get_webfsapi_endpoint( f"http://{host}:{port}/device" ) except FSConnectionError: _LOGGER.error( "Could not add the FSAPI device at %s:%s -> %s", host, port, password ) return afsapi = AFSAPI(webfsapi_url, password) async_add_entities([AFSAPIDevice(name, afsapi)], True)
def test_info(): """ Test info functions.""" try: afsapi = AFSAPI(URL, PIN, TIMEOUT) set_power = yield from afsapi.set_power(True) print('Set power succeeded? - %s' % set_power) power = yield from afsapi.get_power() print('Power on: %s' % power) name = yield from afsapi.get_play_name() print('Name: %s' % name) text = yield from afsapi.get_play_text() print('Text: %s' % text) artist = yield from afsapi.get_play_artist() print('Artist: %s' % artist) album = yield from afsapi.get_play_album() print('Album: %s' % album) graphic = yield from afsapi.get_play_graphic() print('Graphic: %s' % graphic) duration = yield from afsapi.get_play_duration() print('Duration: %s' % duration) power = yield from afsapi.set_power(False) print('Set power succeeded? - %s' % set_power) power = yield from afsapi.get_power() print('Power on: %s' % power) except Exception as e: logging.error(traceback.format_exc())
def test_sys(): """ Test sys functions.""" try: afsapi = AFSAPI(URL, PIN, TIMEOUT) set_power = yield from afsapi.set_power(True) print('Set power succeeded? - %s' % set_power) power = yield from afsapi.get_power() print('Power on: %s' % power) end_point = yield from afsapi.get_fsapi_endpoint() print('Endpoint: %s' % end_point) set_friendly_name = yield from afsapi.set_friendly_name('Badezimmer') print('Set friendly name? - %s' % set_friendly_name) friendly_name = yield from afsapi.get_friendly_name() print('Friendly name: %s' % friendly_name) modes = yield from afsapi.get_modes() print('Modes: %s' % modes) mode_list = yield from afsapi.get_mode_list() print('Mode List: %s' % mode_list) equalisers = yield from afsapi.get_equalisers() print('Equaliser: %s' % equalisers) equaliser_list = yield from afsapi.get_equaliser_list() print('Equaliser List: %s' % equaliser_list) mode = yield from afsapi.get_mode() print('Mode: %s' % mode) power = yield from afsapi.set_power(False) print('Set power succeeded? - %s' % set_power) set_sleep = yield from afsapi.set_sleep(10) print('Set sleep succeeded? - %s' % set_sleep) sleep = yield from afsapi.get_sleep() print('Sleep: %s' % sleep) power = yield from afsapi.get_power() print('Power on: %s' % power) except Exception as e: logging.error(traceback.format_exc())
async def test_with_read(): async with AFSAPI(URL, PIN, TIMEOUT) as api: try: await test_reads(api) except Exception: logging.error(traceback.format_exc())