def test_armed_night_with_specific_pending(self): """Test arm home method.""" assert setup_component( self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': { 'platform': 'manual', 'name': 'test', 'pending_time': 10, 'armed_night': { 'pending_time': 2 } }}) entity_id = 'alarm_control_panel.test' common.alarm_arm_night(self.hass) self.hass.block_till_done() assert STATE_ALARM_PENDING == \ self.hass.states.get(entity_id).state future = dt_util.utcnow() + timedelta(seconds=2) with patch(('homeassistant.components.alarm_control_panel.manual.' 'dt_util.utcnow'), return_value=future): fire_time_changed(self.hass, future) self.hass.block_till_done() assert STATE_ALARM_ARMED_NIGHT == \ self.hass.states.get(entity_id).state
def test_arm_night_publishes_mqtt(self): """Test publishing of MQTT messages while armed.""" assert setup_component(self.hass, alarm_control_panel.DOMAIN, { alarm_control_panel.DOMAIN: { 'platform': 'mqtt', 'name': 'test', 'state_topic': 'alarm/state', 'command_topic': 'alarm/command', } }) common.alarm_arm_night(self.hass) self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'alarm/command', 'ARM_NIGHT', 0, False)
def test_arm_night_not_publishes_mqtt_with_invalid_code(self): """Test not publishing of MQTT messages with invalid code.""" assert setup_component(self.hass, alarm_control_panel.DOMAIN, { alarm_control_panel.DOMAIN: { 'platform': 'mqtt', 'name': 'test', 'state_topic': 'alarm/state', 'command_topic': 'alarm/command', 'code': '1234' } }) call_count = self.mock_publish.call_count common.alarm_arm_night(self.hass, 'abcd') self.hass.block_till_done() assert call_count == self.mock_publish.call_count
def test_arm_night_with_pending(self): """Test arm night method.""" assert setup_component( self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': { 'platform': 'manual', 'name': 'test', 'code': CODE, 'pending_time': 1, 'disarm_after_trigger': False }}) entity_id = 'alarm_control_panel.test' assert STATE_ALARM_DISARMED == \ self.hass.states.get(entity_id).state common.alarm_arm_night(self.hass, CODE, entity_id) self.hass.block_till_done() assert STATE_ALARM_PENDING == \ self.hass.states.get(entity_id).state state = self.hass.states.get(entity_id) assert state.attributes['post_pending_state'] == \ STATE_ALARM_ARMED_NIGHT future = dt_util.utcnow() + timedelta(seconds=1) with patch(('homeassistant.components.alarm_control_panel.manual.' 'dt_util.utcnow'), return_value=future): fire_time_changed(self.hass, future) self.hass.block_till_done() state = self.hass.states.get(entity_id) assert state.state == STATE_ALARM_ARMED_NIGHT # Do not go to the pending state when updating to the same state common.alarm_arm_night(self.hass, CODE, entity_id) self.hass.block_till_done() assert STATE_ALARM_ARMED_NIGHT == \ self.hass.states.get(entity_id).state
def test_arm_night_publishes_mqtt_when_code_not_req(self): """Test publishing of MQTT messages. When code_arm_required = False """ assert setup_component(self.hass, alarm_control_panel.DOMAIN, { alarm_control_panel.DOMAIN: { 'platform': 'mqtt', 'name': 'test', 'state_topic': 'alarm/state', 'command_topic': 'alarm/command', 'code': '1234', 'code_arm_required': False } }) common.alarm_arm_night(self.hass) self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'alarm/command', 'ARM_NIGHT', 0, False)
def test_arm_night_publishes_mqtt_when_code_not_req(self): """Test publishing of MQTT messages. When code_arm_required = False """ assert setup_component(self.hass, alarm_control_panel.DOMAIN, { alarm_control_panel.DOMAIN: { 'platform': 'mqtt', 'name': 'test', 'state_topic': 'alarm/state', 'command_topic': 'alarm/command', 'code': '1234', 'code_arm_required': False } }) common.alarm_arm_night(self.hass) self.hass.block_till_done() self.mock_publish.async_publish.assert_called_once_with( 'alarm/command', 'ARM_NIGHT', 0, False)
def test_arm_night_with_invalid_code(self): """Attempt to night home without a valid code.""" assert setup_component( self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': { 'platform': 'manual', 'name': 'test', 'code': CODE, 'pending_time': 1, 'disarm_after_trigger': False }}) entity_id = 'alarm_control_panel.test' assert STATE_ALARM_DISARMED == \ self.hass.states.get(entity_id).state common.alarm_arm_night(self.hass, CODE + '2') self.hass.block_till_done() assert STATE_ALARM_DISARMED == \ self.hass.states.get(entity_id).state
def test_arm_night_no_pending(self): """Test arm night method.""" assert setup_component( self.hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': { 'platform': 'manual', 'name': 'test', 'code': CODE, 'pending_time': 0, 'disarm_after_trigger': False }}) entity_id = 'alarm_control_panel.test' assert STATE_ALARM_DISARMED == \ self.hass.states.get(entity_id).state common.alarm_arm_night(self.hass, CODE) self.hass.block_till_done() assert STATE_ALARM_ARMED_NIGHT == \ self.hass.states.get(entity_id).state