def configure_mydevolo(conf: dict) -> Mydevolo: """Configure mydevolo.""" mydevolo = Mydevolo() mydevolo.user = conf[CONF_USERNAME] mydevolo.password = conf[CONF_PASSWORD] mydevolo.url = conf.get(CONF_MYDEVOLO, DEFAULT_MYDEVOLO) return mydevolo
def _mydevolo(conf: dict) -> Mydevolo: """Configure mydevolo.""" mydevolo = Mydevolo() mydevolo.user = conf[CONF_USERNAME] mydevolo.password = conf[CONF_PASSWORD] mydevolo.url = conf[CONF_MYDEVOLO] return mydevolo
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool: """Set up the devolo account from a config entry.""" conf = entry.data hass.data.setdefault(DOMAIN, {}) mydevolo = Mydevolo() mydevolo.user = conf[CONF_USERNAME] mydevolo.password = conf[CONF_PASSWORD] mydevolo.url = conf[CONF_MYDEVOLO] credentials_valid = await hass.async_add_executor_job( mydevolo.credentials_valid) if not credentials_valid: return False if await hass.async_add_executor_job(mydevolo.maintenance): raise ConfigEntryNotReady gateway_ids = await hass.async_add_executor_job(mydevolo.get_gateway_ids) try: zeroconf_instance = await zeroconf.async_get_instance(hass) hass.data[DOMAIN][entry.entry_id] = {"gateways": [], "listener": None} for gateway_id in gateway_ids: hass.data[DOMAIN][entry.entry_id]["gateways"].append( await hass.async_add_executor_job( partial( HomeControl, gateway_id=gateway_id, mydevolo_instance=mydevolo, zeroconf_instance=zeroconf_instance, ))) except (ConnectionError, GatewayOfflineError) as err: raise ConfigEntryNotReady from err for platform in PLATFORMS: hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, platform)) def shutdown(event): for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]: gateway.websocket_disconnect( f"websocket disconnect requested by {EVENT_HOMEASSISTANT_STOP}" ) # Listen when EVENT_HOMEASSISTANT_STOP is fired hass.data[DOMAIN][entry.entry_id]["listener"] = hass.bus.async_listen_once( EVENT_HOMEASSISTANT_STOP, shutdown) return True
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool: """Set up the devolo account from a config entry.""" conf = entry.data hass.data.setdefault(DOMAIN, {}) try: mydevolo = Mydevolo.get_instance() except SyntaxError: mydevolo = Mydevolo() mydevolo.user = conf[CONF_USERNAME] mydevolo.password = conf[CONF_PASSWORD] mydevolo.url = conf[CONF_MYDEVOLO] credentials_valid = await hass.async_add_executor_job( mydevolo.credentials_valid) if not credentials_valid: return False if await hass.async_add_executor_job(mydevolo.maintenance): raise ConfigEntryNotReady gateway_ids = await hass.async_add_executor_job(mydevolo.get_gateway_ids) gateway_id = gateway_ids[0] try: zeroconf_instance = await zeroconf.async_get_instance(hass) hass.data[DOMAIN]["homecontrol"] = await hass.async_add_executor_job( partial( HomeControl, gateway_id=gateway_id, zeroconf_instance=zeroconf_instance, url=conf[CONF_HOMECONTROL], )) except ConnectionError as err: raise ConfigEntryNotReady from err for platform in PLATFORMS: hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, platform)) def shutdown(event): hass.data[DOMAIN]["homecontrol"].websocket_disconnect( f"websocket disconnect requested by {EVENT_HOMEASSISTANT_STOP}") # Listen when EVENT_HOMEASSISTANT_STOP is fired hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, shutdown) return True
async def async_step_user(self, user_input=None): """Handle a flow initiated by the user.""" if self.show_advanced_options: self.data_schema = { vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str, vol.Required(CONF_MYDEVOLO): str, vol.Required(CONF_HOMECONTROL): str, } if user_input is None: return self._show_form(user_input) user = user_input[CONF_USERNAME] password = user_input[CONF_PASSWORD] try: mydevolo = Mydevolo.get_instance() except SyntaxError: mydevolo = Mydevolo() mydevolo.user = user mydevolo.password = password if self.show_advanced_options: mydevolo.url = user_input[CONF_MYDEVOLO] mydevolo.mprm = user_input[CONF_HOMECONTROL] else: mydevolo.url = DEFAULT_MYDEVOLO mydevolo.mprm = DEFAULT_MPRM credentials_valid = await self.hass.async_add_executor_job( mydevolo.credentials_valid) if not credentials_valid: return self._show_form({"base": "invalid_credentials"}) _LOGGER.debug("Credentials valid") gateway_ids = await self.hass.async_add_executor_job( mydevolo.get_gateway_ids) await self.async_set_unique_id(gateway_ids[0]) self._abort_if_unique_id_configured() return self.async_create_entry( title="devolo Home Control", data={ CONF_PASSWORD: password, CONF_USERNAME: user, CONF_MYDEVOLO: mydevolo.url, CONF_HOMECONTROL: mydevolo.mprm, }, )
async def async_step_user(self, user_input=None): """Handle a flow initiated by the user.""" if self.show_advanced_options: self.data_schema = { vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str, vol.Required(CONF_MYDEVOLO, default=DEFAULT_MYDEVOLO): str, } if user_input is None: return self._show_form(user_input) user = user_input[CONF_USERNAME] password = user_input[CONF_PASSWORD] mydevolo = Mydevolo() mydevolo.user = user mydevolo.password = password if self.show_advanced_options: mydevolo.url = user_input[CONF_MYDEVOLO] else: mydevolo.url = DEFAULT_MYDEVOLO credentials_valid = await self.hass.async_add_executor_job( mydevolo.credentials_valid ) if not credentials_valid: return self._show_form({"base": "invalid_auth"}) _LOGGER.debug("Credentials valid") uuid = await self.hass.async_add_executor_job(mydevolo.uuid) await self.async_set_unique_id(uuid) self._abort_if_unique_id_configured() return self.async_create_entry( title="devolo Home Control", data={ CONF_PASSWORD: password, CONF_USERNAME: user, CONF_MYDEVOLO: mydevolo.url, }, )
from devolo_home_control_api.homecontrol import HomeControl from devolo_home_control_api.mydevolo import Mydevolo logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s: %(message)s") user = "******" password = "******" class Subscriber: def __init__(self, name): self.name = name def update(self, message): print(f'{self.name} got message "{message}"') mydevolo = Mydevolo() mydevolo.user = user mydevolo.password = password gateway_id = mydevolo.get_gateway_ids()[0] homecontrol = HomeControl(gateway_id=gateway_id, mydevolo_instance=mydevolo) for device in homecontrol.devices: homecontrol.devices[device].subscriber = Subscriber(device) homecontrol.publisher.register(device, homecontrol.devices[device].subscriber)