def new_device(device_json, abode): """Create new device object for the given type.""" type_tag = device_json.get('type_tag') if not type_tag: raise AbodeException((ERROR.UNABLE_TO_MAP_DEVICE)) generic_type = CONST.get_generic_type(type_tag.lower()) device_json['generic_type'] = generic_type if generic_type == CONST.TYPE_CONNECTIVITY or \ generic_type == CONST.TYPE_MOISTURE or \ generic_type == CONST.TYPE_OPENING or \ generic_type == CONST.TYPE_VIBRATION: return AbodeBinarySensor(device_json, abode) elif generic_type == CONST.TYPE_CAMERA: return AbodeCamera(device_json, abode) elif generic_type == CONST.TYPE_COVER: return AbodeCover(device_json, abode) elif generic_type == CONST.TYPE_LIGHT: return AbodeLight(device_json, abode) elif generic_type == CONST.TYPE_LOCK: return AbodeLock(device_json, abode) elif generic_type == CONST.TYPE_SWITCH: return AbodeSwitch(device_json, abode) elif generic_type == CONST.TYPE_UNKNOWN_SENSOR: return _new_sensor(device_json, abode) return AbodeDevice(device_json, abode)
def tests_invalid_all_device_unregister(self, m): """Tests that invalid devices are not all unregistered.""" # Set up URL's m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok()) m.get(CONST.OAUTH_TOKEN_URL, text=OAUTH_CLAIMS.get_response_ok()) m.post(CONST.LOGOUT_URL, text=LOGOUT.post_response_ok()) m.get(CONST.PANEL_URL, text=PANEL.get_response_ok(mode=CONST.MODE_STANDBY)) m.get(CONST.DEVICES_URL, text=COVER.device(devid=COVER.DEVICE_ID, status=CONST.STATUS_CLOSED, low_battery=False, no_response=False)) # Logout to reset everything self.abode.logout() # Get our device device = self.abode.get_device(COVER.DEVICE_ID) self.assertIsNotNone(device) # Get the event controller events = self.abode.events self.assertIsNotNone(events) # Test that no device returns false self.assertFalse(events.remove_all_device_callbacks(None)) # Create a fake device and attempt to unregister that fake_device = AbodeBinarySensor(json.loads(DOORCONTACT.device()), self.abode) with self.assertRaises(abodepy.AbodeException): events.remove_all_device_callbacks(fake_device)
def _new_sensor(device_json, abode): if any(key in device_json for key in CONST.SENSOR_KEYS): device_json['generic_type'] = CONST.TYPE_SENSOR return AbodeSensor(device_json, abode) version = device_json.get('version', '') # this.version.startsWith('MINIPIR') == true ? 'Occupancy Sensor' # : 'Motion Sensor'; if version.lower().startswith('minipir'): device_json['generic_type'] = CONST.TYPE_OCCUPANCY else: device_json['generic_type'] = CONST.TYPE_MOTION return AbodeBinarySensor(device_json, abode)