def __init__(self, name, resource): """Initialize the myStrom switch.""" from pymystrom import MyStromPlug self._name = name self._resource = resource self.data = {} self.plug = MyStromPlug(self._resource) self.update()
def setup_platform(hass, config, add_devices, discovery_info=None): """Find and return myStrom switch.""" from pymystrom import MyStromPlug, exceptions host = config.get(CONF_HOST) try: MyStromPlug(host).get_status() except exceptions.MyStromConnectionError: _LOGGER.error("No route to device '%s'", host) return False add_devices([MyStromSwitch(config.get('name', DEFAULT_NAME), host)])