async def prepare(self): self.name = self.app['config']['name'] self.interval = self.app['config']['broadcast_interval'] self.topic = self.app['config']['history_topic'] + '/plaato' if self.interval <= 0: raise repeater.RepeaterCancelled() token = getenv(AUTH_ENV_KEY) if token is None: raise KeyError(f'Plaato auth token not added as env variable (key={AUTH_ENV_KEY})') self.urls = [f'http://plaato.blynk.cc/{token}/get/{pin}' for pin in PINS]
async def prepare(self): """ This function must be implemented by child classes of RepeaterFeature. It is called once after the service started. """ LOGGER.info(f'Starting {self}') # Get values from config # Name is added by the brewblox-service arguments # poll_interval and history_exchange are added in __main__.create_parser() self.name = self.app['config']['name'] self.interval = self.app['config']['poll_interval'] self.exchange = self.app['config']['history_exchange'] # You can prematurely exit here. # Raise RepeaterCancelled(), and the base class will stop without a fuss. # run() will not be called. if self.interval <= 0: raise repeater.RepeaterCancelled()
async def login(self) -> None: login_page = await self.session.get(SHARE_MY_COOK) login_response = await self.session.post( f'{SHARE_MY_COOK}/Login', data={ 'Username': self.username, 'Password': self.password, '__RequestVerificationToken': get_csrf_token(bs_ify(await login_page.text())), }) if login_response.history and login_response.history[0].status == 302: LOGGER.info( f'Successfully logged in {self.username} to {SHARE_MY_COOK}') return LOGGER.error( f'Unable to login with {self.username}/{"*" * len(self.password)}') raise repeater.RepeaterCancelled()
async def prepare(self): self._changed_event = asyncio.Event() if self._volatile: LOGGER.info(f'{self} is volatile (will not read/write datastore)') raise repeater.RepeaterCancelled()
async def prepare(self): if self.volatile: raise repeater.RepeaterCancelled()
def glean_temperature_units(soup: BeautifulSoup) -> str: _input = soup.find(id='TemperatureUnit', checked='checked') if _input: return _input.get('value') raise repeater.RepeaterCancelled('Unable to identify temperature units')
def get_csrf_token(soup: BeautifulSoup) -> str: login_form = get_login_form(soup) for _input in login_form.find_all('input'): if _input.get('name') == '__RequestVerificationToken': return _input.get('value') raise repeater.RepeaterCancelled('Unable to discover CSRF token')
def get_login_form(soup: BeautifulSoup) -> BeautifulSoup: for form in soup.find_all('form'): if form.get('action') == '/Login': return form raise repeater.RepeaterCancelled('Unable to discover login form')