def _arm_night(self, code=None): """Arm night synchronous.""" try: ArmingHelper(self._partition).arm_stay_night() except BadResultCodeError as error: raise HomeAssistantError( f"TotalConnect failed to arm night {self._name}.") from error
def _arm_home(self): """Arm home synchronous.""" try: ArmingHelper(self._partition).arm_stay() except BadResultCodeError as error: raise HomeAssistantError( f"TotalConnect failed to arm home {self._name}.") from error
def _disarm(self, code=None): """Disarm synchronous.""" try: ArmingHelper(self._partition).disarm() except BadResultCodeError as error: raise HomeAssistantError( f"TotalConnect failed to disarm {self._name}.") from error
def tests_disarm(self): """Test disarm.""" # first test with no issues client = create_client() location = client.locations[self.location_id] responses = [ RESPONSE_ARM_SUCCESS, RESPONSE_ARMED_AWAY, RESPONSE_DISARM_SUCCESS, RESPONSE_DISARMED, ] with patch(TCC_REQUEST_METHOD, side_effect=responses): # arm the system and confirm armed_away ArmingHelper(location).arm_away() location.get_panel_meta_data() assert location.arming_state.is_armed_away() # now disarm ArmingHelper(location).disarm() location.get_panel_meta_data() assert location.arming_state.is_disarmed()
def tests_disarm_user_code_invalid(self): """Test disarm with invalid user code.""" client = create_client() location = client.locations[self.location_id] responses = [ RESPONSE_ARM_SUCCESS, RESPONSE_ARMED_AWAY, RESPONSE_USER_CODE_INVALID, RESPONSE_ARMED_AWAY, ] with patch(TCC_REQUEST_METHOD, side_effect=responses): # arm the system and confirm armed_away ArmingHelper(location).arm_away() location.get_panel_meta_data() assert location.arming_state.is_armed_away() with pytest.raises(UsercodeInvalid): ArmingHelper(location).disarm() # should still be armed_away when disarming fails location.get_panel_meta_data() assert location.arming_state.is_armed_away()
def tests_disarm_disarmed(self): """Test attempt to disarm an already disarmed system.""" # Did this once on my Lynx 7000 and it gave result code SUCCESS client = create_client() location = client.locations[self.location_id] responses = [RESPONSE_DISARMED, RESPONSE_SUCCESS, RESPONSE_DISARMED] with patch(TCC_REQUEST_METHOD, side_effect=responses): location.get_panel_meta_data() assert location.arming_state.is_disarmed() # now disarm ArmingHelper(location).disarm() location.get_panel_meta_data() assert location.arming_state.is_disarmed()
def tests_disarm_command_failed(self): """Test disarm with command failed.""" # first test with no issues client = create_client() location = client.locations[self.location_id] responses = [ RESPONSE_ARM_SUCCESS, RESPONSE_ARMED_AWAY, RESPONSE_DISARM_FAILED, RESPONSE_ARMED_AWAY, ] with patch(TCC_REQUEST_METHOD, side_effect=responses): # arm the system and confirm armed_away ArmingHelper(location).arm_away() location.get_panel_meta_data() assert location.arming_state.is_armed_away() # now disarm, should fail with pytest.raises(BadResultCodeError): ArmingHelper(location).disarm() # should still be armed_away location.get_panel_meta_data() assert location.arming_state.is_armed_away()
def _arm_away_instant(self, code=None): """Arm away instant synchronous.""" ArmingHelper(self._partition).arm_away_instant()
def _arm_home_instant(self): """Arm home instant synchronous.""" ArmingHelper(self._partition).arm_stay_instant()
def _arm_night(self, code=None): """Arm night synchronous.""" ArmingHelper(self._partition).arm_stay_night()
def _arm_away(self, code=None): """Arm away synchronous.""" ArmingHelper(self._partition).arm_away()
def _arm_home(self): """Arm home synchronous.""" ArmingHelper(self._partition).arm_stay()
def _disarm(self, code=None): """Disarm synchronous.""" ArmingHelper(self._partition).disarm()
def tests_arm(self): def run(error, responses, armit, armingstate): client = create_client() location = client.locations[self.location_id] with patch(TCC_REQUEST_METHOD, side_effect=responses): if error: with pytest.raises(error): armit(location) else: armit(location) location.get_panel_meta_data() assert location.arming_state == armingstate def runall(success_response, armit, success_armingstate): # first test is all good run( None, [RESPONSE_ARM_SUCCESS, success_response], armit, success_armingstate, ) for failresponse in ( RESPONSE_ARM_FAILED, # "zone faulted" ): run( BadResultCodeError, [failresponse, RESPONSE_DISARMED], armit, ArmingState.DISARMED, ) # last test has 'unavailable' usercode run( UsercodeUnavailable, [RESPONSE_USER_CODE_UNAVAILABLE, RESPONSE_DISARMED], armit, ArmingState.DISARMED, ) runall( RESPONSE_ARMED_AWAY, lambda loc: ArmingHelper(loc).arm_away(), ArmingState.ARMED_AWAY, ) # this test claims to be testing arm away instant but uses the # arm away response runall( RESPONSE_ARMED_AWAY, lambda loc: ArmingHelper(loc).arm_away_instant(), ArmingState.ARMED_AWAY, ) runall( RESPONSE_ARMED_STAY, lambda loc: ArmingHelper(loc).arm_stay(), ArmingState.ARMED_STAY, ) # this test claims to be testing arm stay instant but uses the # arm stay response runall( RESPONSE_ARMED_STAY, lambda loc: ArmingHelper(loc).arm_stay_instant(), ArmingState.ARMED_STAY, ) runall( RESPONSE_ARMED_STAY_NIGHT, lambda loc: ArmingHelper(loc).arm_stay_night(), ArmingState.ARMED_STAY_NIGHT, )