def compare(self, old, new): if not old or not new: return Comparator.RESULT_INTERNAL_ERROR, None if not validate_update(old) or not validate_update(new): return Comparator.RESULT_INTERNAL_ERROR, None # if old['state'] != new['state']: # return Comparator.RESULT_STATE_CHANGED, None new_sensors = check_for_new_sensors(old["sensors"], new["sensors"]) if new_sensors: return Comparator.RESULT_NEW_SENSOR, new_sensors missing_sensor = check_for_missing_sensors(old["sensors"], new["sensors"]) if missing_sensor: return Comparator.RESULT_MISSING_SENSOR, missing_sensor updated_sensors = check_for_updated_sensors(old["sensors"], new["sensors"]) if len(updated_sensors) != 0: return Comparator.RESULT_SENSORS_UPDATED, updated_sensors return Comparator.RESULT_EQUALS, None
def test_validate_update_valid(self): update = dict(time=1450656001, state='on', sensors=[]) self.assertTrue(validate_update(update))
def test_validate_update_time_after_2116(self): update = dict(time=4604256001, state='on', sensors=[]) self.assertFalse(validate_update(update))
def test_validate_update_time_before_2016(self): update = dict(time=1350656000, state='on', sensors=[]) self.assertFalse(validate_update(update))
def test_validate_update_time_not_int(self): update = dict(time=1450656000.123, state='on', sensors=[]) self.assertFalse(validate_update(update))
def test_validate_update_no_time(self): update = dict() self.assertFalse(validate_update(update))