def test_list_devices(self, mocked_login, mocked_list_devices): dyson_account = DysonAccount("email", "password", "language") dyson_account.login() self.assertEqual(mocked_login.call_count, 1) self.assertTrue(dyson_account.logged) devices = dyson_account.devices() self.assertEqual(mocked_list_devices.call_count, 2) self.assertEqual(len(devices), 6) self.assertTrue(isinstance(devices[0], DysonPureCoolLink)) self.assertTrue(isinstance(devices[1], DysonPureHotCoolLink)) self.assertTrue(isinstance(devices[2], Dyson360Eye)) self.assertTrue(devices[0].active) self.assertTrue(devices[0].auto_update) self.assertFalse(devices[0].new_version_available) self.assertEqual(devices[0].serial, 'device-id-1') self.assertEqual(devices[0].name, 'device-1') self.assertEqual(devices[0].version, '21.03.08') self.assertEqual(devices[0].product_type, '475') self.assertEqual(devices[0].credentials, 'password1')
class Controller(polyinterface.Controller): def __init__(self, polyglot): super().__init__(polyglot) self.name = 'Dyson Controller' self.address = 'dysonctrl' self.primary = self.address self.dyson = None self.devlist = None def start(self): # LOGGER.setLevel(logging.INFO) LOGGER.info('Started Dyson controller') if 'username' not in self.polyConfig[ 'customParams'] or 'password' not in self.polyConfig[ 'customParams']: LOGGER.error( 'Please specify username and password in the NodeServer configuration parameters' ) return False username = self.polyConfig['customParams']['username'] password = self.polyConfig['customParams']['password'] if 'country' in self.polyConfig['customParams']: country = self.polyConfig['customParams']['country'] else: country = 'US' try: self.dyson = DysonAccount(username, password, country) except Exception as ex: LOGGER.error('ERROR connecting to the Dyson API: {}'.format(ex)) return if 'devlist' in self.polyConfig['customParams']: try: self.devlist = json.loads( self.polyConfig['customParams']['devlist']) except Exception as ex: LOGGER.error('Failed to parse the devlist: {}'.format(ex)) return False logged_in = self.dyson.login() if not logged_in: LOGGER.error('Failed to login to Dyson account') else: self.discover() def stop(self): LOGGER.info('Dyson is stopping') for node in self.nodes: if self.nodes[node].address != self.address: self.nodes[node].stop() def updateInfo(self): pass def query(self): for node in self.nodes: self.nodes[node].reportDrivers() def discover(self, command=None): for dev in self.dyson.devices(): address = dev.serial.replace('-', '').lower()[:14] name = dev.name if not address in self.nodes: if dev.product_type == DYSON_PURE_COOL or dev.product_type == DYSON_PURE_COOL_DESKTOP: LOGGER.info('Adding v2 product: {}, name: {}'.format( dev.product_type, dev.name)) self.addNode( DysonPureFan(self, self.address, address, name, dev)) elif dev.product_type == DYSON_PURE_COOL_LINK_TOUR: LOGGER.info('Adding v1 product: {}, name: {}'.format( dev.product_type, dev.name)) self.addNode( DysonPureFanV1(self, self.address, address, name, dev)) elif dev.product_type == DYSON_PURE_HOT_COOL: LOGGER.info('Adding v2 product: {}, name: {}'.format( dev.product_type, dev.name)) self.addNode( DysonPureHotCool(self, self.address, address, name, dev)) elif dev.product_type == DYSON_PURE_COOL_LINK_TOUR: LOGGER.info('Adding v1 product: {}, name: {}'.format( dev.product_type, dev.name)) self.addNode( DysonPureHotCoolV1(self, self.address, address, name, dev)) else: LOGGER.info( 'Found product type: {}, name: {} but it\'s not yet supported' .format(dev.product_type, dev.name)) id = 'DYSONCTRL' commands = {'DISCOVER': discover} drivers = [{'driver': 'ST', 'value': 1, 'uom': 2}]
def setup(hass, config): """Set up the Dyson parent component.""" _LOGGER.info("Creating new Dyson component") if DYSON_DEVICES not in hass.data: hass.data[DYSON_DEVICES] = [] from libpurecool.dyson import DysonAccount dyson_account = DysonAccount(config[DOMAIN].get(CONF_USERNAME), config[DOMAIN].get(CONF_PASSWORD), config[DOMAIN].get(CONF_LANGUAGE)) logged = dyson_account.login() timeout = config[DOMAIN].get(CONF_TIMEOUT) retry = config[DOMAIN].get(CONF_RETRY) if not logged: _LOGGER.error("Not connected to Dyson account. Unable to add devices") return False _LOGGER.info("Connected to Dyson account") dyson_devices = dyson_account.devices() if CONF_DEVICES in config[DOMAIN] and config[DOMAIN].get(CONF_DEVICES): configured_devices = config[DOMAIN].get(CONF_DEVICES) for device in configured_devices: dyson_device = next( (d for d in dyson_devices if d.serial == device["device_id"]), None) if dyson_device: try: connected = dyson_device.connect(device["device_ip"]) if connected: _LOGGER.info("Connected to device %s", dyson_device) hass.data[DYSON_DEVICES].append(dyson_device) else: _LOGGER.warning("Unable to connect to device %s", dyson_device) except OSError as ose: _LOGGER.error("Unable to connect to device %s: %s", str(dyson_device.network_device), str(ose)) else: _LOGGER.warning("Unable to find device %s in Dyson account", device["device_id"]) else: # Not yet reliable for device in dyson_devices: _LOGGER.info( "Trying to connect to device %s with timeout=%i " "and retry=%i", device, timeout, retry) connected = device.auto_connect(timeout, retry) if connected: _LOGGER.info("Connected to device %s", device) hass.data[DYSON_DEVICES].append(device) else: _LOGGER.warning("Unable to connect to device %s", device) # Start fan/sensors components if hass.data[DYSON_DEVICES]: _LOGGER.debug("Starting sensor/fan components") for platform in DYSON_PLATFORMS: discovery.load_platform(hass, platform, DOMAIN, {}, config) return True
def setup(hass, config): """Set up the Dyson parent component.""" _LOGGER.info("Creating new Dyson component") if DYSON_DEVICES not in hass.data: hass.data[DYSON_DEVICES] = [] from libpurecool.dyson import DysonAccount dyson_account = DysonAccount(config[DOMAIN].get(CONF_USERNAME), config[DOMAIN].get(CONF_PASSWORD), config[DOMAIN].get(CONF_LANGUAGE)) logged = dyson_account.login() timeout = config[DOMAIN].get(CONF_TIMEOUT) retry = config[DOMAIN].get(CONF_RETRY) if not logged: _LOGGER.error("Not connected to Dyson account. Unable to add devices") return False _LOGGER.info("Connected to Dyson account") dyson_devices = dyson_account.devices() if CONF_DEVICES in config[DOMAIN] and config[DOMAIN].get(CONF_DEVICES): configured_devices = config[DOMAIN].get(CONF_DEVICES) for device in configured_devices: dyson_device = next((d for d in dyson_devices if d.serial == device["device_id"]), None) if dyson_device: try: connected = dyson_device.connect(device["device_ip"]) if connected: _LOGGER.info("Connected to device %s", dyson_device) hass.data[DYSON_DEVICES].append(dyson_device) else: _LOGGER.warning("Unable to connect to device %s", dyson_device) except OSError as ose: _LOGGER.error("Unable to connect to device %s: %s", str(dyson_device.network_device), str(ose)) else: _LOGGER.warning( "Unable to find device %s in Dyson account", device["device_id"]) else: # Not yet reliable for device in dyson_devices: _LOGGER.info("Trying to connect to device %s with timeout=%i " "and retry=%i", device, timeout, retry) connected = device.auto_connect(timeout, retry) if connected: _LOGGER.info("Connected to device %s", device) hass.data[DYSON_DEVICES].append(device) else: _LOGGER.warning("Unable to connect to device %s", device) # Start fan/sensors components if hass.data[DYSON_DEVICES]: _LOGGER.debug("Starting sensor/fan components") for platform in DYSON_PLATFORMS: discovery.load_platform(hass, platform, DOMAIN, {}, config) return True
dyson_account = DysonAccount(USER, PASS, LANG) while dyson_account.login() == False: if dyson_account.wait_2fa_start and \ dyson_account.authenticate(): print('authent ok!') if dyson_account.wait_2fa_verify and \ dyson_account.verify(input("Please input token received by mail:")): print('verify ok!') break if dyson_account.wait_2fa_start == False: dyson_account.prune() time.sleep(1) dyson_account.nukeDeviceCache() devices = dyson_account.devices() print(devices) # ip of a pure cool humidify device connected = devices[0].connect('192.168.88.27') device = devices[0] #print("Running tests... Turning on...") #device.turn_on() #wait() print_new_attributes() exit(0) device.disconnect() for i in FanSpeed: print(i, i.value)