def get_devices(self, site_id: Optional[str] = None, category: Optional[Category] = None) -> List[Device]: site_ids = [s.id for s in self.get_sites() ] if site_id is None else [site_id] devices = [] for site_id in site_ids: r = self._oauth.get(BASE_URL + '/site/' + site_id + "/device") devices += [ Device(d) for d in r.json() if category is None or category.value in Device(d).categories ] return devices
def get_devices(self, site_id: str, category: Optional[Category] = None) -> List[Device]: response = self.get(f"/site/{site_id}/device") try: content = response.json() except JSONDecodeError: response.raise_for_status() devices = [ Device(**d) for d in content if category is None or category.value in Device(**d).categories ] return devices
def get_devices( self, site_id: Optional[str] = None, category: Optional[Category] = None ) -> List[Device]: site_ids = [s.id for s in self.get_sites()] if site_id is None else [site_id] devices = [] # type: List[Device] for s_id in site_ids: r = self.get("/site/" + s_id + "/device") r.raise_for_status() devices += [ Device(**d) for d in r.json() if category is None or category.value in Device(**d).categories ] return devices
def get_devices(self, site_id: Optional[str] = None, category: Optional[Category] = None) -> List[Device]: site_ids = [s.id for s in self.get_sites() ] if site_id is None else [site_id] devices = [] # type: List[Device] for s_id in site_ids: response = self.get(f"/site/{s_id}/device") try: content = response.json() except JSONDecodeError: response.raise_for_status() if response.status_code != 200: # Can happen when the site does not contain any device continue devices += [ Device(**d) for d in content if category is None or category.value in Device(**d).categories ] return devices
def get_device(self, device_id) -> Device: r = self._oauth.get(BASE_URL + '/device/' + device_id) return Device(r.json())
def get_device(self, device_id: str) -> Device: response = self.get(f"/device/{device_id}") response.raise_for_status() return Device(**response.json())
def device(self): api = SomfyApi("foo", "faa", "https://whatever.com") device_path = os.path.join(CURRENT_DIR, "roller_shutter.json") with open(device_path) as get_device: dumb_device = Device(**json.loads(get_device.read())) return SomfyDevice(dumb_device, api)
def setup_method(self): self.api = SomfyApi('foo', 'faa', 'https://whatever.com') device_path = os.path.join(CURRENT_DIR, 'get_device.json') with open(device_path, 'r') as get_device: self.dumb_device = Device(json.loads(get_device.read())) self.somfy_device = SomfyDevice(self.dumb_device, self.api)
def device(self): api = SomfyApi("foo", "faa", "https://whatever.com") device_path = os.path.join(CURRENT_DIR, "camera.json") with open(device_path, "r") as get_device: device = Device(**json.loads(get_device.read())) return CameraProtect(device, api)
def get_device(self, device_id: str) -> Device: r = self.get('/device/' + device_id) r.raise_for_status() return Device(r.json())
def get_device(self, device_id: str) -> Device: r = self._oauth.get(BASE_URL + '/device/' + device_id) r.raise_for_status() return Device(r.json())
def device(self): api = SomfyApi("foo", "faa", "https://whatever.com") device_path = os.path.join(CURRENT_DIR, "hvac.json") with open(device_path) as get_device: device = Device(**json.loads(get_device.read())) return Thermostat(device, api)