def __init__(self, app: web.Application): super().__init__(app) self.codec = codec.fget(app) self.commander = commander.fget(app) self.service_store = service_store.fget(self.app) self.global_store = global_store.fget(self.app) self.block_store = block_store.fget(self.app)
async def set_display_settings(self): if not service_status.desc(self.app).is_acknowledged: return store = global_store.fget(self.app) controller = spark.fget(self.app) write_required = False display_block = await controller.read_object({ 'nid': const.DISPLAY_SETTINGS_NID }) user_unit = store.units['temperature'] expected_unit = 'TEMP_FAHRENHEIT' if user_unit == 'degF' else 'TEMP_CELSIUS' block_unit = display_block['data']['tempUnit'] if expected_unit != block_unit: write_required = True display_block['data']['tempUnit'] = expected_unit LOGGER.info(f'Spark display temperature unit set to {user_unit}') user_tz_name = store.time_zone['name'] user_tz = store.time_zone['posixValue'] block_tz = display_block['data']['timeZone'] if user_tz != block_tz: write_required = True display_block['data']['timeZone'] = user_tz LOGGER.info(f'Spark display time zone set to {user_tz} ({user_tz_name})') if write_required: await controller.write_object(display_block)
async def test_on_global_store_change(app, client, syncher): # Update during runtime await syncher.run() global_store.fget(app).units['temperature'] = 'degF' await syncher.on_global_store_change() # Should safely handle disconnected state await disconnect(app) await syncher.on_global_store_change()
async def _sync_datastore(self): _service_store = service_store.fget(self.app) _global_store = global_store.fget(self.app) await datastore.check_remote(self.app) await _service_store.read() await _global_store.read() await self.set_converter_units() with _service_store.open() as config: autoconnect = bool(config.setdefault(AUTOCONNECTING_KEY, True)) service_status.set_autoconnecting(self.app, autoconnect) # Units were moved to global config (2021/04/02) with suppress(KeyError): del config[UNIT_CONFIG_KEY]
async def prepare(self): """Implements RepeaterFeature.prepare""" global_store.fget(self.app).listeners.add(self.on_global_store_change)
def store(app): return global_store.fget(app)
async def set_converter_units(self): store = global_store.fget(self.app) converter = codec.get_converter(self.app) converter.temperature = store.units['temperature'] LOGGER.info(f'Service temperature unit set to {converter.temperature}')