def test_should_return_true_for_bulb_if_desired_brightness_matches_actual_brightness(self): brightness = 0.4 bulb_state = { 'desired_state': { 'brightness': brightness }, 'last_reading': { 'brightness': brightness } } self.assertTrue(is_desired_state_reached(bulb_state))
def _update_state_from_response(self, response_json, require_desired_state_fulfilled=False): """ :param response_json: the json obj returned from query :return: """ _response_json = response_json.get('data') if _response_json and require_desired_state_fulfilled: if not is_desired_state_reached(_response_json): return False self.json_state = _response_json return True
def test_should_return_true_for_bulb_if_desired_powered_matches_actual_powered(self): powered = True bulb_state = { 'desired_state': { 'powered': powered }, 'last_reading': { 'powered': powered } } self.assertTrue(is_desired_state_reached(bulb_state))
def test_should_return_true_for_bulb_if_desired_saturation_matches_actual_saturation(self): saturation = 0.5 bulb_state = { 'desired_state': { 'saturation': saturation }, 'last_reading': { 'saturation': saturation } } self.assertTrue(is_desired_state_reached(bulb_state))
def test_should_return_true_for_bulb_if_desired_hue_matches_actual_hue(self): hue = 0.5 bulb_state = { 'desired_state': { 'hue': hue }, 'last_reading': { 'hue': hue } } self.assertTrue(is_desired_state_reached(bulb_state))
def test_should_return_true_if_device_is_disconnected(self): bulb_state = { 'desired_state': { 'powered': True }, 'last_reading': { 'connection': False, 'powered': False } } self.assertTrue(is_desired_state_reached(bulb_state))
def test_should_return_false_for_bulb_if_desired_powered_does_not_match_actual_powered(self): powered_1 = True powered_2 = False bulb_state = { 'desired_state': { 'powered': powered_1 }, 'last_reading': { 'powered': powered_2 } } self.assertFalse(is_desired_state_reached(bulb_state))
def test_should_return_false_for_bulb_if_desired_saturation_does_not_match_actual_saturation(self): saturation_1 = 0.4 saturation_2 = 0.5 bulb_state = { 'desired_state': { 'saturation': saturation_1 }, 'last_reading': { 'saturation': saturation_2 } } self.assertFalse(is_desired_state_reached(bulb_state))
def test_should_return_false_for_bulb_if_desired_hue_does_not_match_actual_hue(self): hue_1 = 0.4 hue_2 = 0.5 bulb_state = { 'desired_state': { 'hue': hue_1 }, 'last_reading': { 'hue': hue_2 } } self.assertFalse(is_desired_state_reached(bulb_state))
def test_should_return_false_for_bulb_if_desired_brightness_does_not_match_actual_brightness(self): brightness_1 = 0.4 brightness_2 = 0.5 bulb_state = { 'desired_state': { 'brightness': brightness_1 }, 'last_reading': { 'brightness': brightness_2 } } self.assertFalse(is_desired_state_reached(bulb_state))
def update_state(self, require_desired_state_fulfilled=False): """ Update state with latest info from Wink API. """ response = self.api_interface.get_device_state(self, id_override=self.parent_id()) power_strip = response.get('data') if require_desired_state_fulfilled: if not is_desired_state_reached(power_strip[0]): return power_strip_reading = power_strip.get('last_reading') outlets = power_strip.get('outlets', power_strip) for outlet in outlets: if outlet.get('outlet_id') == str(self.device_id()): outlet['last_reading']['connection'] = power_strip_reading.get('connection') self.json_state = outlet
def test_should_return_true_for_real_state_which_where_desired_state_is_reached(self): response_dict = ApiResponseJSONLoader('light_bulb_with_desired_state_reached.json').load()['data'] self.assertTrue(is_desired_state_reached(response_dict))