Pytest tests (#17750)
* Convert core tests
* Convert component tests to use pytest assert
* Lint 🤷♂️
* Fix test
* Fix 3 typos in docs
This commit is contained in:
parent
4222f7562b
commit
08fe7c3ece
223 changed files with 6747 additions and 7237 deletions
|
@ -104,7 +104,7 @@ class SetupFlow(data_entry_flow.FlowHandler):
|
||||||
-> Dict[str, Any]:
|
-> Dict[str, Any]:
|
||||||
"""Handle the first step of setup flow.
|
"""Handle the first step of setup flow.
|
||||||
|
|
||||||
Return self.async_show_form(step_id='init') if user_input == None.
|
Return self.async_show_form(step_id='init') if user_input is None.
|
||||||
Return self.async_create_entry(data={'result': result}) if finish.
|
Return self.async_create_entry(data={'result': result}) if finish.
|
||||||
"""
|
"""
|
||||||
errors = {} # type: Dict[str, str]
|
errors = {} # type: Dict[str, str]
|
||||||
|
|
|
@ -176,7 +176,7 @@ class TotpSetupFlow(SetupFlow):
|
||||||
-> Dict[str, Any]:
|
-> Dict[str, Any]:
|
||||||
"""Handle the first step of setup flow.
|
"""Handle the first step of setup flow.
|
||||||
|
|
||||||
Return self.async_show_form(step_id='init') if user_input == None.
|
Return self.async_show_form(step_id='init') if user_input is None.
|
||||||
Return self.async_create_entry(data={'result': result}) if finish.
|
Return self.async_create_entry(data={'result': result}) if finish.
|
||||||
"""
|
"""
|
||||||
import pyotp
|
import pyotp
|
||||||
|
|
|
@ -179,7 +179,7 @@ class LoginFlow(data_entry_flow.FlowHandler):
|
||||||
-> Dict[str, Any]:
|
-> Dict[str, Any]:
|
||||||
"""Handle the first step of login flow.
|
"""Handle the first step of login flow.
|
||||||
|
|
||||||
Return self.async_show_form(step_id='init') if user_input == None.
|
Return self.async_show_form(step_id='init') if user_input is None.
|
||||||
Return await self.async_finish(flow_result) if login init step pass.
|
Return await self.async_finish(flow_result) if login init step pass.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -65,15 +65,15 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
||||||
|
|
||||||
entity_id = 'alarm_control_panel.test'
|
entity_id = 'alarm_control_panel.test'
|
||||||
|
|
||||||
self.assertEqual(STATE_UNKNOWN,
|
assert STATE_UNKNOWN == \
|
||||||
self.hass.states.get(entity_id).state)
|
self.hass.states.get(entity_id).state
|
||||||
|
|
||||||
for state in (STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME,
|
for state in (STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME,
|
||||||
STATE_ALARM_ARMED_AWAY, STATE_ALARM_PENDING,
|
STATE_ALARM_ARMED_AWAY, STATE_ALARM_PENDING,
|
||||||
STATE_ALARM_TRIGGERED):
|
STATE_ALARM_TRIGGERED):
|
||||||
fire_mqtt_message(self.hass, 'alarm/state', state)
|
fire_mqtt_message(self.hass, 'alarm/state', state)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(state, self.hass.states.get(entity_id).state)
|
assert state == self.hass.states.get(entity_id).state
|
||||||
|
|
||||||
def test_ignore_update_state_if_unknown_via_state_topic(self):
|
def test_ignore_update_state_if_unknown_via_state_topic(self):
|
||||||
"""Test ignoring updates via state topic."""
|
"""Test ignoring updates via state topic."""
|
||||||
|
@ -88,12 +88,12 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
||||||
|
|
||||||
entity_id = 'alarm_control_panel.test'
|
entity_id = 'alarm_control_panel.test'
|
||||||
|
|
||||||
self.assertEqual(STATE_UNKNOWN,
|
assert STATE_UNKNOWN == \
|
||||||
self.hass.states.get(entity_id).state)
|
self.hass.states.get(entity_id).state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'alarm/state', 'unsupported state')
|
fire_mqtt_message(self.hass, 'alarm/state', 'unsupported state')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(STATE_UNKNOWN, self.hass.states.get(entity_id).state)
|
assert STATE_UNKNOWN == self.hass.states.get(entity_id).state
|
||||||
|
|
||||||
def test_arm_home_publishes_mqtt(self):
|
def test_arm_home_publishes_mqtt(self):
|
||||||
"""Test publishing of MQTT messages while armed."""
|
"""Test publishing of MQTT messages while armed."""
|
||||||
|
@ -126,7 +126,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
||||||
call_count = self.mock_publish.call_count
|
call_count = self.mock_publish.call_count
|
||||||
common.alarm_arm_home(self.hass, 'abcd')
|
common.alarm_arm_home(self.hass, 'abcd')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(call_count, self.mock_publish.call_count)
|
assert call_count == self.mock_publish.call_count
|
||||||
|
|
||||||
def test_arm_away_publishes_mqtt(self):
|
def test_arm_away_publishes_mqtt(self):
|
||||||
"""Test publishing of MQTT messages while armed."""
|
"""Test publishing of MQTT messages while armed."""
|
||||||
|
@ -159,7 +159,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
||||||
call_count = self.mock_publish.call_count
|
call_count = self.mock_publish.call_count
|
||||||
common.alarm_arm_away(self.hass, 'abcd')
|
common.alarm_arm_away(self.hass, 'abcd')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(call_count, self.mock_publish.call_count)
|
assert call_count == self.mock_publish.call_count
|
||||||
|
|
||||||
def test_disarm_publishes_mqtt(self):
|
def test_disarm_publishes_mqtt(self):
|
||||||
"""Test publishing of MQTT messages while disarmed."""
|
"""Test publishing of MQTT messages while disarmed."""
|
||||||
|
@ -192,7 +192,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
||||||
call_count = self.mock_publish.call_count
|
call_count = self.mock_publish.call_count
|
||||||
common.alarm_disarm(self.hass, 'abcd')
|
common.alarm_disarm(self.hass, 'abcd')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(call_count, self.mock_publish.call_count)
|
assert call_count == self.mock_publish.call_count
|
||||||
|
|
||||||
def test_default_availability_payload(self):
|
def test_default_availability_payload(self):
|
||||||
"""Test availability by default payload with defined topic."""
|
"""Test availability by default payload with defined topic."""
|
||||||
|
@ -208,19 +208,19 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('alarm_control_panel.test')
|
state = self.hass.states.get('alarm_control_panel.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('alarm_control_panel.test')
|
state = self.hass.states.get('alarm_control_panel.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('alarm_control_panel.test')
|
state = self.hass.states.get('alarm_control_panel.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
def test_custom_availability_payload(self):
|
def test_custom_availability_payload(self):
|
||||||
"""Test availability by custom payload with defined topic."""
|
"""Test availability by custom payload with defined topic."""
|
||||||
|
@ -238,7 +238,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('alarm_control_panel.test')
|
state = self.hass.states.get('alarm_control_panel.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ class TestAutomationEvent(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.bus.fire('test_event', context=context)
|
self.hass.bus.fire('test_event', context=context)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
assert self.calls[0].context is context
|
assert self.calls[0].context is context
|
||||||
|
|
||||||
common.turn_off(self.hass)
|
common.turn_off(self.hass)
|
||||||
|
@ -56,7 +56,7 @@ class TestAutomationEvent(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_event_extra_data(self):
|
def test_if_fires_on_event_extra_data(self):
|
||||||
"""Test the firing of events still matches with event data."""
|
"""Test the firing of events still matches with event data."""
|
||||||
|
@ -74,14 +74,14 @@ class TestAutomationEvent(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.bus.fire('test_event', {'extra_key': 'extra_data'})
|
self.hass.bus.fire('test_event', {'extra_key': 'extra_data'})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
common.turn_off(self.hass)
|
common.turn_off(self.hass)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_event_with_data(self):
|
def test_if_fires_on_event_with_data(self):
|
||||||
"""Test the firing of events with data."""
|
"""Test the firing of events with data."""
|
||||||
|
@ -101,7 +101,7 @@ class TestAutomationEvent(unittest.TestCase):
|
||||||
self.hass.bus.fire('test_event', {'some_attr': 'some_value',
|
self.hass.bus.fire('test_event', {'some_attr': 'some_value',
|
||||||
'another': 'value'})
|
'another': 'value'})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_event_with_empty_data_config(self):
|
def test_if_fires_on_event_with_empty_data_config(self):
|
||||||
"""Test the firing of events with empty data config.
|
"""Test the firing of events with empty data config.
|
||||||
|
@ -125,7 +125,7 @@ class TestAutomationEvent(unittest.TestCase):
|
||||||
self.hass.bus.fire('test_event', {'some_attr': 'some_value',
|
self.hass.bus.fire('test_event', {'some_attr': 'some_value',
|
||||||
'another': 'value'})
|
'another': 'value'})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_event_with_nested_data(self):
|
def test_if_fires_on_event_with_nested_data(self):
|
||||||
"""Test the firing of events with nested data."""
|
"""Test the firing of events with nested data."""
|
||||||
|
@ -153,7 +153,7 @@ class TestAutomationEvent(unittest.TestCase):
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_if_event_data_not_matches(self):
|
def test_if_not_fires_if_event_data_not_matches(self):
|
||||||
"""Test firing of event if no match."""
|
"""Test firing of event if no match."""
|
||||||
|
@ -172,4 +172,4 @@ class TestAutomationEvent(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.bus.fire('test_event', {'some_attr': 'some_other_value'})
|
self.hass.bus.fire('test_event', {'some_attr': 'some_other_value'})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
|
@ -75,11 +75,10 @@ class TestAutomationGeoLocation(unittest.TestCase):
|
||||||
}, context=context)
|
}, context=context)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
assert self.calls[0].context is context
|
assert self.calls[0].context is context
|
||||||
self.assertEqual(
|
assert 'geo_location - geo_location.entity - hello - hello - test' == \
|
||||||
'geo_location - geo_location.entity - hello - hello - test',
|
self.calls[0].data['some']
|
||||||
self.calls[0].data['some'])
|
|
||||||
|
|
||||||
# Set out of zone again so we can trigger call
|
# Set out of zone again so we can trigger call
|
||||||
self.hass.states.set('geo_location.entity', 'hello', {
|
self.hass.states.set('geo_location.entity', 'hello', {
|
||||||
|
@ -97,7 +96,7 @@ class TestAutomationGeoLocation(unittest.TestCase):
|
||||||
})
|
})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_for_enter_on_zone_leave(self):
|
def test_if_not_fires_for_enter_on_zone_leave(self):
|
||||||
"""Test for not firing on zone leave."""
|
"""Test for not firing on zone leave."""
|
||||||
|
@ -128,7 +127,7 @@ class TestAutomationGeoLocation(unittest.TestCase):
|
||||||
})
|
})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_zone_leave(self):
|
def test_if_fires_on_zone_leave(self):
|
||||||
"""Test for firing on zone leave."""
|
"""Test for firing on zone leave."""
|
||||||
|
@ -160,7 +159,7 @@ class TestAutomationGeoLocation(unittest.TestCase):
|
||||||
})
|
})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_for_leave_on_zone_enter(self):
|
def test_if_not_fires_for_leave_on_zone_enter(self):
|
||||||
"""Test for not firing on zone enter."""
|
"""Test for not firing on zone enter."""
|
||||||
|
@ -191,7 +190,7 @@ class TestAutomationGeoLocation(unittest.TestCase):
|
||||||
})
|
})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_zone_appear(self):
|
def test_if_fires_on_zone_appear(self):
|
||||||
"""Test for firing if entity appears in zone."""
|
"""Test for firing if entity appears in zone."""
|
||||||
|
@ -225,11 +224,10 @@ class TestAutomationGeoLocation(unittest.TestCase):
|
||||||
}, context=context)
|
}, context=context)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
assert self.calls[0].context is context
|
assert self.calls[0].context is context
|
||||||
self.assertEqual(
|
assert 'geo_location - geo_location.entity - - hello - test' == \
|
||||||
'geo_location - geo_location.entity - - hello - test',
|
self.calls[0].data['some']
|
||||||
self.calls[0].data['some'])
|
|
||||||
|
|
||||||
def test_if_fires_on_zone_disappear(self):
|
def test_if_fires_on_zone_disappear(self):
|
||||||
"""Test for firing if entity disappears from zone."""
|
"""Test for firing if entity disappears from zone."""
|
||||||
|
@ -265,7 +263,6 @@ class TestAutomationGeoLocation(unittest.TestCase):
|
||||||
self.hass.states.async_remove('geo_location.entity')
|
self.hass.states.async_remove('geo_location.entity')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual(
|
assert 'geo_location - geo_location.entity - hello - - test' == \
|
||||||
'geo_location - geo_location.entity - hello - - test',
|
self.calls[0].data['some']
|
||||||
self.calls[0].data['some'])
|
|
||||||
|
|
|
@ -152,9 +152,9 @@ class TestAutomation(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual(['hello.world'],
|
assert ['hello.world'] == \
|
||||||
self.calls[0].data.get(ATTR_ENTITY_ID))
|
self.calls[0].data.get(ATTR_ENTITY_ID)
|
||||||
|
|
||||||
def test_service_specify_entity_id_list(self):
|
def test_service_specify_entity_id_list(self):
|
||||||
"""Test service data."""
|
"""Test service data."""
|
||||||
|
@ -173,9 +173,9 @@ class TestAutomation(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual(['hello.world', 'hello.world2'],
|
assert ['hello.world', 'hello.world2'] == \
|
||||||
self.calls[0].data.get(ATTR_ENTITY_ID))
|
self.calls[0].data.get(ATTR_ENTITY_ID)
|
||||||
|
|
||||||
def test_two_triggers(self):
|
def test_two_triggers(self):
|
||||||
"""Test triggers."""
|
"""Test triggers."""
|
||||||
|
@ -199,10 +199,10 @@ class TestAutomation(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.hass.states.set('test.entity', 'hello')
|
self.hass.states.set('test.entity', 'hello')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(2, len(self.calls))
|
assert 2 == len(self.calls)
|
||||||
|
|
||||||
def test_trigger_service_ignoring_condition(self):
|
def test_trigger_service_ignoring_condition(self):
|
||||||
"""Test triggers."""
|
"""Test triggers."""
|
||||||
|
@ -268,21 +268,21 @@ class TestAutomation(unittest.TestCase):
|
||||||
self.hass.states.set(entity_id, 100)
|
self.hass.states.set(entity_id, 100)
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
self.hass.states.set(entity_id, 101)
|
self.hass.states.set(entity_id, 101)
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
self.hass.states.set(entity_id, 151)
|
self.hass.states.set(entity_id, 151)
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_automation_list_setting(self):
|
def test_automation_list_setting(self):
|
||||||
"""Event is not a valid condition."""
|
"""Event is not a valid condition."""
|
||||||
self.assertTrue(setup_component(self.hass, automation.DOMAIN, {
|
assert setup_component(self.hass, automation.DOMAIN, {
|
||||||
automation.DOMAIN: [{
|
automation.DOMAIN: [{
|
||||||
'trigger': {
|
'trigger': {
|
||||||
'platform': 'event',
|
'platform': 'event',
|
||||||
|
@ -301,19 +301,19 @@ class TestAutomation(unittest.TestCase):
|
||||||
'service': 'test.automation',
|
'service': 'test.automation',
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}))
|
})
|
||||||
|
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
self.hass.bus.fire('test_event_2')
|
self.hass.bus.fire('test_event_2')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(2, len(self.calls))
|
assert 2 == len(self.calls)
|
||||||
|
|
||||||
def test_automation_calling_two_actions(self):
|
def test_automation_calling_two_actions(self):
|
||||||
"""Test if we can call two actions from automation definition."""
|
"""Test if we can call two actions from automation definition."""
|
||||||
self.assertTrue(setup_component(self.hass, automation.DOMAIN, {
|
assert setup_component(self.hass, automation.DOMAIN, {
|
||||||
automation.DOMAIN: {
|
automation.DOMAIN: {
|
||||||
'trigger': {
|
'trigger': {
|
||||||
'platform': 'event',
|
'platform': 'event',
|
||||||
|
@ -328,7 +328,7 @@ class TestAutomation(unittest.TestCase):
|
||||||
'data': {'position': 1},
|
'data': {'position': 1},
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
|
@ -53,15 +53,15 @@ class TestAutomationMQTT(unittest.TestCase):
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test-topic', '{ "hello": "world" }')
|
fire_mqtt_message(self.hass, 'test-topic', '{ "hello": "world" }')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual('mqtt - test-topic - { "hello": "world" } - world',
|
assert 'mqtt - test-topic - { "hello": "world" } - world' == \
|
||||||
self.calls[0].data['some'])
|
self.calls[0].data['some']
|
||||||
|
|
||||||
common.turn_off(self.hass)
|
common.turn_off(self.hass)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
fire_mqtt_message(self.hass, 'test-topic', 'test_payload')
|
fire_mqtt_message(self.hass, 'test-topic', 'test_payload')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_topic_and_payload_match(self):
|
def test_if_fires_on_topic_and_payload_match(self):
|
||||||
"""Test if message is fired on topic and payload match."""
|
"""Test if message is fired on topic and payload match."""
|
||||||
|
@ -80,7 +80,7 @@ class TestAutomationMQTT(unittest.TestCase):
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test-topic', 'hello')
|
fire_mqtt_message(self.hass, 'test-topic', 'hello')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_on_topic_but_no_payload_match(self):
|
def test_if_not_fires_on_topic_but_no_payload_match(self):
|
||||||
"""Test if message is not fired on topic but no payload."""
|
"""Test if message is not fired on topic but no payload."""
|
||||||
|
@ -99,4 +99,4 @@ class TestAutomationMQTT(unittest.TestCase):
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test-topic', 'no-hello')
|
fire_mqtt_message(self.hass, 'test-topic', 'no-hello')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
|
@ -53,7 +53,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 9 is below 10
|
# 9 is below 10
|
||||||
self.hass.states.set('test.entity', 9, context=context)
|
self.hass.states.set('test.entity', 9, context=context)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
assert self.calls[0].context is context
|
assert self.calls[0].context is context
|
||||||
|
|
||||||
# Set above 12 so the automation will fire again
|
# Set above 12 so the automation will fire again
|
||||||
|
@ -62,7 +62,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.hass.states.set('test.entity', 9)
|
self.hass.states.set('test.entity', 9)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_over_to_below(self):
|
def test_if_fires_on_entity_change_over_to_below(self):
|
||||||
"""Test the firing with changed entity."""
|
"""Test the firing with changed entity."""
|
||||||
|
@ -85,7 +85,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 9 is below 10
|
# 9 is below 10
|
||||||
self.hass.states.set('test.entity', 9)
|
self.hass.states.set('test.entity', 9)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entities_change_over_to_below(self):
|
def test_if_fires_on_entities_change_over_to_below(self):
|
||||||
"""Test the firing with changed entities."""
|
"""Test the firing with changed entities."""
|
||||||
|
@ -112,10 +112,10 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 9 is below 10
|
# 9 is below 10
|
||||||
self.hass.states.set('test.entity_1', 9)
|
self.hass.states.set('test.entity_1', 9)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.hass.states.set('test.entity_2', 9)
|
self.hass.states.set('test.entity_2', 9)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(2, len(self.calls))
|
assert 2 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_on_entity_change_below_to_below(self):
|
def test_if_not_fires_on_entity_change_below_to_below(self):
|
||||||
"""Test the firing with changed entity."""
|
"""Test the firing with changed entity."""
|
||||||
|
@ -139,18 +139,18 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 9 is below 10 so this should fire
|
# 9 is below 10 so this should fire
|
||||||
self.hass.states.set('test.entity', 9, context=context)
|
self.hass.states.set('test.entity', 9, context=context)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
assert self.calls[0].context is context
|
assert self.calls[0].context is context
|
||||||
|
|
||||||
# already below so should not fire again
|
# already below so should not fire again
|
||||||
self.hass.states.set('test.entity', 5)
|
self.hass.states.set('test.entity', 5)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
# still below so should not fire again
|
# still below so should not fire again
|
||||||
self.hass.states.set('test.entity', 3)
|
self.hass.states.set('test.entity', 3)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_below_fires_on_entity_change_to_equal(self):
|
def test_if_not_below_fires_on_entity_change_to_equal(self):
|
||||||
"""Test the firing with changed entity."""
|
"""Test the firing with changed entity."""
|
||||||
|
@ -173,7 +173,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 10 is not below 10 so this should not fire again
|
# 10 is not below 10 so this should not fire again
|
||||||
self.hass.states.set('test.entity', 10)
|
self.hass.states.set('test.entity', 10)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_initial_entity_below(self):
|
def test_if_fires_on_initial_entity_below(self):
|
||||||
"""Test the firing when starting with a match."""
|
"""Test the firing when starting with a match."""
|
||||||
|
@ -196,7 +196,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# Fire on first update even if initial state was already below
|
# Fire on first update even if initial state was already below
|
||||||
self.hass.states.set('test.entity', 8)
|
self.hass.states.set('test.entity', 8)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_initial_entity_above(self):
|
def test_if_fires_on_initial_entity_above(self):
|
||||||
"""Test the firing when starting with a match."""
|
"""Test the firing when starting with a match."""
|
||||||
|
@ -219,7 +219,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# Fire on first update even if initial state was already above
|
# Fire on first update even if initial state was already above
|
||||||
self.hass.states.set('test.entity', 12)
|
self.hass.states.set('test.entity', 12)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_above(self):
|
def test_if_fires_on_entity_change_above(self):
|
||||||
"""Test the firing with changed entity."""
|
"""Test the firing with changed entity."""
|
||||||
|
@ -238,7 +238,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 11 is above 10
|
# 11 is above 10
|
||||||
self.hass.states.set('test.entity', 11)
|
self.hass.states.set('test.entity', 11)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_below_to_above(self):
|
def test_if_fires_on_entity_change_below_to_above(self):
|
||||||
"""Test the firing with changed entity."""
|
"""Test the firing with changed entity."""
|
||||||
|
@ -262,7 +262,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 11 is above 10 and 9 is below
|
# 11 is above 10 and 9 is below
|
||||||
self.hass.states.set('test.entity', 11)
|
self.hass.states.set('test.entity', 11)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_on_entity_change_above_to_above(self):
|
def test_if_not_fires_on_entity_change_above_to_above(self):
|
||||||
"""Test the firing with changed entity."""
|
"""Test the firing with changed entity."""
|
||||||
|
@ -286,12 +286,12 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 12 is above 10 so this should fire
|
# 12 is above 10 so this should fire
|
||||||
self.hass.states.set('test.entity', 12)
|
self.hass.states.set('test.entity', 12)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
# already above, should not fire again
|
# already above, should not fire again
|
||||||
self.hass.states.set('test.entity', 15)
|
self.hass.states.set('test.entity', 15)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_above_fires_on_entity_change_to_equal(self):
|
def test_if_not_above_fires_on_entity_change_to_equal(self):
|
||||||
"""Test the firing with changed entity."""
|
"""Test the firing with changed entity."""
|
||||||
|
@ -315,7 +315,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 10 is not above 10 so this should not fire again
|
# 10 is not above 10 so this should not fire again
|
||||||
self.hass.states.set('test.entity', 10)
|
self.hass.states.set('test.entity', 10)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_below_range(self):
|
def test_if_fires_on_entity_change_below_range(self):
|
||||||
"""Test the firing with changed entity."""
|
"""Test the firing with changed entity."""
|
||||||
|
@ -335,7 +335,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 9 is below 10
|
# 9 is below 10
|
||||||
self.hass.states.set('test.entity', 9)
|
self.hass.states.set('test.entity', 9)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_below_above_range(self):
|
def test_if_fires_on_entity_change_below_above_range(self):
|
||||||
"""Test the firing with changed entity."""
|
"""Test the firing with changed entity."""
|
||||||
|
@ -355,7 +355,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 4 is below 5
|
# 4 is below 5
|
||||||
self.hass.states.set('test.entity', 4)
|
self.hass.states.set('test.entity', 4)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_over_to_below_range(self):
|
def test_if_fires_on_entity_change_over_to_below_range(self):
|
||||||
"""Test the firing with changed entity."""
|
"""Test the firing with changed entity."""
|
||||||
|
@ -379,7 +379,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 9 is below 10
|
# 9 is below 10
|
||||||
self.hass.states.set('test.entity', 9)
|
self.hass.states.set('test.entity', 9)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_over_to_below_above_range(self):
|
def test_if_fires_on_entity_change_over_to_below_above_range(self):
|
||||||
"""Test the firing with changed entity."""
|
"""Test the firing with changed entity."""
|
||||||
|
@ -403,7 +403,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 4 is below 5 so it should not fire
|
# 4 is below 5 so it should not fire
|
||||||
self.hass.states.set('test.entity', 4)
|
self.hass.states.set('test.entity', 4)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_if_entity_not_match(self):
|
def test_if_not_fires_if_entity_not_match(self):
|
||||||
"""Test if not fired with non matching entity."""
|
"""Test if not fired with non matching entity."""
|
||||||
|
@ -422,7 +422,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 11)
|
self.hass.states.set('test.entity', 11)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_below_with_attribute(self):
|
def test_if_fires_on_entity_change_below_with_attribute(self):
|
||||||
"""Test attributes change."""
|
"""Test attributes change."""
|
||||||
|
@ -441,7 +441,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 9 is below 10
|
# 9 is below 10
|
||||||
self.hass.states.set('test.entity', 9, {'test_attribute': 11})
|
self.hass.states.set('test.entity', 9, {'test_attribute': 11})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_on_entity_change_not_below_with_attribute(self):
|
def test_if_not_fires_on_entity_change_not_below_with_attribute(self):
|
||||||
"""Test attributes."""
|
"""Test attributes."""
|
||||||
|
@ -460,7 +460,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 11 is not below 10
|
# 11 is not below 10
|
||||||
self.hass.states.set('test.entity', 11, {'test_attribute': 9})
|
self.hass.states.set('test.entity', 11, {'test_attribute': 9})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_attribute_change_with_attribute_below(self):
|
def test_if_fires_on_attribute_change_with_attribute_below(self):
|
||||||
"""Test attributes change."""
|
"""Test attributes change."""
|
||||||
|
@ -480,7 +480,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 9 is below 10
|
# 9 is below 10
|
||||||
self.hass.states.set('test.entity', 'entity', {'test_attribute': 9})
|
self.hass.states.set('test.entity', 'entity', {'test_attribute': 9})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_on_attribute_change_with_attribute_not_below(self):
|
def test_if_not_fires_on_attribute_change_with_attribute_not_below(self):
|
||||||
"""Test attributes change."""
|
"""Test attributes change."""
|
||||||
|
@ -500,7 +500,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 11 is not below 10
|
# 11 is not below 10
|
||||||
self.hass.states.set('test.entity', 'entity', {'test_attribute': 11})
|
self.hass.states.set('test.entity', 'entity', {'test_attribute': 11})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_on_entity_change_with_attribute_below(self):
|
def test_if_not_fires_on_entity_change_with_attribute_below(self):
|
||||||
"""Test attributes change."""
|
"""Test attributes change."""
|
||||||
|
@ -520,7 +520,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 11 is not below 10, entity state value should not be tested
|
# 11 is not below 10, entity state value should not be tested
|
||||||
self.hass.states.set('test.entity', '9', {'test_attribute': 11})
|
self.hass.states.set('test.entity', '9', {'test_attribute': 11})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_on_entity_change_with_not_attribute_below(self):
|
def test_if_not_fires_on_entity_change_with_not_attribute_below(self):
|
||||||
"""Test attributes change."""
|
"""Test attributes change."""
|
||||||
|
@ -540,7 +540,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
# 11 is not below 10, entity state value should not be tested
|
# 11 is not below 10, entity state value should not be tested
|
||||||
self.hass.states.set('test.entity', 'entity')
|
self.hass.states.set('test.entity', 'entity')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_fires_on_attr_change_with_attribute_below_and_multiple_attr(self):
|
def test_fires_on_attr_change_with_attribute_below_and_multiple_attr(self):
|
||||||
"""Test attributes change."""
|
"""Test attributes change."""
|
||||||
|
@ -561,7 +561,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
self.hass.states.set('test.entity', 'entity',
|
self.hass.states.set('test.entity', 'entity',
|
||||||
{'test_attribute': 9, 'not_test_attribute': 11})
|
{'test_attribute': 9, 'not_test_attribute': 11})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_template_list(self):
|
def test_template_list(self):
|
||||||
"""Test template list."""
|
"""Test template list."""
|
||||||
|
@ -583,7 +583,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
self.hass.states.set('test.entity', 'entity',
|
self.hass.states.set('test.entity', 'entity',
|
||||||
{'test_attribute': [11, 15, 3]})
|
{'test_attribute': [11, 15, 3]})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_template_string(self):
|
def test_template_string(self):
|
||||||
"""Test template string."""
|
"""Test template string."""
|
||||||
|
@ -612,11 +612,10 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
self.hass.states.set('test.entity', 'test state 2',
|
self.hass.states.set('test.entity', 'test state 2',
|
||||||
{'test_attribute': '0.9'})
|
{'test_attribute': '0.9'})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual(
|
assert 'numeric_state - test.entity - 10.0 - None - test state 1 - ' \
|
||||||
'numeric_state - test.entity - 10.0 - None - test state 1 - '
|
'test state 2' == \
|
||||||
'test state 2',
|
self.calls[0].data['some']
|
||||||
self.calls[0].data['some'])
|
|
||||||
|
|
||||||
def test_not_fires_on_attr_change_with_attr_not_below_multiple_attr(self):
|
def test_not_fires_on_attr_change_with_attr_not_below_multiple_attr(self):
|
||||||
"""Test if not fired changed attributes."""
|
"""Test if not fired changed attributes."""
|
||||||
|
@ -637,7 +636,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
self.hass.states.set('test.entity', 'entity',
|
self.hass.states.set('test.entity', 'entity',
|
||||||
{'test_attribute': 11, 'not_test_attribute': 9})
|
{'test_attribute': 11, 'not_test_attribute': 9})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_action(self):
|
def test_if_action(self):
|
||||||
"""Test if action."""
|
"""Test if action."""
|
||||||
|
@ -664,19 +663,19 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
self.hass.states.set(entity_id, 8)
|
self.hass.states.set(entity_id, 8)
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
self.hass.states.set(entity_id, 9)
|
self.hass.states.set(entity_id, 9)
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(2, len(self.calls))
|
assert 2 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fails_setup_bad_for(self):
|
def test_if_fails_setup_bad_for(self):
|
||||||
"""Test for setup failure for bad for."""
|
"""Test for setup failure for bad for."""
|
||||||
|
@ -739,7 +738,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_on_entities_change_with_for_after_stop(self):
|
def test_if_not_fires_on_entities_change_with_for_after_stop(self):
|
||||||
"""Test for not firing on entities change with for after stop."""
|
"""Test for not firing on entities change with for after stop."""
|
||||||
|
@ -768,7 +767,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(2, len(self.calls))
|
assert 2 == len(self.calls)
|
||||||
|
|
||||||
self.hass.states.set('test.entity_1', 15)
|
self.hass.states.set('test.entity_1', 15)
|
||||||
self.hass.states.set('test.entity_2', 15)
|
self.hass.states.set('test.entity_2', 15)
|
||||||
|
@ -781,7 +780,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
|
|
||||||
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(2, len(self.calls))
|
assert 2 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_with_for_attribute_change(self):
|
def test_if_fires_on_entity_change_with_for_attribute_change(self):
|
||||||
"""Test for firing on entity change with for and attribute change."""
|
"""Test for firing on entity change with for and attribute change."""
|
||||||
|
@ -812,11 +811,11 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
self.hass.states.set('test.entity', 9,
|
self.hass.states.set('test.entity', 9,
|
||||||
attributes={"mock_attr": "attr_change"})
|
attributes={"mock_attr": "attr_change"})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
mock_utcnow.return_value += timedelta(seconds=4)
|
mock_utcnow.return_value += timedelta(seconds=4)
|
||||||
fire_time_changed(self.hass, mock_utcnow.return_value)
|
fire_time_changed(self.hass, mock_utcnow.return_value)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_with_for(self):
|
def test_if_fires_on_entity_change_with_for(self):
|
||||||
"""Test for firing on entity change with for."""
|
"""Test for firing on entity change with for."""
|
||||||
|
@ -841,7 +840,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_wait_template_with_trigger(self):
|
def test_wait_template_with_trigger(self):
|
||||||
"""Test using wait template with 'trigger.entity_id'."""
|
"""Test using wait template with 'trigger.entity_id'."""
|
||||||
|
@ -872,7 +871,6 @@ class TestAutomationNumericState(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.hass.states.set('test.entity', '8')
|
self.hass.states.set('test.entity', '8')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual(
|
assert 'numeric_state - test.entity - 12' == \
|
||||||
'numeric_state - test.entity - 12',
|
self.calls[0].data['some']
|
||||||
self.calls[0].data['some'])
|
|
||||||
|
|
|
@ -63,17 +63,16 @@ class TestAutomationState(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world', context=context)
|
self.hass.states.set('test.entity', 'world', context=context)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
assert self.calls[0].context is context
|
assert self.calls[0].context is context
|
||||||
self.assertEqual(
|
assert 'state - test.entity - hello - world - None' == \
|
||||||
'state - test.entity - hello - world - None',
|
self.calls[0].data['some']
|
||||||
self.calls[0].data['some'])
|
|
||||||
|
|
||||||
common.turn_off(self.hass)
|
common.turn_off(self.hass)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.hass.states.set('test.entity', 'planet')
|
self.hass.states.set('test.entity', 'planet')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_with_from_filter(self):
|
def test_if_fires_on_entity_change_with_from_filter(self):
|
||||||
"""Test for firing on entity change with filter."""
|
"""Test for firing on entity change with filter."""
|
||||||
|
@ -92,7 +91,7 @@ class TestAutomationState(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_with_to_filter(self):
|
def test_if_fires_on_entity_change_with_to_filter(self):
|
||||||
"""Test for firing on entity change with no filter."""
|
"""Test for firing on entity change with no filter."""
|
||||||
|
@ -111,7 +110,7 @@ class TestAutomationState(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_attribute_change_with_to_filter(self):
|
def test_if_fires_on_attribute_change_with_to_filter(self):
|
||||||
"""Test for not firing on attribute change."""
|
"""Test for not firing on attribute change."""
|
||||||
|
@ -131,7 +130,7 @@ class TestAutomationState(unittest.TestCase):
|
||||||
self.hass.states.set('test.entity', 'world', {'test_attribute': 11})
|
self.hass.states.set('test.entity', 'world', {'test_attribute': 11})
|
||||||
self.hass.states.set('test.entity', 'world', {'test_attribute': 12})
|
self.hass.states.set('test.entity', 'world', {'test_attribute': 12})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_with_both_filters(self):
|
def test_if_fires_on_entity_change_with_both_filters(self):
|
||||||
"""Test for firing if both filters are a non match."""
|
"""Test for firing if both filters are a non match."""
|
||||||
|
@ -151,7 +150,7 @@ class TestAutomationState(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_if_to_filter_not_match(self):
|
def test_if_not_fires_if_to_filter_not_match(self):
|
||||||
"""Test for not firing if to filter is not a match."""
|
"""Test for not firing if to filter is not a match."""
|
||||||
|
@ -171,7 +170,7 @@ class TestAutomationState(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'moon')
|
self.hass.states.set('test.entity', 'moon')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_if_from_filter_not_match(self):
|
def test_if_not_fires_if_from_filter_not_match(self):
|
||||||
"""Test for not firing if from filter is not a match."""
|
"""Test for not firing if from filter is not a match."""
|
||||||
|
@ -193,7 +192,7 @@ class TestAutomationState(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_if_entity_not_match(self):
|
def test_if_not_fires_if_entity_not_match(self):
|
||||||
"""Test for not firing if entity is not matching."""
|
"""Test for not firing if entity is not matching."""
|
||||||
|
@ -211,7 +210,7 @@ class TestAutomationState(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_action(self):
|
def test_if_action(self):
|
||||||
"""Test for to action."""
|
"""Test for to action."""
|
||||||
|
@ -238,13 +237,13 @@ class TestAutomationState(unittest.TestCase):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
self.hass.states.set(entity_id, test_state + 'something')
|
self.hass.states.set(entity_id, test_state + 'something')
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fails_setup_if_to_boolean_value(self):
|
def test_if_fails_setup_if_to_boolean_value(self):
|
||||||
"""Test for setup failure for boolean to."""
|
"""Test for setup failure for boolean to."""
|
||||||
|
@ -335,7 +334,7 @@ class TestAutomationState(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_on_entities_change_with_for_after_stop(self):
|
def test_if_not_fires_on_entities_change_with_for_after_stop(self):
|
||||||
"""Test for not firing on entity change with for after stop trigger."""
|
"""Test for not firing on entity change with for after stop trigger."""
|
||||||
|
@ -363,7 +362,7 @@ class TestAutomationState(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(2, len(self.calls))
|
assert 2 == len(self.calls)
|
||||||
|
|
||||||
self.hass.states.set('test.entity_1', 'world_no')
|
self.hass.states.set('test.entity_1', 'world_no')
|
||||||
self.hass.states.set('test.entity_2', 'world_no')
|
self.hass.states.set('test.entity_2', 'world_no')
|
||||||
|
@ -376,7 +375,7 @@ class TestAutomationState(unittest.TestCase):
|
||||||
|
|
||||||
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(2, len(self.calls))
|
assert 2 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_with_for_attribute_change(self):
|
def test_if_fires_on_entity_change_with_for_attribute_change(self):
|
||||||
"""Test for firing on entity change with for and attribute change."""
|
"""Test for firing on entity change with for and attribute change."""
|
||||||
|
@ -406,11 +405,11 @@ class TestAutomationState(unittest.TestCase):
|
||||||
self.hass.states.set('test.entity', 'world',
|
self.hass.states.set('test.entity', 'world',
|
||||||
attributes={"mock_attr": "attr_change"})
|
attributes={"mock_attr": "attr_change"})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
mock_utcnow.return_value += timedelta(seconds=4)
|
mock_utcnow.return_value += timedelta(seconds=4)
|
||||||
fire_time_changed(self.hass, mock_utcnow.return_value)
|
fire_time_changed(self.hass, mock_utcnow.return_value)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_with_for_multiple_force_update(self):
|
def test_if_fires_on_entity_change_with_for_multiple_force_update(self):
|
||||||
"""Test for firing on entity change with for and force update."""
|
"""Test for firing on entity change with for and force update."""
|
||||||
|
@ -440,11 +439,11 @@ class TestAutomationState(unittest.TestCase):
|
||||||
fire_time_changed(self.hass, mock_utcnow.return_value)
|
fire_time_changed(self.hass, mock_utcnow.return_value)
|
||||||
self.hass.states.set('test.force_entity', 'world', None, True)
|
self.hass.states.set('test.force_entity', 'world', None, True)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
mock_utcnow.return_value += timedelta(seconds=4)
|
mock_utcnow.return_value += timedelta(seconds=4)
|
||||||
fire_time_changed(self.hass, mock_utcnow.return_value)
|
fire_time_changed(self.hass, mock_utcnow.return_value)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_with_for(self):
|
def test_if_fires_on_entity_change_with_for(self):
|
||||||
"""Test for firing on entity change with for."""
|
"""Test for firing on entity change with for."""
|
||||||
|
@ -468,7 +467,7 @@ class TestAutomationState(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_for_condition(self):
|
def test_if_fires_on_for_condition(self):
|
||||||
"""Test for firing if condition is on."""
|
"""Test for firing if condition is on."""
|
||||||
|
@ -498,13 +497,13 @@ class TestAutomationState(unittest.TestCase):
|
||||||
# not enough time has passed
|
# not enough time has passed
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
# Time travel 10 secs into the future
|
# Time travel 10 secs into the future
|
||||||
mock_utcnow.return_value = point2
|
mock_utcnow.return_value = point2
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_for_condition_attribute_change(self):
|
def test_if_fires_on_for_condition_attribute_change(self):
|
||||||
"""Test for firing if condition is on with attribute change."""
|
"""Test for firing if condition is on with attribute change."""
|
||||||
|
@ -535,7 +534,7 @@ class TestAutomationState(unittest.TestCase):
|
||||||
# not enough time has passed
|
# not enough time has passed
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
# Still not enough time has passed, but an attribute is changed
|
# Still not enough time has passed, but an attribute is changed
|
||||||
mock_utcnow.return_value = point2
|
mock_utcnow.return_value = point2
|
||||||
|
@ -543,13 +542,13 @@ class TestAutomationState(unittest.TestCase):
|
||||||
attributes={"mock_attr": "attr_change"})
|
attributes={"mock_attr": "attr_change"})
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
# Enough time has now passed
|
# Enough time has now passed
|
||||||
mock_utcnow.return_value = point3
|
mock_utcnow.return_value = point3
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fails_setup_for_without_time(self):
|
def test_if_fails_setup_for_without_time(self):
|
||||||
"""Test for setup failure if no time is provided."""
|
"""Test for setup failure if no time is provided."""
|
||||||
|
@ -615,7 +614,6 @@ class TestAutomationState(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.hass.states.set('test.entity', 'hello')
|
self.hass.states.set('test.entity', 'hello')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual(
|
assert 'state - test.entity - hello - world' == \
|
||||||
'state - test.entity - hello - world',
|
self.calls[0].data['some']
|
||||||
self.calls[0].data['some'])
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ class TestAutomationSun(unittest.TestCase):
|
||||||
|
|
||||||
fire_time_changed(self.hass, trigger_time)
|
fire_time_changed(self.hass, trigger_time)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
with patch('homeassistant.util.dt.utcnow',
|
with patch('homeassistant.util.dt.utcnow',
|
||||||
return_value=now):
|
return_value=now):
|
||||||
|
@ -72,7 +72,7 @@ class TestAutomationSun(unittest.TestCase):
|
||||||
|
|
||||||
fire_time_changed(self.hass, trigger_time)
|
fire_time_changed(self.hass, trigger_time)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_sunrise_trigger(self):
|
def test_sunrise_trigger(self):
|
||||||
"""Test the sunrise trigger."""
|
"""Test the sunrise trigger."""
|
||||||
|
@ -95,7 +95,7 @@ class TestAutomationSun(unittest.TestCase):
|
||||||
|
|
||||||
fire_time_changed(self.hass, trigger_time)
|
fire_time_changed(self.hass, trigger_time)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_sunset_trigger_with_offset(self):
|
def test_sunset_trigger_with_offset(self):
|
||||||
"""Test the sunset trigger with offset."""
|
"""Test the sunset trigger with offset."""
|
||||||
|
@ -124,8 +124,8 @@ class TestAutomationSun(unittest.TestCase):
|
||||||
|
|
||||||
fire_time_changed(self.hass, trigger_time)
|
fire_time_changed(self.hass, trigger_time)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual('sun - sunset - 0:30:00', self.calls[0].data['some'])
|
assert 'sun - sunset - 0:30:00' == self.calls[0].data['some']
|
||||||
|
|
||||||
def test_sunrise_trigger_with_offset(self):
|
def test_sunrise_trigger_with_offset(self):
|
||||||
"""Test the sunrise trigger with offset."""
|
"""Test the sunrise trigger with offset."""
|
||||||
|
@ -149,7 +149,7 @@ class TestAutomationSun(unittest.TestCase):
|
||||||
|
|
||||||
fire_time_changed(self.hass, trigger_time)
|
fire_time_changed(self.hass, trigger_time)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_action_before(self):
|
def test_if_action_before(self):
|
||||||
"""Test if action was before."""
|
"""Test if action was before."""
|
||||||
|
@ -174,14 +174,14 @@ class TestAutomationSun(unittest.TestCase):
|
||||||
return_value=now):
|
return_value=now):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
now = datetime(2015, 9, 16, 10, tzinfo=dt_util.UTC)
|
now = datetime(2015, 9, 16, 10, tzinfo=dt_util.UTC)
|
||||||
with patch('homeassistant.util.dt.utcnow',
|
with patch('homeassistant.util.dt.utcnow',
|
||||||
return_value=now):
|
return_value=now):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_action_after(self):
|
def test_if_action_after(self):
|
||||||
"""Test if action was after."""
|
"""Test if action was after."""
|
||||||
|
@ -206,14 +206,14 @@ class TestAutomationSun(unittest.TestCase):
|
||||||
return_value=now):
|
return_value=now):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
now = datetime(2015, 9, 16, 15, tzinfo=dt_util.UTC)
|
now = datetime(2015, 9, 16, 15, tzinfo=dt_util.UTC)
|
||||||
with patch('homeassistant.util.dt.utcnow',
|
with patch('homeassistant.util.dt.utcnow',
|
||||||
return_value=now):
|
return_value=now):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_action_before_with_offset(self):
|
def test_if_action_before_with_offset(self):
|
||||||
"""Test if action was before offset."""
|
"""Test if action was before offset."""
|
||||||
|
@ -239,14 +239,14 @@ class TestAutomationSun(unittest.TestCase):
|
||||||
return_value=now):
|
return_value=now):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
now = datetime(2015, 9, 16, 14, 32, 43, tzinfo=dt_util.UTC)
|
now = datetime(2015, 9, 16, 14, 32, 43, tzinfo=dt_util.UTC)
|
||||||
with patch('homeassistant.util.dt.utcnow',
|
with patch('homeassistant.util.dt.utcnow',
|
||||||
return_value=now):
|
return_value=now):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_action_after_with_offset(self):
|
def test_if_action_after_with_offset(self):
|
||||||
"""Test if action was after offset."""
|
"""Test if action was after offset."""
|
||||||
|
@ -272,14 +272,14 @@ class TestAutomationSun(unittest.TestCase):
|
||||||
return_value=now):
|
return_value=now):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
now = datetime(2015, 9, 16, 14, 32, 43, tzinfo=dt_util.UTC)
|
now = datetime(2015, 9, 16, 14, 32, 43, tzinfo=dt_util.UTC)
|
||||||
with patch('homeassistant.util.dt.utcnow',
|
with patch('homeassistant.util.dt.utcnow',
|
||||||
return_value=now):
|
return_value=now):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_action_before_and_after_during(self):
|
def test_if_action_before_and_after_during(self):
|
||||||
"""Test if action was before and after during."""
|
"""Test if action was before and after during."""
|
||||||
|
@ -305,18 +305,18 @@ class TestAutomationSun(unittest.TestCase):
|
||||||
return_value=now):
|
return_value=now):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
now = datetime(2015, 9, 17, 2, 25, 18, tzinfo=dt_util.UTC)
|
now = datetime(2015, 9, 17, 2, 25, 18, tzinfo=dt_util.UTC)
|
||||||
with patch('homeassistant.util.dt.utcnow',
|
with patch('homeassistant.util.dt.utcnow',
|
||||||
return_value=now):
|
return_value=now):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
now = datetime(2015, 9, 16, 16, tzinfo=dt_util.UTC)
|
now = datetime(2015, 9, 16, 16, tzinfo=dt_util.UTC)
|
||||||
with patch('homeassistant.util.dt.utcnow',
|
with patch('homeassistant.util.dt.utcnow',
|
||||||
return_value=now):
|
return_value=now):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
|
@ -48,14 +48,14 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
common.turn_off(self.hass)
|
common.turn_off(self.hass)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'planet')
|
self.hass.states.set('test.entity', 'planet')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_change_str(self):
|
def test_if_fires_on_change_str(self):
|
||||||
"""Test for firing on change."""
|
"""Test for firing on change."""
|
||||||
|
@ -73,7 +73,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_change_str_crazy(self):
|
def test_if_fires_on_change_str_crazy(self):
|
||||||
"""Test for firing on change."""
|
"""Test for firing on change."""
|
||||||
|
@ -91,7 +91,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_on_change_bool(self):
|
def test_if_not_fires_on_change_bool(self):
|
||||||
"""Test for not firing on boolean change."""
|
"""Test for not firing on boolean change."""
|
||||||
|
@ -109,7 +109,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_on_change_str(self):
|
def test_if_not_fires_on_change_str(self):
|
||||||
"""Test for not firing on string change."""
|
"""Test for not firing on string change."""
|
||||||
|
@ -127,7 +127,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_on_change_str_crazy(self):
|
def test_if_not_fires_on_change_str_crazy(self):
|
||||||
"""Test for not firing on string change."""
|
"""Test for not firing on string change."""
|
||||||
|
@ -145,7 +145,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_no_change(self):
|
def test_if_fires_on_no_change(self):
|
||||||
"""Test for firing on no change."""
|
"""Test for firing on no change."""
|
||||||
|
@ -166,7 +166,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'hello')
|
self.hass.states.set('test.entity', 'hello')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_two_change(self):
|
def test_if_fires_on_two_change(self):
|
||||||
"""Test for firing on two changes."""
|
"""Test for firing on two changes."""
|
||||||
|
@ -185,12 +185,12 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||||
# Trigger once
|
# Trigger once
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
# Trigger again
|
# Trigger again
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_change_with_template(self):
|
def test_if_fires_on_change_with_template(self):
|
||||||
"""Test for firing on change with template."""
|
"""Test for firing on change with template."""
|
||||||
|
@ -208,7 +208,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_on_change_with_template(self):
|
def test_if_not_fires_on_change_with_template(self):
|
||||||
"""Test for not firing on change with template."""
|
"""Test for not firing on change with template."""
|
||||||
|
@ -257,11 +257,10 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world', context=context)
|
self.hass.states.set('test.entity', 'world', context=context)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
assert self.calls[0].context is context
|
assert self.calls[0].context is context
|
||||||
self.assertEqual(
|
assert 'template - test.entity - hello - world' == \
|
||||||
'template - test.entity - hello - world',
|
self.calls[0].data['some']
|
||||||
self.calls[0].data['some'])
|
|
||||||
|
|
||||||
def test_if_fires_on_no_change_with_template_advanced(self):
|
def test_if_fires_on_no_change_with_template_advanced(self):
|
||||||
"""Test for firing on no change with template advanced."""
|
"""Test for firing on no change with template advanced."""
|
||||||
|
@ -284,12 +283,12 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||||
# Different state
|
# Different state
|
||||||
self.hass.states.set('test.entity', 'worldz')
|
self.hass.states.set('test.entity', 'worldz')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
# Different state
|
# Different state
|
||||||
self.hass.states.set('test.entity', 'hello')
|
self.hass.states.set('test.entity', 'hello')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_change_with_template_2(self):
|
def test_if_fires_on_change_with_template_2(self):
|
||||||
"""Test for firing on change with template."""
|
"""Test for firing on change with template."""
|
||||||
|
@ -354,17 +353,17 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||||
# Condition is not true yet
|
# Condition is not true yet
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
# Change condition to true, but it shouldn't be triggered yet
|
# Change condition to true, but it shouldn't be triggered yet
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
# Condition is true and event is triggered
|
# Condition is true and event is triggered
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_change_with_bad_template(self):
|
def test_if_fires_on_change_with_bad_template(self):
|
||||||
"""Test for firing on change with bad template."""
|
"""Test for firing on change with bad template."""
|
||||||
|
@ -397,7 +396,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world')
|
self.hass.states.set('test.entity', 'world')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_wait_template_with_trigger(self):
|
def test_wait_template_with_trigger(self):
|
||||||
"""Test using wait template with 'trigger.entity_id'."""
|
"""Test using wait template with 'trigger.entity_id'."""
|
||||||
|
@ -429,7 +428,6 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.hass.states.set('test.entity', 'hello')
|
self.hass.states.set('test.entity', 'hello')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual(
|
assert 'template - test.entity - hello - world' == \
|
||||||
'template - test.entity - hello - world',
|
self.calls[0].data['some']
|
||||||
self.calls[0].data['some'])
|
|
||||||
|
|
|
@ -51,14 +51,14 @@ class TestAutomationTime(unittest.TestCase):
|
||||||
|
|
||||||
fire_time_changed(self.hass, dt_util.utcnow().replace(hour=0))
|
fire_time_changed(self.hass, dt_util.utcnow().replace(hour=0))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
common.turn_off(self.hass)
|
common.turn_off(self.hass)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
fire_time_changed(self.hass, dt_util.utcnow().replace(hour=0))
|
fire_time_changed(self.hass, dt_util.utcnow().replace(hour=0))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_when_minute_matches(self):
|
def test_if_fires_when_minute_matches(self):
|
||||||
"""Test for firing if minutes are matching."""
|
"""Test for firing if minutes are matching."""
|
||||||
|
@ -77,7 +77,7 @@ class TestAutomationTime(unittest.TestCase):
|
||||||
fire_time_changed(self.hass, dt_util.utcnow().replace(minute=0))
|
fire_time_changed(self.hass, dt_util.utcnow().replace(minute=0))
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_when_second_matches(self):
|
def test_if_fires_when_second_matches(self):
|
||||||
"""Test for firing if seconds are matching."""
|
"""Test for firing if seconds are matching."""
|
||||||
|
@ -96,7 +96,7 @@ class TestAutomationTime(unittest.TestCase):
|
||||||
fire_time_changed(self.hass, dt_util.utcnow().replace(second=0))
|
fire_time_changed(self.hass, dt_util.utcnow().replace(second=0))
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_when_all_matches(self):
|
def test_if_fires_when_all_matches(self):
|
||||||
"""Test for firing if everything matches."""
|
"""Test for firing if everything matches."""
|
||||||
|
@ -118,7 +118,7 @@ class TestAutomationTime(unittest.TestCase):
|
||||||
hour=1, minute=2, second=3))
|
hour=1, minute=2, second=3))
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_periodic_seconds(self):
|
def test_if_fires_periodic_seconds(self):
|
||||||
"""Test for firing periodically every second."""
|
"""Test for firing periodically every second."""
|
||||||
|
@ -138,7 +138,7 @@ class TestAutomationTime(unittest.TestCase):
|
||||||
hour=0, minute=0, second=2))
|
hour=0, minute=0, second=2))
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_periodic_minutes(self):
|
def test_if_fires_periodic_minutes(self):
|
||||||
"""Test for firing periodically every minute."""
|
"""Test for firing periodically every minute."""
|
||||||
|
@ -158,7 +158,7 @@ class TestAutomationTime(unittest.TestCase):
|
||||||
hour=0, minute=2, second=0))
|
hour=0, minute=2, second=0))
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_periodic_hours(self):
|
def test_if_fires_periodic_hours(self):
|
||||||
"""Test for firing periodically every hour."""
|
"""Test for firing periodically every hour."""
|
||||||
|
@ -178,7 +178,7 @@ class TestAutomationTime(unittest.TestCase):
|
||||||
hour=2, minute=0, second=0))
|
hour=2, minute=0, second=0))
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_using_at(self):
|
def test_if_fires_using_at(self):
|
||||||
"""Test for firing at."""
|
"""Test for firing at."""
|
||||||
|
@ -202,8 +202,8 @@ class TestAutomationTime(unittest.TestCase):
|
||||||
hour=5, minute=0, second=0))
|
hour=5, minute=0, second=0))
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual('time - 5', self.calls[0].data['some'])
|
assert 'time - 5' == self.calls[0].data['some']
|
||||||
|
|
||||||
def test_if_not_working_if_no_values_in_conf_provided(self):
|
def test_if_not_working_if_no_values_in_conf_provided(self):
|
||||||
"""Test for failure if no configuration."""
|
"""Test for failure if no configuration."""
|
||||||
|
@ -223,7 +223,7 @@ class TestAutomationTime(unittest.TestCase):
|
||||||
hour=5, minute=0, second=0))
|
hour=5, minute=0, second=0))
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_using_wrong_at(self):
|
def test_if_not_fires_using_wrong_at(self):
|
||||||
"""YAML translates time values to total seconds.
|
"""YAML translates time values to total seconds.
|
||||||
|
@ -248,7 +248,7 @@ class TestAutomationTime(unittest.TestCase):
|
||||||
hour=1, minute=0, second=5))
|
hour=1, minute=0, second=5))
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_action_before(self):
|
def test_if_action_before(self):
|
||||||
"""Test for if action before."""
|
"""Test for if action before."""
|
||||||
|
@ -276,14 +276,14 @@ class TestAutomationTime(unittest.TestCase):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
with patch('homeassistant.helpers.condition.dt_util.now',
|
with patch('homeassistant.helpers.condition.dt_util.now',
|
||||||
return_value=after_10):
|
return_value=after_10):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_action_after(self):
|
def test_if_action_after(self):
|
||||||
"""Test for if action after."""
|
"""Test for if action after."""
|
||||||
|
@ -311,14 +311,14 @@ class TestAutomationTime(unittest.TestCase):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
with patch('homeassistant.helpers.condition.dt_util.now',
|
with patch('homeassistant.helpers.condition.dt_util.now',
|
||||||
return_value=after_10):
|
return_value=after_10):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_action_one_weekday(self):
|
def test_if_action_one_weekday(self):
|
||||||
"""Test for if action with one weekday."""
|
"""Test for if action with one weekday."""
|
||||||
|
@ -347,14 +347,14 @@ class TestAutomationTime(unittest.TestCase):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
with patch('homeassistant.helpers.condition.dt_util.now',
|
with patch('homeassistant.helpers.condition.dt_util.now',
|
||||||
return_value=tuesday):
|
return_value=tuesday):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_action_list_weekday(self):
|
def test_if_action_list_weekday(self):
|
||||||
"""Test for action with a list of weekdays."""
|
"""Test for action with a list of weekdays."""
|
||||||
|
@ -384,18 +384,18 @@ class TestAutomationTime(unittest.TestCase):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
with patch('homeassistant.helpers.condition.dt_util.now',
|
with patch('homeassistant.helpers.condition.dt_util.now',
|
||||||
return_value=tuesday):
|
return_value=tuesday):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(2, len(self.calls))
|
assert 2 == len(self.calls)
|
||||||
|
|
||||||
with patch('homeassistant.helpers.condition.dt_util.now',
|
with patch('homeassistant.helpers.condition.dt_util.now',
|
||||||
return_value=wednesday):
|
return_value=wednesday):
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(2, len(self.calls))
|
assert 2 == len(self.calls)
|
||||||
|
|
|
@ -75,11 +75,10 @@ class TestAutomationZone(unittest.TestCase):
|
||||||
}, context=context)
|
}, context=context)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
assert self.calls[0].context is context
|
assert self.calls[0].context is context
|
||||||
self.assertEqual(
|
assert 'zone - test.entity - hello - hello - test' == \
|
||||||
'zone - test.entity - hello - hello - test',
|
self.calls[0].data['some']
|
||||||
self.calls[0].data['some'])
|
|
||||||
|
|
||||||
# Set out of zone again so we can trigger call
|
# Set out of zone again so we can trigger call
|
||||||
self.hass.states.set('test.entity', 'hello', {
|
self.hass.states.set('test.entity', 'hello', {
|
||||||
|
@ -97,7 +96,7 @@ class TestAutomationZone(unittest.TestCase):
|
||||||
})
|
})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_for_enter_on_zone_leave(self):
|
def test_if_not_fires_for_enter_on_zone_leave(self):
|
||||||
"""Test for not firing on zone leave."""
|
"""Test for not firing on zone leave."""
|
||||||
|
@ -127,7 +126,7 @@ class TestAutomationZone(unittest.TestCase):
|
||||||
})
|
})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_if_fires_on_zone_leave(self):
|
def test_if_fires_on_zone_leave(self):
|
||||||
"""Test for firing on zone leave."""
|
"""Test for firing on zone leave."""
|
||||||
|
@ -157,7 +156,7 @@ class TestAutomationZone(unittest.TestCase):
|
||||||
})
|
})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_if_not_fires_for_leave_on_zone_enter(self):
|
def test_if_not_fires_for_leave_on_zone_enter(self):
|
||||||
"""Test for not firing on zone enter."""
|
"""Test for not firing on zone enter."""
|
||||||
|
@ -187,7 +186,7 @@ class TestAutomationZone(unittest.TestCase):
|
||||||
})
|
})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_zone_condition(self):
|
def test_zone_condition(self):
|
||||||
"""Test for zone condition."""
|
"""Test for zone condition."""
|
||||||
|
@ -216,4 +215,4 @@ class TestAutomationZone(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
|
@ -50,17 +50,13 @@ class TestAuroraSensorSetUp(unittest.TestCase):
|
||||||
aurora.setup_platform(self.hass, config, mock_add_entities)
|
aurora.setup_platform(self.hass, config, mock_add_entities)
|
||||||
|
|
||||||
aurora_component = entities[0]
|
aurora_component = entities[0]
|
||||||
self.assertEqual(len(entities), 1)
|
assert len(entities) == 1
|
||||||
self.assertEqual(aurora_component.name, "Test")
|
assert aurora_component.name == "Test"
|
||||||
self.assertEqual(
|
assert \
|
||||||
aurora_component.device_state_attributes["visibility_level"],
|
aurora_component.device_state_attributes["visibility_level"] == '0'
|
||||||
'0'
|
assert aurora_component.device_state_attributes["message"] == \
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
aurora_component.device_state_attributes["message"],
|
|
||||||
"nothing's out"
|
"nothing's out"
|
||||||
)
|
assert not aurora_component.is_on
|
||||||
self.assertFalse(aurora_component.is_on)
|
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_custom_threshold_works(self, mock_req):
|
def test_custom_threshold_works(self, mock_req):
|
||||||
|
@ -91,5 +87,5 @@ class TestAuroraSensorSetUp(unittest.TestCase):
|
||||||
aurora.setup_platform(self.hass, config, mock_add_entities)
|
aurora.setup_platform(self.hass, config, mock_add_entities)
|
||||||
|
|
||||||
aurora_component = entities[0]
|
aurora_component = entities[0]
|
||||||
self.assertEqual(aurora_component.aurora_data.visibility_level, '5')
|
assert aurora_component.aurora_data.visibility_level == '5'
|
||||||
self.assertTrue(aurora_component.is_on)
|
assert aurora_component.is_on
|
||||||
|
|
|
@ -52,8 +52,8 @@ class TestBayesianBinarySensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test_binary')
|
state = self.hass.states.get('binary_sensor.test_binary')
|
||||||
|
|
||||||
self.assertEqual([], state.attributes.get('observations'))
|
assert [] == state.attributes.get('observations')
|
||||||
self.assertEqual(0.2, state.attributes.get('probability'))
|
assert 0.2 == state.attributes.get('probability')
|
||||||
|
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
|
@ -66,14 +66,14 @@ class TestBayesianBinarySensor(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test_binary')
|
state = self.hass.states.get('binary_sensor.test_binary')
|
||||||
self.assertEqual([{
|
assert [{
|
||||||
'prob_false': 0.4,
|
'prob_false': 0.4,
|
||||||
'prob_true': 0.6
|
'prob_true': 0.6
|
||||||
}, {
|
}, {
|
||||||
'prob_false': 0.1,
|
'prob_false': 0.1,
|
||||||
'prob_true': 0.9
|
'prob_true': 0.9
|
||||||
}], state.attributes.get('observations'))
|
}] == state.attributes.get('observations')
|
||||||
self.assertAlmostEqual(0.77, state.attributes.get('probability'))
|
assert round(abs(0.77-state.attributes.get('probability')), 7) == 0
|
||||||
|
|
||||||
assert state.state == 'on'
|
assert state.state == 'on'
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ class TestBayesianBinarySensor(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test_binary')
|
state = self.hass.states.get('binary_sensor.test_binary')
|
||||||
self.assertEqual(0.2, state.attributes.get('probability'))
|
assert 0.2 == state.attributes.get('probability')
|
||||||
|
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
|
@ -123,8 +123,8 @@ class TestBayesianBinarySensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test_binary')
|
state = self.hass.states.get('binary_sensor.test_binary')
|
||||||
|
|
||||||
self.assertEqual([], state.attributes.get('observations'))
|
assert [] == state.attributes.get('observations')
|
||||||
self.assertEqual(0.2, state.attributes.get('probability'))
|
assert 0.2 == state.attributes.get('probability')
|
||||||
|
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
|
@ -136,11 +136,11 @@ class TestBayesianBinarySensor(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test_binary')
|
state = self.hass.states.get('binary_sensor.test_binary')
|
||||||
self.assertEqual([{
|
assert [{
|
||||||
'prob_true': 0.8,
|
'prob_true': 0.8,
|
||||||
'prob_false': 0.4
|
'prob_false': 0.4
|
||||||
}], state.attributes.get('observations'))
|
}] == state.attributes.get('observations')
|
||||||
self.assertAlmostEqual(0.33, state.attributes.get('probability'))
|
assert round(abs(0.33-state.attributes.get('probability')), 7) == 0
|
||||||
|
|
||||||
assert state.state == 'on'
|
assert state.state == 'on'
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ class TestBayesianBinarySensor(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test_binary')
|
state = self.hass.states.get('binary_sensor.test_binary')
|
||||||
self.assertAlmostEqual(0.2, state.attributes.get('probability'))
|
assert round(abs(0.2-state.attributes.get('probability')), 7) == 0
|
||||||
|
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ class TestBayesianBinarySensor(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test_binary')
|
state = self.hass.states.get('binary_sensor.test_binary')
|
||||||
self.assertAlmostEqual(1.0, state.attributes.get('probability'))
|
assert round(abs(1.0-state.attributes.get('probability')), 7) == 0
|
||||||
|
|
||||||
assert state.state == 'on'
|
assert state.state == 'on'
|
||||||
|
|
||||||
|
@ -219,8 +219,8 @@ class TestBayesianBinarySensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test_binary')
|
state = self.hass.states.get('binary_sensor.test_binary')
|
||||||
|
|
||||||
self.assertEqual([], state.attributes.get('observations'))
|
assert [] == state.attributes.get('observations')
|
||||||
self.assertEqual(0.2, state.attributes.get('probability'))
|
assert 0.2 == state.attributes.get('probability')
|
||||||
|
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
|
@ -232,11 +232,11 @@ class TestBayesianBinarySensor(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test_binary')
|
state = self.hass.states.get('binary_sensor.test_binary')
|
||||||
self.assertEqual([{
|
assert [{
|
||||||
'prob_true': 0.8,
|
'prob_true': 0.8,
|
||||||
'prob_false': 0.4
|
'prob_false': 0.4
|
||||||
}], state.attributes.get('observations'))
|
}] == state.attributes.get('observations')
|
||||||
self.assertAlmostEqual(0.33, state.attributes.get('probability'))
|
assert round(abs(0.33-state.attributes.get('probability')), 7) == 0
|
||||||
|
|
||||||
assert state.state == 'on'
|
assert state.state == 'on'
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ class TestBayesianBinarySensor(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test_binary')
|
state = self.hass.states.get('binary_sensor.test_binary')
|
||||||
self.assertAlmostEqual(0.11, state.attributes.get('probability'))
|
assert round(abs(0.11-state.attributes.get('probability')), 7) == 0
|
||||||
|
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ class TestBayesianBinarySensor(unittest.TestCase):
|
||||||
for pt, pf in zip(prob_true, prob_false):
|
for pt, pf in zip(prob_true, prob_false):
|
||||||
prior = bayesian.update_probability(prior, pt, pf)
|
prior = bayesian.update_probability(prior, pt, pf)
|
||||||
|
|
||||||
self.assertAlmostEqual(0.720000, prior)
|
assert round(abs(0.720000-prior), 7) == 0
|
||||||
|
|
||||||
prob_true = [0.8, 0.3, 0.9]
|
prob_true = [0.8, 0.3, 0.9]
|
||||||
prob_false = [0.6, 0.4, 0.2]
|
prob_false = [0.6, 0.4, 0.2]
|
||||||
|
@ -268,4 +268,4 @@ class TestBayesianBinarySensor(unittest.TestCase):
|
||||||
for pt, pf in zip(prob_true, prob_false):
|
for pt, pf in zip(prob_true, prob_false):
|
||||||
prior = bayesian.update_probability(prior, pt, pf)
|
prior = bayesian.update_probability(prior, pt, pf)
|
||||||
|
|
||||||
self.assertAlmostEqual(0.9130434782608695, prior)
|
assert round(abs(0.9130434782608695-prior), 7) == 0
|
||||||
|
|
|
@ -12,14 +12,14 @@ class TestBinarySensor(unittest.TestCase):
|
||||||
def test_state(self):
|
def test_state(self):
|
||||||
"""Test binary sensor state."""
|
"""Test binary sensor state."""
|
||||||
sensor = binary_sensor.BinarySensorDevice()
|
sensor = binary_sensor.BinarySensorDevice()
|
||||||
self.assertEqual(STATE_OFF, sensor.state)
|
assert STATE_OFF == sensor.state
|
||||||
with mock.patch('homeassistant.components.binary_sensor.'
|
with mock.patch('homeassistant.components.binary_sensor.'
|
||||||
'BinarySensorDevice.is_on',
|
'BinarySensorDevice.is_on',
|
||||||
new=False):
|
new=False):
|
||||||
self.assertEqual(STATE_OFF,
|
assert STATE_OFF == \
|
||||||
binary_sensor.BinarySensorDevice().state)
|
binary_sensor.BinarySensorDevice().state
|
||||||
with mock.patch('homeassistant.components.binary_sensor.'
|
with mock.patch('homeassistant.components.binary_sensor.'
|
||||||
'BinarySensorDevice.is_on',
|
'BinarySensorDevice.is_on',
|
||||||
new=True):
|
new=True):
|
||||||
self.assertEqual(STATE_ON,
|
assert STATE_ON == \
|
||||||
binary_sensor.BinarySensorDevice().state)
|
binary_sensor.BinarySensorDevice().state
|
||||||
|
|
|
@ -37,11 +37,11 @@ class TestCommandSensorBinarySensor(unittest.TestCase):
|
||||||
|
|
||||||
command_line.setup_platform(self.hass, config, add_dev_callback)
|
command_line.setup_platform(self.hass, config, add_dev_callback)
|
||||||
|
|
||||||
self.assertEqual(1, len(devices))
|
assert 1 == len(devices)
|
||||||
entity = devices[0]
|
entity = devices[0]
|
||||||
entity.update()
|
entity.update()
|
||||||
self.assertEqual('Test', entity.name)
|
assert 'Test' == entity.name
|
||||||
self.assertEqual(STATE_ON, entity.state)
|
assert STATE_ON == entity.state
|
||||||
|
|
||||||
def test_template(self):
|
def test_template(self):
|
||||||
"""Test setting the state with a template."""
|
"""Test setting the state with a template."""
|
||||||
|
@ -51,7 +51,7 @@ class TestCommandSensorBinarySensor(unittest.TestCase):
|
||||||
self.hass, data, 'test', None, '1.0', '0',
|
self.hass, data, 'test', None, '1.0', '0',
|
||||||
template.Template('{{ value | multiply(0.1) }}', self.hass))
|
template.Template('{{ value | multiply(0.1) }}', self.hass))
|
||||||
entity.update()
|
entity.update()
|
||||||
self.assertEqual(STATE_ON, entity.state)
|
assert STATE_ON == entity.state
|
||||||
|
|
||||||
def test_sensor_off(self):
|
def test_sensor_off(self):
|
||||||
"""Test setting the state with a template."""
|
"""Test setting the state with a template."""
|
||||||
|
@ -60,4 +60,4 @@ class TestCommandSensorBinarySensor(unittest.TestCase):
|
||||||
entity = command_line.CommandBinarySensor(
|
entity = command_line.CommandBinarySensor(
|
||||||
self.hass, data, 'test', None, '1', '0', None)
|
self.hass, data, 'test', None, '1', '0', None)
|
||||||
entity.update()
|
entity.update()
|
||||||
self.assertEqual(STATE_OFF, entity.state)
|
assert STATE_OFF == entity.state
|
||||||
|
|
|
@ -46,17 +46,17 @@ class TestSensorMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test-topic', 'ON')
|
fire_mqtt_message(self.hass, 'test-topic', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test-topic', 'OFF')
|
fire_mqtt_message(self.hass, 'test-topic', 'OFF')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
def test_valid_device_class(self):
|
def test_valid_device_class(self):
|
||||||
"""Test the setting of a valid sensor class."""
|
"""Test the setting of a valid sensor class."""
|
||||||
|
@ -70,7 +70,7 @@ class TestSensorMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertEqual('motion', state.attributes.get('device_class'))
|
assert 'motion' == state.attributes.get('device_class')
|
||||||
|
|
||||||
def test_invalid_device_class(self):
|
def test_invalid_device_class(self):
|
||||||
"""Test the setting of an invalid sensor class."""
|
"""Test the setting of an invalid sensor class."""
|
||||||
|
@ -84,50 +84,50 @@ class TestSensorMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertIsNone(state)
|
assert state is None
|
||||||
|
|
||||||
def test_availability_without_topic(self):
|
def test_availability_without_topic(self):
|
||||||
"""Test availability without defined availability topic."""
|
"""Test availability without defined availability topic."""
|
||||||
self.assertTrue(setup_component(self.hass, binary_sensor.DOMAIN, {
|
assert setup_component(self.hass, binary_sensor.DOMAIN, {
|
||||||
binary_sensor.DOMAIN: {
|
binary_sensor.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'state_topic': 'state-topic',
|
'state_topic': 'state-topic',
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
def test_availability_by_defaults(self):
|
def test_availability_by_defaults(self):
|
||||||
"""Test availability by defaults with defined topic."""
|
"""Test availability by defaults with defined topic."""
|
||||||
self.assertTrue(setup_component(self.hass, binary_sensor.DOMAIN, {
|
assert setup_component(self.hass, binary_sensor.DOMAIN, {
|
||||||
binary_sensor.DOMAIN: {
|
binary_sensor.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'state_topic': 'state-topic',
|
'state_topic': 'state-topic',
|
||||||
'availability_topic': 'availability-topic'
|
'availability_topic': 'availability-topic'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
def test_availability_by_custom_payload(self):
|
def test_availability_by_custom_payload(self):
|
||||||
"""Test availability by custom payload with defined topic."""
|
"""Test availability by custom payload with defined topic."""
|
||||||
self.assertTrue(setup_component(self.hass, binary_sensor.DOMAIN, {
|
assert setup_component(self.hass, binary_sensor.DOMAIN, {
|
||||||
binary_sensor.DOMAIN: {
|
binary_sensor.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -136,22 +136,22 @@ class TestSensorMQTT(unittest.TestCase):
|
||||||
'payload_available': 'good',
|
'payload_available': 'good',
|
||||||
'payload_not_available': 'nogood'
|
'payload_not_available': 'nogood'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
def test_force_update_disabled(self):
|
def test_force_update_disabled(self):
|
||||||
"""Test force update option."""
|
"""Test force update option."""
|
||||||
|
@ -177,11 +177,11 @@ class TestSensorMQTT(unittest.TestCase):
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test-topic', 'ON')
|
fire_mqtt_message(self.hass, 'test-topic', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(events))
|
assert 1 == len(events)
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test-topic', 'ON')
|
fire_mqtt_message(self.hass, 'test-topic', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(events))
|
assert 1 == len(events)
|
||||||
|
|
||||||
def test_force_update_enabled(self):
|
def test_force_update_enabled(self):
|
||||||
"""Test force update option."""
|
"""Test force update option."""
|
||||||
|
@ -208,11 +208,11 @@ class TestSensorMQTT(unittest.TestCase):
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test-topic', 'ON')
|
fire_mqtt_message(self.hass, 'test-topic', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(events))
|
assert 1 == len(events)
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test-topic', 'ON')
|
fire_mqtt_message(self.hass, 'test-topic', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(2, len(events))
|
assert 2 == len(events)
|
||||||
|
|
||||||
def test_off_delay(self):
|
def test_off_delay(self):
|
||||||
"""Test off_delay option."""
|
"""Test off_delay option."""
|
||||||
|
@ -241,20 +241,20 @@ class TestSensorMQTT(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'test-topic', 'ON')
|
fire_mqtt_message(self.hass, 'test-topic', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(1, len(events))
|
assert 1 == len(events)
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test-topic', 'ON')
|
fire_mqtt_message(self.hass, 'test-topic', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(2, len(events))
|
assert 2 == len(events)
|
||||||
|
|
||||||
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=30))
|
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=30))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertEqual(3, len(events))
|
assert 3 == len(events)
|
||||||
|
|
||||||
|
|
||||||
async def test_unique_id(hass):
|
async def test_unique_id(hass):
|
||||||
|
|
|
@ -9,6 +9,7 @@ from homeassistant.components.binary_sensor import nx584
|
||||||
from homeassistant.setup import setup_component
|
from homeassistant.setup import setup_component
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant
|
from tests.common import get_test_home_assistant
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
class StopMe(Exception):
|
class StopMe(Exception):
|
||||||
|
@ -52,14 +53,13 @@ class TestNX584SensorSetup(unittest.TestCase):
|
||||||
'exclude_zones': [],
|
'exclude_zones': [],
|
||||||
'zone_types': {},
|
'zone_types': {},
|
||||||
}
|
}
|
||||||
self.assertTrue(nx584.setup_platform(self.hass, config, add_entities))
|
assert nx584.setup_platform(self.hass, config, add_entities)
|
||||||
mock_nx.assert_has_calls(
|
mock_nx.assert_has_calls(
|
||||||
[mock.call(zone, 'opening') for zone in self.fake_zones])
|
[mock.call(zone, 'opening') for zone in self.fake_zones])
|
||||||
self.assertTrue(add_entities.called)
|
assert add_entities.called
|
||||||
self.assertEqual(nx584_client.Client.call_count, 1)
|
assert nx584_client.Client.call_count == 1
|
||||||
self.assertEqual(
|
assert nx584_client.Client.call_args == \
|
||||||
nx584_client.Client.call_args, mock.call('http://localhost:5007')
|
mock.call('http://localhost:5007')
|
||||||
)
|
|
||||||
|
|
||||||
@mock.patch('homeassistant.components.binary_sensor.nx584.NX584Watcher')
|
@mock.patch('homeassistant.components.binary_sensor.nx584.NX584Watcher')
|
||||||
@mock.patch('homeassistant.components.binary_sensor.nx584.NX584ZoneSensor')
|
@mock.patch('homeassistant.components.binary_sensor.nx584.NX584ZoneSensor')
|
||||||
|
@ -72,22 +72,20 @@ class TestNX584SensorSetup(unittest.TestCase):
|
||||||
'zone_types': {3: 'motion'},
|
'zone_types': {3: 'motion'},
|
||||||
}
|
}
|
||||||
add_entities = mock.MagicMock()
|
add_entities = mock.MagicMock()
|
||||||
self.assertTrue(nx584.setup_platform(self.hass, config, add_entities))
|
assert nx584.setup_platform(self.hass, config, add_entities)
|
||||||
mock_nx.assert_has_calls([
|
mock_nx.assert_has_calls([
|
||||||
mock.call(self.fake_zones[0], 'opening'),
|
mock.call(self.fake_zones[0], 'opening'),
|
||||||
mock.call(self.fake_zones[2], 'motion'),
|
mock.call(self.fake_zones[2], 'motion'),
|
||||||
])
|
])
|
||||||
self.assertTrue(add_entities.called)
|
assert add_entities.called
|
||||||
self.assertEqual(nx584_client.Client.call_count, 1)
|
assert nx584_client.Client.call_count == 1
|
||||||
self.assertEqual(
|
assert nx584_client.Client.call_args == mock.call('http://foo:123')
|
||||||
nx584_client.Client.call_args, mock.call('http://foo:123')
|
assert mock_watcher.called
|
||||||
)
|
|
||||||
self.assertTrue(mock_watcher.called)
|
|
||||||
|
|
||||||
def _test_assert_graceful_fail(self, config):
|
def _test_assert_graceful_fail(self, config):
|
||||||
"""Test the failing."""
|
"""Test the failing."""
|
||||||
self.assertFalse(setup_component(
|
assert not setup_component(
|
||||||
self.hass, 'binary_sensor.nx584', config))
|
self.hass, 'binary_sensor.nx584', config)
|
||||||
|
|
||||||
def test_setup_bad_config(self):
|
def test_setup_bad_config(self):
|
||||||
"""Test the setup with bad configuration."""
|
"""Test the setup with bad configuration."""
|
||||||
|
@ -121,8 +119,8 @@ class TestNX584SensorSetup(unittest.TestCase):
|
||||||
"""Test the setup with no zones."""
|
"""Test the setup with no zones."""
|
||||||
nx584_client.Client.return_value.list_zones.return_value = []
|
nx584_client.Client.return_value.list_zones.return_value = []
|
||||||
add_entities = mock.MagicMock()
|
add_entities = mock.MagicMock()
|
||||||
self.assertTrue(nx584.setup_platform(self.hass, {}, add_entities))
|
assert nx584.setup_platform(self.hass, {}, add_entities)
|
||||||
self.assertFalse(add_entities.called)
|
assert not add_entities.called
|
||||||
|
|
||||||
|
|
||||||
class TestNX584ZoneSensor(unittest.TestCase):
|
class TestNX584ZoneSensor(unittest.TestCase):
|
||||||
|
@ -132,12 +130,12 @@ class TestNX584ZoneSensor(unittest.TestCase):
|
||||||
"""Test the sensor."""
|
"""Test the sensor."""
|
||||||
zone = {'number': 1, 'name': 'foo', 'state': True}
|
zone = {'number': 1, 'name': 'foo', 'state': True}
|
||||||
sensor = nx584.NX584ZoneSensor(zone, 'motion')
|
sensor = nx584.NX584ZoneSensor(zone, 'motion')
|
||||||
self.assertEqual('foo', sensor.name)
|
assert 'foo' == sensor.name
|
||||||
self.assertFalse(sensor.should_poll)
|
assert not sensor.should_poll
|
||||||
self.assertTrue(sensor.is_on)
|
assert sensor.is_on
|
||||||
|
|
||||||
zone['state'] = False
|
zone['state'] = False
|
||||||
self.assertFalse(sensor.is_on)
|
assert not sensor.is_on
|
||||||
|
|
||||||
|
|
||||||
class TestNX584Watcher(unittest.TestCase):
|
class TestNX584Watcher(unittest.TestCase):
|
||||||
|
@ -154,15 +152,15 @@ class TestNX584Watcher(unittest.TestCase):
|
||||||
}
|
}
|
||||||
watcher = nx584.NX584Watcher(None, zones)
|
watcher = nx584.NX584Watcher(None, zones)
|
||||||
watcher._process_zone_event({'zone': 1, 'zone_state': False})
|
watcher._process_zone_event({'zone': 1, 'zone_state': False})
|
||||||
self.assertFalse(zone1['state'])
|
assert not zone1['state']
|
||||||
self.assertEqual(1, mock_update.call_count)
|
assert 1 == mock_update.call_count
|
||||||
|
|
||||||
@mock.patch.object(nx584.NX584ZoneSensor, 'schedule_update_ha_state')
|
@mock.patch.object(nx584.NX584ZoneSensor, 'schedule_update_ha_state')
|
||||||
def test_process_zone_event_missing_zone(self, mock_update):
|
def test_process_zone_event_missing_zone(self, mock_update):
|
||||||
"""Test the processing of zone events with missing zones."""
|
"""Test the processing of zone events with missing zones."""
|
||||||
watcher = nx584.NX584Watcher(None, {})
|
watcher = nx584.NX584Watcher(None, {})
|
||||||
watcher._process_zone_event({'zone': 1, 'zone_state': False})
|
watcher._process_zone_event({'zone': 1, 'zone_state': False})
|
||||||
self.assertFalse(mock_update.called)
|
assert not mock_update.called
|
||||||
|
|
||||||
def test_run_with_zone_events(self):
|
def test_run_with_zone_events(self):
|
||||||
"""Test the zone events."""
|
"""Test the zone events."""
|
||||||
|
@ -187,12 +185,13 @@ class TestNX584Watcher(unittest.TestCase):
|
||||||
def run(fake_process):
|
def run(fake_process):
|
||||||
"""Run a fake process."""
|
"""Run a fake process."""
|
||||||
fake_process.side_effect = StopMe
|
fake_process.side_effect = StopMe
|
||||||
self.assertRaises(StopMe, watcher._run)
|
with pytest.raises(StopMe):
|
||||||
self.assertEqual(fake_process.call_count, 1)
|
watcher._run()
|
||||||
self.assertEqual(fake_process.call_args, mock.call(fake_events[0]))
|
assert fake_process.call_count == 1
|
||||||
|
assert fake_process.call_args == mock.call(fake_events[0])
|
||||||
|
|
||||||
run()
|
run()
|
||||||
self.assertEqual(3, client.get_events.call_count)
|
assert 3 == client.get_events.call_count
|
||||||
|
|
||||||
@mock.patch('time.sleep')
|
@mock.patch('time.sleep')
|
||||||
def test_run_retries_failures(self, mock_sleep):
|
def test_run_retries_failures(self, mock_sleep):
|
||||||
|
@ -210,6 +209,7 @@ class TestNX584Watcher(unittest.TestCase):
|
||||||
watcher = nx584.NX584Watcher(None, {})
|
watcher = nx584.NX584Watcher(None, {})
|
||||||
with mock.patch.object(watcher, '_run') as mock_inner:
|
with mock.patch.object(watcher, '_run') as mock_inner:
|
||||||
mock_inner.side_effect = fake_run
|
mock_inner.side_effect = fake_run
|
||||||
self.assertRaises(StopMe, watcher.run)
|
with pytest.raises(StopMe):
|
||||||
self.assertEqual(3, mock_inner.call_count)
|
watcher.run()
|
||||||
|
assert 3 == mock_inner.call_count
|
||||||
mock_sleep.assert_has_calls([mock.call(10), mock.call(10)])
|
mock_sleep.assert_has_calls([mock.call(10), mock.call(10)])
|
||||||
|
|
|
@ -32,7 +32,7 @@ class TestRandomSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
|
|
||||||
self.assertEqual(state.state, 'on')
|
assert state.state == 'on'
|
||||||
|
|
||||||
@patch('random.getrandbits', return_value=False)
|
@patch('random.getrandbits', return_value=False)
|
||||||
def test_random_binary_sensor_off(self, mocked):
|
def test_random_binary_sensor_off(self, mocked):
|
||||||
|
@ -48,4 +48,4 @@ class TestRandomSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.test')
|
state = self.hass.states.get('binary_sensor.test')
|
||||||
|
|
||||||
self.assertEqual(state.state, 'off')
|
assert state.state == 'off'
|
||||||
|
|
|
@ -15,6 +15,7 @@ from homeassistant.const import STATE_ON, STATE_OFF
|
||||||
from homeassistant.helpers import template
|
from homeassistant.helpers import template
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant, assert_setup_component
|
from tests.common import get_test_home_assistant, assert_setup_component
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
class TestRestBinarySensorSetup(unittest.TestCase):
|
class TestRestBinarySensorSetup(unittest.TestCase):
|
||||||
|
@ -45,7 +46,7 @@ class TestRestBinarySensorSetup(unittest.TestCase):
|
||||||
|
|
||||||
def test_setup_missing_schema(self):
|
def test_setup_missing_schema(self):
|
||||||
"""Test setup with resource missing schema."""
|
"""Test setup with resource missing schema."""
|
||||||
with self.assertRaises(MissingSchema):
|
with pytest.raises(MissingSchema):
|
||||||
rest.setup_platform(self.hass, {
|
rest.setup_platform(self.hass, {
|
||||||
'platform': 'rest',
|
'platform': 'rest',
|
||||||
'resource': 'localhost',
|
'resource': 'localhost',
|
||||||
|
@ -61,7 +62,7 @@ class TestRestBinarySensorSetup(unittest.TestCase):
|
||||||
'platform': 'rest',
|
'platform': 'rest',
|
||||||
'resource': 'http://localhost',
|
'resource': 'http://localhost',
|
||||||
}, self.add_devices, None)
|
}, self.add_devices, None)
|
||||||
self.assertEqual(len(self.DEVICES), 0)
|
assert len(self.DEVICES) == 0
|
||||||
|
|
||||||
@patch('requests.Session.send', side_effect=Timeout())
|
@patch('requests.Session.send', side_effect=Timeout())
|
||||||
def test_setup_timeout(self, mock_req):
|
def test_setup_timeout(self, mock_req):
|
||||||
|
@ -71,27 +72,27 @@ class TestRestBinarySensorSetup(unittest.TestCase):
|
||||||
'platform': 'rest',
|
'platform': 'rest',
|
||||||
'resource': 'http://localhost',
|
'resource': 'http://localhost',
|
||||||
}, self.add_devices, None)
|
}, self.add_devices, None)
|
||||||
self.assertEqual(len(self.DEVICES), 0)
|
assert len(self.DEVICES) == 0
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_setup_minimum(self, mock_req):
|
def test_setup_minimum(self, mock_req):
|
||||||
"""Test setup with minimum configuration."""
|
"""Test setup with minimum configuration."""
|
||||||
mock_req.get('http://localhost', status_code=200)
|
mock_req.get('http://localhost', status_code=200)
|
||||||
with assert_setup_component(1, 'binary_sensor'):
|
with assert_setup_component(1, 'binary_sensor'):
|
||||||
self.assertTrue(setup_component(self.hass, 'binary_sensor', {
|
assert setup_component(self.hass, 'binary_sensor', {
|
||||||
'binary_sensor': {
|
'binary_sensor': {
|
||||||
'platform': 'rest',
|
'platform': 'rest',
|
||||||
'resource': 'http://localhost'
|
'resource': 'http://localhost'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
self.assertEqual(1, mock_req.call_count)
|
assert 1 == mock_req.call_count
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_setup_get(self, mock_req):
|
def test_setup_get(self, mock_req):
|
||||||
"""Test setup with valid configuration."""
|
"""Test setup with valid configuration."""
|
||||||
mock_req.get('http://localhost', status_code=200)
|
mock_req.get('http://localhost', status_code=200)
|
||||||
with assert_setup_component(1, 'binary_sensor'):
|
with assert_setup_component(1, 'binary_sensor'):
|
||||||
self.assertTrue(setup_component(self.hass, 'binary_sensor', {
|
assert setup_component(self.hass, 'binary_sensor', {
|
||||||
'binary_sensor': {
|
'binary_sensor': {
|
||||||
'platform': 'rest',
|
'platform': 'rest',
|
||||||
'resource': 'http://localhost',
|
'resource': 'http://localhost',
|
||||||
|
@ -105,15 +106,15 @@ class TestRestBinarySensorSetup(unittest.TestCase):
|
||||||
'password': 'my password',
|
'password': 'my password',
|
||||||
'headers': {'Accept': 'application/json'}
|
'headers': {'Accept': 'application/json'}
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
self.assertEqual(1, mock_req.call_count)
|
assert 1 == mock_req.call_count
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_setup_post(self, mock_req):
|
def test_setup_post(self, mock_req):
|
||||||
"""Test setup with valid configuration."""
|
"""Test setup with valid configuration."""
|
||||||
mock_req.post('http://localhost', status_code=200)
|
mock_req.post('http://localhost', status_code=200)
|
||||||
with assert_setup_component(1, 'binary_sensor'):
|
with assert_setup_component(1, 'binary_sensor'):
|
||||||
self.assertTrue(setup_component(self.hass, 'binary_sensor', {
|
assert setup_component(self.hass, 'binary_sensor', {
|
||||||
'binary_sensor': {
|
'binary_sensor': {
|
||||||
'platform': 'rest',
|
'platform': 'rest',
|
||||||
'resource': 'http://localhost',
|
'resource': 'http://localhost',
|
||||||
|
@ -128,8 +129,8 @@ class TestRestBinarySensorSetup(unittest.TestCase):
|
||||||
'password': 'my password',
|
'password': 'my password',
|
||||||
'headers': {'Accept': 'application/json'}
|
'headers': {'Accept': 'application/json'}
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
self.assertEqual(1, mock_req.call_count)
|
assert 1 == mock_req.call_count
|
||||||
|
|
||||||
|
|
||||||
class TestRestBinarySensor(unittest.TestCase):
|
class TestRestBinarySensor(unittest.TestCase):
|
||||||
|
@ -161,16 +162,16 @@ class TestRestBinarySensor(unittest.TestCase):
|
||||||
|
|
||||||
def test_name(self):
|
def test_name(self):
|
||||||
"""Test the name."""
|
"""Test the name."""
|
||||||
self.assertEqual(self.name, self.binary_sensor.name)
|
assert self.name == self.binary_sensor.name
|
||||||
|
|
||||||
def test_device_class(self):
|
def test_device_class(self):
|
||||||
"""Test the device class."""
|
"""Test the device class."""
|
||||||
self.assertEqual(self.device_class, self.binary_sensor.device_class)
|
assert self.device_class == self.binary_sensor.device_class
|
||||||
|
|
||||||
def test_initial_state(self):
|
def test_initial_state(self):
|
||||||
"""Test the initial state."""
|
"""Test the initial state."""
|
||||||
self.binary_sensor.update()
|
self.binary_sensor.update()
|
||||||
self.assertEqual(STATE_OFF, self.binary_sensor.state)
|
assert STATE_OFF == self.binary_sensor.state
|
||||||
|
|
||||||
def test_update_when_value_is_none(self):
|
def test_update_when_value_is_none(self):
|
||||||
"""Test state gets updated to unknown when sensor returns no data."""
|
"""Test state gets updated to unknown when sensor returns no data."""
|
||||||
|
@ -178,7 +179,7 @@ class TestRestBinarySensor(unittest.TestCase):
|
||||||
'RestData.update',
|
'RestData.update',
|
||||||
side_effect=self.update_side_effect(None))
|
side_effect=self.update_side_effect(None))
|
||||||
self.binary_sensor.update()
|
self.binary_sensor.update()
|
||||||
self.assertFalse(self.binary_sensor.available)
|
assert not self.binary_sensor.available
|
||||||
|
|
||||||
def test_update_when_value_changed(self):
|
def test_update_when_value_changed(self):
|
||||||
"""Test state gets updated when sensor returns a new status."""
|
"""Test state gets updated when sensor returns a new status."""
|
||||||
|
@ -186,15 +187,15 @@ class TestRestBinarySensor(unittest.TestCase):
|
||||||
side_effect=self.update_side_effect(
|
side_effect=self.update_side_effect(
|
||||||
'{ "key": true }'))
|
'{ "key": true }'))
|
||||||
self.binary_sensor.update()
|
self.binary_sensor.update()
|
||||||
self.assertEqual(STATE_ON, self.binary_sensor.state)
|
assert STATE_ON == self.binary_sensor.state
|
||||||
self.assertTrue(self.binary_sensor.available)
|
assert self.binary_sensor.available
|
||||||
|
|
||||||
def test_update_when_failed_request(self):
|
def test_update_when_failed_request(self):
|
||||||
"""Test state gets updated when sensor returns a new status."""
|
"""Test state gets updated when sensor returns a new status."""
|
||||||
self.rest.update = Mock('rest.RestData.update',
|
self.rest.update = Mock('rest.RestData.update',
|
||||||
side_effect=self.update_side_effect(None))
|
side_effect=self.update_side_effect(None))
|
||||||
self.binary_sensor.update()
|
self.binary_sensor.update()
|
||||||
self.assertFalse(self.binary_sensor.available)
|
assert not self.binary_sensor.available
|
||||||
|
|
||||||
def test_update_with_no_template(self):
|
def test_update_with_no_template(self):
|
||||||
"""Test update when there is no value template."""
|
"""Test update when there is no value template."""
|
||||||
|
@ -203,5 +204,5 @@ class TestRestBinarySensor(unittest.TestCase):
|
||||||
self.binary_sensor = rest.RestBinarySensor(
|
self.binary_sensor = rest.RestBinarySensor(
|
||||||
self.hass, self.rest, self.name, self.device_class, None)
|
self.hass, self.rest, self.name, self.device_class, None)
|
||||||
self.binary_sensor.update()
|
self.binary_sensor.update()
|
||||||
self.assertEqual(STATE_ON, self.binary_sensor.state)
|
assert STATE_ON == self.binary_sensor.state
|
||||||
self.assertTrue(self.binary_sensor.available)
|
assert self.binary_sensor.available
|
||||||
|
|
|
@ -64,13 +64,13 @@ class TestRingBinarySensorSetup(unittest.TestCase):
|
||||||
for device in self.DEVICES:
|
for device in self.DEVICES:
|
||||||
device.update()
|
device.update()
|
||||||
if device.name == 'Front Door Ding':
|
if device.name == 'Front Door Ding':
|
||||||
self.assertEqual('on', device.state)
|
assert 'on' == device.state
|
||||||
self.assertEqual('America/New_York',
|
assert 'America/New_York' == \
|
||||||
device.device_state_attributes['timezone'])
|
device.device_state_attributes['timezone']
|
||||||
elif device.name == 'Front Door Motion':
|
elif device.name == 'Front Door Motion':
|
||||||
self.assertEqual('off', device.state)
|
assert 'off' == device.state
|
||||||
self.assertEqual('motion', device.device_class)
|
assert 'motion' == device.device_class
|
||||||
|
|
||||||
self.assertIsNone(device.entity_picture)
|
assert device.entity_picture is None
|
||||||
self.assertEqual(ATTRIBUTION,
|
assert ATTRIBUTION == \
|
||||||
device.device_state_attributes['attribution'])
|
device.device_state_attributes['attribution']
|
||||||
|
|
|
@ -47,12 +47,12 @@ class TestSleepIQBinarySensorSetup(unittest.TestCase):
|
||||||
self.config,
|
self.config,
|
||||||
self.add_entities,
|
self.add_entities,
|
||||||
MagicMock())
|
MagicMock())
|
||||||
self.assertEqual(2, len(self.DEVICES))
|
assert 2 == len(self.DEVICES)
|
||||||
|
|
||||||
left_side = self.DEVICES[1]
|
left_side = self.DEVICES[1]
|
||||||
self.assertEqual('SleepNumber ILE Test1 Is In Bed', left_side.name)
|
assert 'SleepNumber ILE Test1 Is In Bed' == left_side.name
|
||||||
self.assertEqual('on', left_side.state)
|
assert 'on' == left_side.state
|
||||||
|
|
||||||
right_side = self.DEVICES[0]
|
right_side = self.DEVICES[0]
|
||||||
self.assertEqual('SleepNumber ILE Test2 Is In Bed', right_side.name)
|
assert 'SleepNumber ILE Test2 Is In Bed' == right_side.name
|
||||||
self.assertEqual('off', right_side.state)
|
assert 'off' == right_side.state
|
||||||
|
|
|
@ -168,18 +168,18 @@ class TestBinarySensorTemplate(unittest.TestCase):
|
||||||
template_hlpr.Template('{{ 1 > 1 }}', self.hass),
|
template_hlpr.Template('{{ 1 > 1 }}', self.hass),
|
||||||
None, None, MATCH_ALL, None, None
|
None, None, MATCH_ALL, None, None
|
||||||
).result()
|
).result()
|
||||||
self.assertFalse(vs.should_poll)
|
assert not vs.should_poll
|
||||||
self.assertEqual('motion', vs.device_class)
|
assert 'motion' == vs.device_class
|
||||||
self.assertEqual('Parent', vs.name)
|
assert 'Parent' == vs.name
|
||||||
|
|
||||||
run_callback_threadsafe(self.hass.loop, vs.async_check_state).result()
|
run_callback_threadsafe(self.hass.loop, vs.async_check_state).result()
|
||||||
self.assertFalse(vs.is_on)
|
assert not vs.is_on
|
||||||
|
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
vs._template = template_hlpr.Template("{{ 2 > 1 }}", self.hass)
|
vs._template = template_hlpr.Template("{{ 2 > 1 }}", self.hass)
|
||||||
|
|
||||||
run_callback_threadsafe(self.hass.loop, vs.async_check_state).result()
|
run_callback_threadsafe(self.hass.loop, vs.async_check_state).result()
|
||||||
self.assertTrue(vs.is_on)
|
assert vs.is_on
|
||||||
|
|
||||||
def test_event(self):
|
def test_event(self):
|
||||||
"""Test the event."""
|
"""Test the event."""
|
||||||
|
|
|
@ -37,14 +37,14 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('sensor.test_monitored',
|
assert 'sensor.test_monitored' == \
|
||||||
state.attributes.get('entity_id'))
|
state.attributes.get('entity_id')
|
||||||
self.assertEqual(16, state.attributes.get('sensor_value'))
|
assert 16 == state.attributes.get('sensor_value')
|
||||||
self.assertEqual('above', state.attributes.get('position'))
|
assert 'above' == state.attributes.get('position')
|
||||||
self.assertEqual(float(config['binary_sensor']['upper']),
|
assert float(config['binary_sensor']['upper']) == \
|
||||||
state.attributes.get('upper'))
|
state.attributes.get('upper')
|
||||||
self.assertEqual(0.0, state.attributes.get('hysteresis'))
|
assert 0.0 == state.attributes.get('hysteresis')
|
||||||
self.assertEqual('upper', state.attributes.get('type'))
|
assert 'upper' == state.attributes.get('type')
|
||||||
|
|
||||||
assert state.state == 'on'
|
assert state.state == 'on'
|
||||||
|
|
||||||
|
@ -79,11 +79,11 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('above', state.attributes.get('position'))
|
assert 'above' == state.attributes.get('position')
|
||||||
self.assertEqual(float(config['binary_sensor']['lower']),
|
assert float(config['binary_sensor']['lower']) == \
|
||||||
state.attributes.get('lower'))
|
state.attributes.get('lower')
|
||||||
self.assertEqual(0.0, state.attributes.get('hysteresis'))
|
assert 0.0 == state.attributes.get('hysteresis')
|
||||||
self.assertEqual('lower', state.attributes.get('type'))
|
assert 'lower' == state.attributes.get('type')
|
||||||
|
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
|
@ -112,11 +112,11 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('above', state.attributes.get('position'))
|
assert 'above' == state.attributes.get('position')
|
||||||
self.assertEqual(float(config['binary_sensor']['upper']),
|
assert float(config['binary_sensor']['upper']) == \
|
||||||
state.attributes.get('upper'))
|
state.attributes.get('upper')
|
||||||
self.assertEqual(2.5, state.attributes.get('hysteresis'))
|
assert 2.5 == state.attributes.get('hysteresis')
|
||||||
self.assertEqual('upper', state.attributes.get('type'))
|
assert 'upper' == state.attributes.get('type')
|
||||||
|
|
||||||
assert state.state == 'on'
|
assert state.state == 'on'
|
||||||
|
|
||||||
|
@ -167,16 +167,16 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('sensor.test_monitored',
|
assert 'sensor.test_monitored' == \
|
||||||
state.attributes.get('entity_id'))
|
state.attributes.get('entity_id')
|
||||||
self.assertEqual(16, state.attributes.get('sensor_value'))
|
assert 16 == state.attributes.get('sensor_value')
|
||||||
self.assertEqual('in_range', state.attributes.get('position'))
|
assert 'in_range' == state.attributes.get('position')
|
||||||
self.assertEqual(float(config['binary_sensor']['lower']),
|
assert float(config['binary_sensor']['lower']) == \
|
||||||
state.attributes.get('lower'))
|
state.attributes.get('lower')
|
||||||
self.assertEqual(float(config['binary_sensor']['upper']),
|
assert float(config['binary_sensor']['upper']) == \
|
||||||
state.attributes.get('upper'))
|
state.attributes.get('upper')
|
||||||
self.assertEqual(0.0, state.attributes.get('hysteresis'))
|
assert 0.0 == state.attributes.get('hysteresis')
|
||||||
self.assertEqual('range', state.attributes.get('type'))
|
assert 'range' == state.attributes.get('type')
|
||||||
|
|
||||||
assert state.state == 'on'
|
assert state.state == 'on'
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('below', state.attributes.get('position'))
|
assert 'below' == state.attributes.get('position')
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
self.hass.states.set('sensor.test_monitored', 21)
|
self.hass.states.set('sensor.test_monitored', 21)
|
||||||
|
@ -193,7 +193,7 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('above', state.attributes.get('position'))
|
assert 'above' == state.attributes.get('position')
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
def test_sensor_in_range_with_hysteresis(self):
|
def test_sensor_in_range_with_hysteresis(self):
|
||||||
|
@ -216,17 +216,17 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('sensor.test_monitored',
|
assert 'sensor.test_monitored' == \
|
||||||
state.attributes.get('entity_id'))
|
state.attributes.get('entity_id')
|
||||||
self.assertEqual(16, state.attributes.get('sensor_value'))
|
assert 16 == state.attributes.get('sensor_value')
|
||||||
self.assertEqual('in_range', state.attributes.get('position'))
|
assert 'in_range' == state.attributes.get('position')
|
||||||
self.assertEqual(float(config['binary_sensor']['lower']),
|
assert float(config['binary_sensor']['lower']) == \
|
||||||
state.attributes.get('lower'))
|
state.attributes.get('lower')
|
||||||
self.assertEqual(float(config['binary_sensor']['upper']),
|
assert float(config['binary_sensor']['upper']) == \
|
||||||
state.attributes.get('upper'))
|
state.attributes.get('upper')
|
||||||
self.assertEqual(float(config['binary_sensor']['hysteresis']),
|
assert float(config['binary_sensor']['hysteresis']) == \
|
||||||
state.attributes.get('hysteresis'))
|
state.attributes.get('hysteresis')
|
||||||
self.assertEqual('range', state.attributes.get('type'))
|
assert 'range' == state.attributes.get('type')
|
||||||
|
|
||||||
assert state.state == 'on'
|
assert state.state == 'on'
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('in_range', state.attributes.get('position'))
|
assert 'in_range' == state.attributes.get('position')
|
||||||
assert state.state == 'on'
|
assert state.state == 'on'
|
||||||
|
|
||||||
self.hass.states.set('sensor.test_monitored', 7)
|
self.hass.states.set('sensor.test_monitored', 7)
|
||||||
|
@ -243,7 +243,7 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('below', state.attributes.get('position'))
|
assert 'below' == state.attributes.get('position')
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
self.hass.states.set('sensor.test_monitored', 12)
|
self.hass.states.set('sensor.test_monitored', 12)
|
||||||
|
@ -251,7 +251,7 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('below', state.attributes.get('position'))
|
assert 'below' == state.attributes.get('position')
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
self.hass.states.set('sensor.test_monitored', 13)
|
self.hass.states.set('sensor.test_monitored', 13)
|
||||||
|
@ -259,7 +259,7 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('in_range', state.attributes.get('position'))
|
assert 'in_range' == state.attributes.get('position')
|
||||||
assert state.state == 'on'
|
assert state.state == 'on'
|
||||||
|
|
||||||
self.hass.states.set('sensor.test_monitored', 22)
|
self.hass.states.set('sensor.test_monitored', 22)
|
||||||
|
@ -267,7 +267,7 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('in_range', state.attributes.get('position'))
|
assert 'in_range' == state.attributes.get('position')
|
||||||
assert state.state == 'on'
|
assert state.state == 'on'
|
||||||
|
|
||||||
self.hass.states.set('sensor.test_monitored', 23)
|
self.hass.states.set('sensor.test_monitored', 23)
|
||||||
|
@ -275,7 +275,7 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('above', state.attributes.get('position'))
|
assert 'above' == state.attributes.get('position')
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
self.hass.states.set('sensor.test_monitored', 18)
|
self.hass.states.set('sensor.test_monitored', 18)
|
||||||
|
@ -283,7 +283,7 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('above', state.attributes.get('position'))
|
assert 'above' == state.attributes.get('position')
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
self.hass.states.set('sensor.test_monitored', 17)
|
self.hass.states.set('sensor.test_monitored', 17)
|
||||||
|
@ -291,7 +291,7 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('in_range', state.attributes.get('position'))
|
assert 'in_range' == state.attributes.get('position')
|
||||||
assert state.state == 'on'
|
assert state.state == 'on'
|
||||||
|
|
||||||
def test_sensor_in_range_unknown_state(self):
|
def test_sensor_in_range_unknown_state(self):
|
||||||
|
@ -313,16 +313,16 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('sensor.test_monitored',
|
assert 'sensor.test_monitored' == \
|
||||||
state.attributes.get('entity_id'))
|
state.attributes.get('entity_id')
|
||||||
self.assertEqual(16, state.attributes.get('sensor_value'))
|
assert 16 == state.attributes.get('sensor_value')
|
||||||
self.assertEqual('in_range', state.attributes.get('position'))
|
assert 'in_range' == state.attributes.get('position')
|
||||||
self.assertEqual(float(config['binary_sensor']['lower']),
|
assert float(config['binary_sensor']['lower']) == \
|
||||||
state.attributes.get('lower'))
|
state.attributes.get('lower')
|
||||||
self.assertEqual(float(config['binary_sensor']['upper']),
|
assert float(config['binary_sensor']['upper']) == \
|
||||||
state.attributes.get('upper'))
|
state.attributes.get('upper')
|
||||||
self.assertEqual(0.0, state.attributes.get('hysteresis'))
|
assert 0.0 == state.attributes.get('hysteresis')
|
||||||
self.assertEqual('range', state.attributes.get('type'))
|
assert 'range' == state.attributes.get('type')
|
||||||
|
|
||||||
assert state.state == 'on'
|
assert state.state == 'on'
|
||||||
|
|
||||||
|
@ -331,7 +331,7 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('unknown', state.attributes.get('position'))
|
assert 'unknown' == state.attributes.get('position')
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
def test_sensor_lower_zero_threshold(self):
|
def test_sensor_lower_zero_threshold(self):
|
||||||
|
@ -351,9 +351,9 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('lower', state.attributes.get('type'))
|
assert 'lower' == state.attributes.get('type')
|
||||||
self.assertEqual(float(config['binary_sensor']['lower']),
|
assert float(config['binary_sensor']['lower']) == \
|
||||||
state.attributes.get('lower'))
|
state.attributes.get('lower')
|
||||||
|
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
|
@ -381,9 +381,9 @@ class TestThresholdSensor(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('binary_sensor.threshold')
|
state = self.hass.states.get('binary_sensor.threshold')
|
||||||
|
|
||||||
self.assertEqual('upper', state.attributes.get('type'))
|
assert 'upper' == state.attributes.get('type')
|
||||||
self.assertEqual(float(config['binary_sensor']['upper']),
|
assert float(config['binary_sensor']['upper']) == \
|
||||||
state.attributes.get('upper'))
|
state.attributes.get('upper')
|
||||||
|
|
||||||
assert state.state == 'off'
|
assert state.state == 'off'
|
||||||
|
|
||||||
|
|
|
@ -74,53 +74,53 @@ class TestVultrBinarySensorSetup(unittest.TestCase):
|
||||||
self.add_entities,
|
self.add_entities,
|
||||||
None)
|
None)
|
||||||
|
|
||||||
self.assertEqual(len(self.DEVICES), 3)
|
assert len(self.DEVICES) == 3
|
||||||
|
|
||||||
for device in self.DEVICES:
|
for device in self.DEVICES:
|
||||||
|
|
||||||
# Test pre data retrieval
|
# Test pre data retrieval
|
||||||
if device.subscription == '555555':
|
if device.subscription == '555555':
|
||||||
self.assertEqual('Vultr {}', device.name)
|
assert 'Vultr {}' == device.name
|
||||||
|
|
||||||
device.update()
|
device.update()
|
||||||
device_attrs = device.device_state_attributes
|
device_attrs = device.device_state_attributes
|
||||||
|
|
||||||
if device.subscription == '555555':
|
if device.subscription == '555555':
|
||||||
self.assertEqual('Vultr Another Server', device.name)
|
assert 'Vultr Another Server' == device.name
|
||||||
|
|
||||||
if device.name == 'A Server':
|
if device.name == 'A Server':
|
||||||
self.assertEqual(True, device.is_on)
|
assert device.is_on is True
|
||||||
self.assertEqual('power', device.device_class)
|
assert 'power' == device.device_class
|
||||||
self.assertEqual('on', device.state)
|
assert 'on' == device.state
|
||||||
self.assertEqual('mdi:server', device.icon)
|
assert 'mdi:server' == device.icon
|
||||||
self.assertEqual('1000',
|
assert '1000' == \
|
||||||
device_attrs[ATTR_ALLOWED_BANDWIDTH])
|
device_attrs[ATTR_ALLOWED_BANDWIDTH]
|
||||||
self.assertEqual('yes',
|
assert 'yes' == \
|
||||||
device_attrs[ATTR_AUTO_BACKUPS])
|
device_attrs[ATTR_AUTO_BACKUPS]
|
||||||
self.assertEqual('123.123.123.123',
|
assert '123.123.123.123' == \
|
||||||
device_attrs[ATTR_IPV4_ADDRESS])
|
device_attrs[ATTR_IPV4_ADDRESS]
|
||||||
self.assertEqual('10.05',
|
assert '10.05' == \
|
||||||
device_attrs[ATTR_COST_PER_MONTH])
|
device_attrs[ATTR_COST_PER_MONTH]
|
||||||
self.assertEqual('2013-12-19 14:45:41',
|
assert '2013-12-19 14:45:41' == \
|
||||||
device_attrs[ATTR_CREATED_AT])
|
device_attrs[ATTR_CREATED_AT]
|
||||||
self.assertEqual('576965',
|
assert '576965' == \
|
||||||
device_attrs[ATTR_SUBSCRIPTION_ID])
|
device_attrs[ATTR_SUBSCRIPTION_ID]
|
||||||
elif device.name == 'Failed Server':
|
elif device.name == 'Failed Server':
|
||||||
self.assertEqual(False, device.is_on)
|
assert device.is_on is False
|
||||||
self.assertEqual('off', device.state)
|
assert 'off' == device.state
|
||||||
self.assertEqual('mdi:server-off', device.icon)
|
assert 'mdi:server-off' == device.icon
|
||||||
self.assertEqual('1000',
|
assert '1000' == \
|
||||||
device_attrs[ATTR_ALLOWED_BANDWIDTH])
|
device_attrs[ATTR_ALLOWED_BANDWIDTH]
|
||||||
self.assertEqual('no',
|
assert 'no' == \
|
||||||
device_attrs[ATTR_AUTO_BACKUPS])
|
device_attrs[ATTR_AUTO_BACKUPS]
|
||||||
self.assertEqual('192.168.100.50',
|
assert '192.168.100.50' == \
|
||||||
device_attrs[ATTR_IPV4_ADDRESS])
|
device_attrs[ATTR_IPV4_ADDRESS]
|
||||||
self.assertEqual('73.25',
|
assert '73.25' == \
|
||||||
device_attrs[ATTR_COST_PER_MONTH])
|
device_attrs[ATTR_COST_PER_MONTH]
|
||||||
self.assertEqual('2014-10-13 14:45:41',
|
assert '2014-10-13 14:45:41' == \
|
||||||
device_attrs[ATTR_CREATED_AT])
|
device_attrs[ATTR_CREATED_AT]
|
||||||
self.assertEqual('123456',
|
assert '123456' == \
|
||||||
device_attrs[ATTR_SUBSCRIPTION_ID])
|
device_attrs[ATTR_SUBSCRIPTION_ID]
|
||||||
|
|
||||||
def test_invalid_sensor_config(self):
|
def test_invalid_sensor_config(self):
|
||||||
"""Test config type failures."""
|
"""Test config type failures."""
|
||||||
|
@ -150,7 +150,7 @@ class TestVultrBinarySensorSetup(unittest.TestCase):
|
||||||
self.add_entities,
|
self.add_entities,
|
||||||
None)
|
None)
|
||||||
|
|
||||||
self.assertFalse(no_subs_setup)
|
assert not no_subs_setup
|
||||||
|
|
||||||
bad_conf = {
|
bad_conf = {
|
||||||
CONF_NAME: "Missing Server",
|
CONF_NAME: "Missing Server",
|
||||||
|
@ -162,4 +162,4 @@ class TestVultrBinarySensorSetup(unittest.TestCase):
|
||||||
self.add_entities,
|
self.add_entities,
|
||||||
None)
|
None)
|
||||||
|
|
||||||
self.assertFalse(wrong_subs_setup)
|
assert not wrong_subs_setup
|
||||||
|
|
|
@ -178,10 +178,10 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
assert len(devices) == 2
|
assert len(devices) == 2
|
||||||
assert devices[0].name == "First"
|
assert devices[0].name == "First"
|
||||||
assert devices[0].dev_id == "First"
|
assert devices[0].dev_id == "First"
|
||||||
self.assertFalse(devices[0].data.include_all_day)
|
assert not devices[0].data.include_all_day
|
||||||
assert devices[1].name == "Second"
|
assert devices[1].name == "Second"
|
||||||
assert devices[1].dev_id == "Second"
|
assert devices[1].dev_id == "Second"
|
||||||
self.assertFalse(devices[1].data.include_all_day)
|
assert not devices[1].data.include_all_day
|
||||||
|
|
||||||
caldav.setup_platform(self.hass,
|
caldav.setup_platform(self.hass,
|
||||||
{
|
{
|
||||||
|
@ -226,7 +226,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
assert len(devices) == 1
|
assert len(devices) == 1
|
||||||
assert devices[0].name == "HomeOffice"
|
assert devices[0].name == "HomeOffice"
|
||||||
assert devices[0].dev_id == "Second HomeOffice"
|
assert devices[0].dev_id == "Second HomeOffice"
|
||||||
self.assertTrue(devices[0].data.include_all_day)
|
assert devices[0].data.include_all_day
|
||||||
|
|
||||||
caldav.setup_platform(self.hass,
|
caldav.setup_platform(self.hass,
|
||||||
{
|
{
|
||||||
|
@ -247,9 +247,9 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
DEVICE_DATA,
|
DEVICE_DATA,
|
||||||
self.calendar)
|
self.calendar)
|
||||||
|
|
||||||
self.assertEqual(cal.name, DEVICE_DATA["name"])
|
assert cal.name == DEVICE_DATA["name"]
|
||||||
self.assertEqual(cal.state, STATE_ON)
|
assert cal.state == STATE_ON
|
||||||
self.assertEqual(cal.device_state_attributes, {
|
assert cal.device_state_attributes == {
|
||||||
"message": "This is a normal event",
|
"message": "This is a normal event",
|
||||||
"all_day": False,
|
"all_day": False,
|
||||||
"offset_reached": False,
|
"offset_reached": False,
|
||||||
|
@ -257,7 +257,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
"end_time": "2017-11-27 18:00:00",
|
"end_time": "2017-11-27 18:00:00",
|
||||||
"location": "Hamburg",
|
"location": "Hamburg",
|
||||||
"description": "Surprisingly rainy",
|
"description": "Surprisingly rainy",
|
||||||
})
|
}
|
||||||
|
|
||||||
@patch('homeassistant.util.dt.now', return_value=_local_datetime(17, 30))
|
@patch('homeassistant.util.dt.now', return_value=_local_datetime(17, 30))
|
||||||
def test_just_ended_event(self, mock_now):
|
def test_just_ended_event(self, mock_now):
|
||||||
|
@ -266,9 +266,9 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
DEVICE_DATA,
|
DEVICE_DATA,
|
||||||
self.calendar)
|
self.calendar)
|
||||||
|
|
||||||
self.assertEqual(cal.name, DEVICE_DATA["name"])
|
assert cal.name == DEVICE_DATA["name"]
|
||||||
self.assertEqual(cal.state, STATE_ON)
|
assert cal.state == STATE_ON
|
||||||
self.assertEqual(cal.device_state_attributes, {
|
assert cal.device_state_attributes == {
|
||||||
"message": "This is a normal event",
|
"message": "This is a normal event",
|
||||||
"all_day": False,
|
"all_day": False,
|
||||||
"offset_reached": False,
|
"offset_reached": False,
|
||||||
|
@ -276,7 +276,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
"end_time": "2017-11-27 18:00:00",
|
"end_time": "2017-11-27 18:00:00",
|
||||||
"location": "Hamburg",
|
"location": "Hamburg",
|
||||||
"description": "Surprisingly rainy",
|
"description": "Surprisingly rainy",
|
||||||
})
|
}
|
||||||
|
|
||||||
@patch('homeassistant.util.dt.now', return_value=_local_datetime(17, 00))
|
@patch('homeassistant.util.dt.now', return_value=_local_datetime(17, 00))
|
||||||
def test_ongoing_event_different_tz(self, mock_now):
|
def test_ongoing_event_different_tz(self, mock_now):
|
||||||
|
@ -285,9 +285,9 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
DEVICE_DATA,
|
DEVICE_DATA,
|
||||||
self.calendar)
|
self.calendar)
|
||||||
|
|
||||||
self.assertEqual(cal.name, DEVICE_DATA["name"])
|
assert cal.name == DEVICE_DATA["name"]
|
||||||
self.assertEqual(cal.state, STATE_ON)
|
assert cal.state == STATE_ON
|
||||||
self.assertEqual(cal.device_state_attributes, {
|
assert cal.device_state_attributes == {
|
||||||
"message": "Enjoy the sun",
|
"message": "Enjoy the sun",
|
||||||
"all_day": False,
|
"all_day": False,
|
||||||
"offset_reached": False,
|
"offset_reached": False,
|
||||||
|
@ -295,7 +295,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
"description": "Sunny day",
|
"description": "Sunny day",
|
||||||
"end_time": "2017-11-27 17:30:00",
|
"end_time": "2017-11-27 17:30:00",
|
||||||
"location": "San Francisco",
|
"location": "San Francisco",
|
||||||
})
|
}
|
||||||
|
|
||||||
@patch('homeassistant.util.dt.now', return_value=_local_datetime(8, 30))
|
@patch('homeassistant.util.dt.now', return_value=_local_datetime(8, 30))
|
||||||
def test_ongoing_event_with_offset(self, mock_now):
|
def test_ongoing_event_with_offset(self, mock_now):
|
||||||
|
@ -304,8 +304,8 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
DEVICE_DATA,
|
DEVICE_DATA,
|
||||||
self.calendar)
|
self.calendar)
|
||||||
|
|
||||||
self.assertEqual(cal.state, STATE_OFF)
|
assert cal.state == STATE_OFF
|
||||||
self.assertEqual(cal.device_state_attributes, {
|
assert cal.device_state_attributes == {
|
||||||
"message": "This is an offset event",
|
"message": "This is an offset event",
|
||||||
"all_day": False,
|
"all_day": False,
|
||||||
"offset_reached": True,
|
"offset_reached": True,
|
||||||
|
@ -313,7 +313,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
"end_time": "2017-11-27 11:00:00",
|
"end_time": "2017-11-27 11:00:00",
|
||||||
"location": "Hamburg",
|
"location": "Hamburg",
|
||||||
"description": "Surprisingly shiny",
|
"description": "Surprisingly shiny",
|
||||||
})
|
}
|
||||||
|
|
||||||
@patch('homeassistant.util.dt.now', return_value=_local_datetime(12, 00))
|
@patch('homeassistant.util.dt.now', return_value=_local_datetime(12, 00))
|
||||||
def test_matching_filter(self, mock_now):
|
def test_matching_filter(self, mock_now):
|
||||||
|
@ -324,9 +324,9 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
False,
|
False,
|
||||||
"This is a normal event")
|
"This is a normal event")
|
||||||
|
|
||||||
self.assertEqual(cal.state, STATE_OFF)
|
assert cal.state == STATE_OFF
|
||||||
self.assertFalse(cal.offset_reached())
|
assert not cal.offset_reached()
|
||||||
self.assertEqual(cal.device_state_attributes, {
|
assert cal.device_state_attributes == {
|
||||||
"message": "This is a normal event",
|
"message": "This is a normal event",
|
||||||
"all_day": False,
|
"all_day": False,
|
||||||
"offset_reached": False,
|
"offset_reached": False,
|
||||||
|
@ -334,7 +334,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
"end_time": "2017-11-27 18:00:00",
|
"end_time": "2017-11-27 18:00:00",
|
||||||
"location": "Hamburg",
|
"location": "Hamburg",
|
||||||
"description": "Surprisingly rainy",
|
"description": "Surprisingly rainy",
|
||||||
})
|
}
|
||||||
|
|
||||||
@patch('homeassistant.util.dt.now', return_value=_local_datetime(12, 00))
|
@patch('homeassistant.util.dt.now', return_value=_local_datetime(12, 00))
|
||||||
def test_matching_filter_real_regexp(self, mock_now):
|
def test_matching_filter_real_regexp(self, mock_now):
|
||||||
|
@ -345,9 +345,9 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
False,
|
False,
|
||||||
"^This.*event")
|
"^This.*event")
|
||||||
|
|
||||||
self.assertEqual(cal.state, STATE_OFF)
|
assert cal.state == STATE_OFF
|
||||||
self.assertFalse(cal.offset_reached())
|
assert not cal.offset_reached()
|
||||||
self.assertEqual(cal.device_state_attributes, {
|
assert cal.device_state_attributes == {
|
||||||
"message": "This is a normal event",
|
"message": "This is a normal event",
|
||||||
"all_day": False,
|
"all_day": False,
|
||||||
"offset_reached": False,
|
"offset_reached": False,
|
||||||
|
@ -355,7 +355,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
"end_time": "2017-11-27 18:00:00",
|
"end_time": "2017-11-27 18:00:00",
|
||||||
"location": "Hamburg",
|
"location": "Hamburg",
|
||||||
"description": "Surprisingly rainy",
|
"description": "Surprisingly rainy",
|
||||||
})
|
}
|
||||||
|
|
||||||
@patch('homeassistant.util.dt.now', return_value=_local_datetime(20, 00))
|
@patch('homeassistant.util.dt.now', return_value=_local_datetime(20, 00))
|
||||||
def test_filter_matching_past_event(self, mock_now):
|
def test_filter_matching_past_event(self, mock_now):
|
||||||
|
@ -366,7 +366,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
False,
|
False,
|
||||||
"This is a normal event")
|
"This is a normal event")
|
||||||
|
|
||||||
self.assertEqual(cal.data.event, None)
|
assert cal.data.event is None
|
||||||
|
|
||||||
@patch('homeassistant.util.dt.now', return_value=_local_datetime(12, 00))
|
@patch('homeassistant.util.dt.now', return_value=_local_datetime(12, 00))
|
||||||
def test_no_result_with_filtering(self, mock_now):
|
def test_no_result_with_filtering(self, mock_now):
|
||||||
|
@ -377,7 +377,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
False,
|
False,
|
||||||
"This is a non-existing event")
|
"This is a non-existing event")
|
||||||
|
|
||||||
self.assertEqual(cal.data.event, None)
|
assert cal.data.event is None
|
||||||
|
|
||||||
@patch('homeassistant.util.dt.now', return_value=_local_datetime(17, 30))
|
@patch('homeassistant.util.dt.now', return_value=_local_datetime(17, 30))
|
||||||
def test_all_day_event_returned(self, mock_now):
|
def test_all_day_event_returned(self, mock_now):
|
||||||
|
@ -387,9 +387,9 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
self.calendar,
|
self.calendar,
|
||||||
True)
|
True)
|
||||||
|
|
||||||
self.assertEqual(cal.name, DEVICE_DATA["name"])
|
assert cal.name == DEVICE_DATA["name"]
|
||||||
self.assertEqual(cal.state, STATE_ON)
|
assert cal.state == STATE_ON
|
||||||
self.assertEqual(cal.device_state_attributes, {
|
assert cal.device_state_attributes == {
|
||||||
"message": "This is an all day event",
|
"message": "This is an all day event",
|
||||||
"all_day": True,
|
"all_day": True,
|
||||||
"offset_reached": False,
|
"offset_reached": False,
|
||||||
|
@ -397,4 +397,4 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
|
||||||
"end_time": "2017-11-28 00:00:00",
|
"end_time": "2017-11-28 00:00:00",
|
||||||
"location": "Hamburg",
|
"location": "Hamburg",
|
||||||
"description": "What a beautiful day",
|
"description": "What a beautiful day",
|
||||||
})
|
}
|
||||||
|
|
|
@ -87,13 +87,13 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
|
||||||
cal = calendar.GoogleCalendarEventDevice(self.hass, None,
|
cal = calendar.GoogleCalendarEventDevice(self.hass, None,
|
||||||
'', {'name': device_name})
|
'', {'name': device_name})
|
||||||
|
|
||||||
self.assertEqual(cal.name, device_name)
|
assert cal.name == device_name
|
||||||
|
|
||||||
self.assertEqual(cal.state, STATE_OFF)
|
assert cal.state == STATE_OFF
|
||||||
|
|
||||||
self.assertFalse(cal.offset_reached())
|
assert not cal.offset_reached()
|
||||||
|
|
||||||
self.assertEqual(cal.device_state_attributes, {
|
assert cal.device_state_attributes == {
|
||||||
'message': event['summary'],
|
'message': event['summary'],
|
||||||
'all_day': True,
|
'all_day': True,
|
||||||
'offset_reached': False,
|
'offset_reached': False,
|
||||||
|
@ -101,7 +101,7 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
|
||||||
'end_time': '{} 00:00:00'.format(event['end']['date']),
|
'end_time': '{} 00:00:00'.format(event['end']['date']),
|
||||||
'location': event['location'],
|
'location': event['location'],
|
||||||
'description': event['description'],
|
'description': event['description'],
|
||||||
})
|
}
|
||||||
|
|
||||||
@patch('homeassistant.components.calendar.google.GoogleCalendarData')
|
@patch('homeassistant.components.calendar.google.GoogleCalendarData')
|
||||||
def test_future_event(self, mock_next_event):
|
def test_future_event(self, mock_next_event):
|
||||||
|
@ -146,13 +146,13 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
|
||||||
cal = calendar.GoogleCalendarEventDevice(self.hass, None, device_id,
|
cal = calendar.GoogleCalendarEventDevice(self.hass, None, device_id,
|
||||||
{'name': device_name})
|
{'name': device_name})
|
||||||
|
|
||||||
self.assertEqual(cal.name, device_name)
|
assert cal.name == device_name
|
||||||
|
|
||||||
self.assertEqual(cal.state, STATE_OFF)
|
assert cal.state == STATE_OFF
|
||||||
|
|
||||||
self.assertFalse(cal.offset_reached())
|
assert not cal.offset_reached()
|
||||||
|
|
||||||
self.assertEqual(cal.device_state_attributes, {
|
assert cal.device_state_attributes == {
|
||||||
'message': event['summary'],
|
'message': event['summary'],
|
||||||
'all_day': False,
|
'all_day': False,
|
||||||
'offset_reached': False,
|
'offset_reached': False,
|
||||||
|
@ -162,7 +162,7 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
|
||||||
.strftime(DATE_STR_FORMAT),
|
.strftime(DATE_STR_FORMAT),
|
||||||
'location': '',
|
'location': '',
|
||||||
'description': '',
|
'description': '',
|
||||||
})
|
}
|
||||||
|
|
||||||
@patch('homeassistant.components.calendar.google.GoogleCalendarData')
|
@patch('homeassistant.components.calendar.google.GoogleCalendarData')
|
||||||
def test_in_progress_event(self, mock_next_event):
|
def test_in_progress_event(self, mock_next_event):
|
||||||
|
@ -208,13 +208,13 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
|
||||||
cal = calendar.GoogleCalendarEventDevice(self.hass, None, device_id,
|
cal = calendar.GoogleCalendarEventDevice(self.hass, None, device_id,
|
||||||
{'name': device_name})
|
{'name': device_name})
|
||||||
|
|
||||||
self.assertEqual(cal.name, device_name)
|
assert cal.name == device_name
|
||||||
|
|
||||||
self.assertEqual(cal.state, STATE_ON)
|
assert cal.state == STATE_ON
|
||||||
|
|
||||||
self.assertFalse(cal.offset_reached())
|
assert not cal.offset_reached()
|
||||||
|
|
||||||
self.assertEqual(cal.device_state_attributes, {
|
assert cal.device_state_attributes == {
|
||||||
'message': event['summary'],
|
'message': event['summary'],
|
||||||
'all_day': False,
|
'all_day': False,
|
||||||
'offset_reached': False,
|
'offset_reached': False,
|
||||||
|
@ -224,7 +224,7 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
|
||||||
.strftime(DATE_STR_FORMAT),
|
.strftime(DATE_STR_FORMAT),
|
||||||
'location': '',
|
'location': '',
|
||||||
'description': '',
|
'description': '',
|
||||||
})
|
}
|
||||||
|
|
||||||
@patch('homeassistant.components.calendar.google.GoogleCalendarData')
|
@patch('homeassistant.components.calendar.google.GoogleCalendarData')
|
||||||
def test_offset_in_progress_event(self, mock_next_event):
|
def test_offset_in_progress_event(self, mock_next_event):
|
||||||
|
@ -271,13 +271,13 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
|
||||||
cal = calendar.GoogleCalendarEventDevice(self.hass, None, device_id,
|
cal = calendar.GoogleCalendarEventDevice(self.hass, None, device_id,
|
||||||
{'name': device_name})
|
{'name': device_name})
|
||||||
|
|
||||||
self.assertEqual(cal.name, device_name)
|
assert cal.name == device_name
|
||||||
|
|
||||||
self.assertEqual(cal.state, STATE_OFF)
|
assert cal.state == STATE_OFF
|
||||||
|
|
||||||
self.assertTrue(cal.offset_reached())
|
assert cal.offset_reached()
|
||||||
|
|
||||||
self.assertEqual(cal.device_state_attributes, {
|
assert cal.device_state_attributes == {
|
||||||
'message': event_summary,
|
'message': event_summary,
|
||||||
'all_day': False,
|
'all_day': False,
|
||||||
'offset_reached': True,
|
'offset_reached': True,
|
||||||
|
@ -287,7 +287,7 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
|
||||||
.strftime(DATE_STR_FORMAT),
|
.strftime(DATE_STR_FORMAT),
|
||||||
'location': '',
|
'location': '',
|
||||||
'description': '',
|
'description': '',
|
||||||
})
|
}
|
||||||
|
|
||||||
@pytest.mark.skip
|
@pytest.mark.skip
|
||||||
@patch('homeassistant.components.calendar.google.GoogleCalendarData')
|
@patch('homeassistant.components.calendar.google.GoogleCalendarData')
|
||||||
|
@ -340,13 +340,13 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
|
||||||
cal = calendar.GoogleCalendarEventDevice(self.hass, None, device_id,
|
cal = calendar.GoogleCalendarEventDevice(self.hass, None, device_id,
|
||||||
{'name': device_name})
|
{'name': device_name})
|
||||||
|
|
||||||
self.assertEqual(cal.name, device_name)
|
assert cal.name == device_name
|
||||||
|
|
||||||
self.assertEqual(cal.state, STATE_OFF)
|
assert cal.state == STATE_OFF
|
||||||
|
|
||||||
self.assertTrue(cal.offset_reached())
|
assert cal.offset_reached()
|
||||||
|
|
||||||
self.assertEqual(cal.device_state_attributes, {
|
assert cal.device_state_attributes == {
|
||||||
'message': event_summary,
|
'message': event_summary,
|
||||||
'all_day': True,
|
'all_day': True,
|
||||||
'offset_reached': True,
|
'offset_reached': True,
|
||||||
|
@ -354,7 +354,7 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
|
||||||
'end_time': '{} 06:00:00'.format(event['end']['date']),
|
'end_time': '{} 06:00:00'.format(event['end']['date']),
|
||||||
'location': event['location'],
|
'location': event['location'],
|
||||||
'description': event['description'],
|
'description': event['description'],
|
||||||
})
|
}
|
||||||
|
|
||||||
@patch('homeassistant.components.calendar.google.GoogleCalendarData')
|
@patch('homeassistant.components.calendar.google.GoogleCalendarData')
|
||||||
def test_all_day_offset_event(self, mock_next_event):
|
def test_all_day_offset_event(self, mock_next_event):
|
||||||
|
@ -407,13 +407,13 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
|
||||||
cal = calendar.GoogleCalendarEventDevice(self.hass, None, device_id,
|
cal = calendar.GoogleCalendarEventDevice(self.hass, None, device_id,
|
||||||
{'name': device_name})
|
{'name': device_name})
|
||||||
|
|
||||||
self.assertEqual(cal.name, device_name)
|
assert cal.name == device_name
|
||||||
|
|
||||||
self.assertEqual(cal.state, STATE_OFF)
|
assert cal.state == STATE_OFF
|
||||||
|
|
||||||
self.assertFalse(cal.offset_reached())
|
assert not cal.offset_reached()
|
||||||
|
|
||||||
self.assertEqual(cal.device_state_attributes, {
|
assert cal.device_state_attributes == {
|
||||||
'message': event_summary,
|
'message': event_summary,
|
||||||
'all_day': True,
|
'all_day': True,
|
||||||
'offset_reached': False,
|
'offset_reached': False,
|
||||||
|
@ -421,7 +421,7 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
|
||||||
'end_time': '{} 00:00:00'.format(event['end']['date']),
|
'end_time': '{} 00:00:00'.format(event['end']['date']),
|
||||||
'location': event['location'],
|
'location': event['location'],
|
||||||
'description': event['description'],
|
'description': event['description'],
|
||||||
})
|
}
|
||||||
|
|
||||||
@MockDependency("httplib2")
|
@MockDependency("httplib2")
|
||||||
def test_update_false(self, mock_httplib2):
|
def test_update_false(self, mock_httplib2):
|
||||||
|
@ -434,4 +434,4 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
|
||||||
{'name': "test"})
|
{'name': "test"})
|
||||||
result = cal.data.update()
|
result = cal.data.update()
|
||||||
|
|
||||||
self.assertFalse(result)
|
assert not result
|
||||||
|
|
|
@ -11,6 +11,7 @@ from homeassistant.exceptions import PlatformNotReady
|
||||||
from homeassistant.setup import setup_component
|
from homeassistant.setup import setup_component
|
||||||
from homeassistant.components.camera import uvc
|
from homeassistant.components.camera import uvc
|
||||||
from tests.common import get_test_home_assistant
|
from tests.common import get_test_home_assistant
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
class TestUVCSetup(unittest.TestCase):
|
class TestUVCSetup(unittest.TestCase):
|
||||||
|
@ -53,10 +54,8 @@ class TestUVCSetup(unittest.TestCase):
|
||||||
|
|
||||||
assert setup_component(self.hass, 'camera', {'camera': config})
|
assert setup_component(self.hass, 'camera', {'camera': config})
|
||||||
|
|
||||||
self.assertEqual(mock_remote.call_count, 1)
|
assert mock_remote.call_count == 1
|
||||||
self.assertEqual(
|
assert mock_remote.call_args == mock.call('foo', 123, 'secret')
|
||||||
mock_remote.call_args, mock.call('foo', 123, 'secret')
|
|
||||||
)
|
|
||||||
mock_uvc.assert_has_calls([
|
mock_uvc.assert_has_calls([
|
||||||
mock.call(mock_remote.return_value, 'id1', 'Front', 'bar'),
|
mock.call(mock_remote.return_value, 'id1', 'Front', 'bar'),
|
||||||
mock.call(mock_remote.return_value, 'id2', 'Back', 'bar'),
|
mock.call(mock_remote.return_value, 'id2', 'Back', 'bar'),
|
||||||
|
@ -81,10 +80,8 @@ class TestUVCSetup(unittest.TestCase):
|
||||||
|
|
||||||
assert setup_component(self.hass, 'camera', {'camera': config})
|
assert setup_component(self.hass, 'camera', {'camera': config})
|
||||||
|
|
||||||
self.assertEqual(mock_remote.call_count, 1)
|
assert mock_remote.call_count == 1
|
||||||
self.assertEqual(
|
assert mock_remote.call_args == mock.call('foo', 7080, 'secret')
|
||||||
mock_remote.call_args, mock.call('foo', 7080, 'secret')
|
|
||||||
)
|
|
||||||
mock_uvc.assert_has_calls([
|
mock_uvc.assert_has_calls([
|
||||||
mock.call(mock_remote.return_value, 'id1', 'Front', 'ubnt'),
|
mock.call(mock_remote.return_value, 'id1', 'Front', 'ubnt'),
|
||||||
mock.call(mock_remote.return_value, 'id2', 'Back', 'ubnt'),
|
mock.call(mock_remote.return_value, 'id2', 'Back', 'ubnt'),
|
||||||
|
@ -109,10 +106,8 @@ class TestUVCSetup(unittest.TestCase):
|
||||||
|
|
||||||
assert setup_component(self.hass, 'camera', {'camera': config})
|
assert setup_component(self.hass, 'camera', {'camera': config})
|
||||||
|
|
||||||
self.assertEqual(mock_remote.call_count, 1)
|
assert mock_remote.call_count == 1
|
||||||
self.assertEqual(
|
assert mock_remote.call_args == mock.call('foo', 7080, 'secret')
|
||||||
mock_remote.call_args, mock.call('foo', 7080, 'secret')
|
|
||||||
)
|
|
||||||
mock_uvc.assert_has_calls([
|
mock_uvc.assert_has_calls([
|
||||||
mock.call(mock_remote.return_value, 'one', 'Front', 'ubnt'),
|
mock.call(mock_remote.return_value, 'one', 'Front', 'ubnt'),
|
||||||
mock.call(mock_remote.return_value, 'two', 'Back', 'ubnt'),
|
mock.call(mock_remote.return_value, 'two', 'Back', 'ubnt'),
|
||||||
|
@ -151,13 +146,13 @@ class TestUVCSetup(unittest.TestCase):
|
||||||
def test_setup_nvr_error_during_indexing_nvrerror(self):
|
def test_setup_nvr_error_during_indexing_nvrerror(self):
|
||||||
"""Test for error: nvr.NvrError."""
|
"""Test for error: nvr.NvrError."""
|
||||||
self.setup_nvr_errors_during_indexing(nvr.NvrError)
|
self.setup_nvr_errors_during_indexing(nvr.NvrError)
|
||||||
self.assertRaises(PlatformNotReady)
|
pytest.raises(PlatformNotReady)
|
||||||
|
|
||||||
def test_setup_nvr_error_during_indexing_connectionerror(self):
|
def test_setup_nvr_error_during_indexing_connectionerror(self):
|
||||||
"""Test for error: requests.exceptions.ConnectionError."""
|
"""Test for error: requests.exceptions.ConnectionError."""
|
||||||
self.setup_nvr_errors_during_indexing(
|
self.setup_nvr_errors_during_indexing(
|
||||||
requests.exceptions.ConnectionError)
|
requests.exceptions.ConnectionError)
|
||||||
self.assertRaises(PlatformNotReady)
|
pytest.raises(PlatformNotReady)
|
||||||
|
|
||||||
@mock.patch.object(uvc, 'UnifiVideoCamera')
|
@mock.patch.object(uvc, 'UnifiVideoCamera')
|
||||||
@mock.patch('uvcclient.nvr.UVCRemote.__init__')
|
@mock.patch('uvcclient.nvr.UVCRemote.__init__')
|
||||||
|
@ -182,13 +177,13 @@ class TestUVCSetup(unittest.TestCase):
|
||||||
def test_setup_nvr_error_during_initialization_nvrerror(self):
|
def test_setup_nvr_error_during_initialization_nvrerror(self):
|
||||||
"""Test for error: nvr.NvrError."""
|
"""Test for error: nvr.NvrError."""
|
||||||
self.setup_nvr_errors_during_initialization(nvr.NvrError)
|
self.setup_nvr_errors_during_initialization(nvr.NvrError)
|
||||||
self.assertRaises(PlatformNotReady)
|
pytest.raises(PlatformNotReady)
|
||||||
|
|
||||||
def test_setup_nvr_error_during_initialization_connectionerror(self):
|
def test_setup_nvr_error_during_initialization_connectionerror(self):
|
||||||
"""Test for error: requests.exceptions.ConnectionError."""
|
"""Test for error: requests.exceptions.ConnectionError."""
|
||||||
self.setup_nvr_errors_during_initialization(
|
self.setup_nvr_errors_during_initialization(
|
||||||
requests.exceptions.ConnectionError)
|
requests.exceptions.ConnectionError)
|
||||||
self.assertRaises(PlatformNotReady)
|
pytest.raises(PlatformNotReady)
|
||||||
|
|
||||||
|
|
||||||
class TestUVC(unittest.TestCase):
|
class TestUVC(unittest.TestCase):
|
||||||
|
@ -215,22 +210,20 @@ class TestUVC(unittest.TestCase):
|
||||||
|
|
||||||
def test_properties(self):
|
def test_properties(self):
|
||||||
"""Test the properties."""
|
"""Test the properties."""
|
||||||
self.assertEqual(self.name, self.uvc.name)
|
assert self.name == self.uvc.name
|
||||||
self.assertTrue(self.uvc.is_recording)
|
assert self.uvc.is_recording
|
||||||
self.assertEqual('Ubiquiti', self.uvc.brand)
|
assert 'Ubiquiti' == self.uvc.brand
|
||||||
self.assertEqual('UVC Fake', self.uvc.model)
|
assert 'UVC Fake' == self.uvc.model
|
||||||
|
|
||||||
@mock.patch('uvcclient.store.get_info_store')
|
@mock.patch('uvcclient.store.get_info_store')
|
||||||
@mock.patch('uvcclient.camera.UVCCameraClientV320')
|
@mock.patch('uvcclient.camera.UVCCameraClientV320')
|
||||||
def test_login(self, mock_camera, mock_store):
|
def test_login(self, mock_camera, mock_store):
|
||||||
"""Test the login."""
|
"""Test the login."""
|
||||||
self.uvc._login()
|
self.uvc._login()
|
||||||
self.assertEqual(mock_camera.call_count, 1)
|
assert mock_camera.call_count == 1
|
||||||
self.assertEqual(
|
assert mock_camera.call_args == mock.call('host-a', 'admin', 'seekret')
|
||||||
mock_camera.call_args, mock.call('host-a', 'admin', 'seekret')
|
assert mock_camera.return_value.login.call_count == 1
|
||||||
)
|
assert mock_camera.return_value.login.call_args == mock.call()
|
||||||
self.assertEqual(mock_camera.return_value.login.call_count, 1)
|
|
||||||
self.assertEqual(mock_camera.return_value.login.call_args, mock.call())
|
|
||||||
|
|
||||||
@mock.patch('uvcclient.store.get_info_store')
|
@mock.patch('uvcclient.store.get_info_store')
|
||||||
@mock.patch('uvcclient.camera.UVCCameraClient')
|
@mock.patch('uvcclient.camera.UVCCameraClient')
|
||||||
|
@ -238,12 +231,10 @@ class TestUVC(unittest.TestCase):
|
||||||
"""Test login with v3.1.x server."""
|
"""Test login with v3.1.x server."""
|
||||||
self.nvr.server_version = (3, 1, 3)
|
self.nvr.server_version = (3, 1, 3)
|
||||||
self.uvc._login()
|
self.uvc._login()
|
||||||
self.assertEqual(mock_camera.call_count, 1)
|
assert mock_camera.call_count == 1
|
||||||
self.assertEqual(
|
assert mock_camera.call_args == mock.call('host-a', 'admin', 'seekret')
|
||||||
mock_camera.call_args, mock.call('host-a', 'admin', 'seekret')
|
assert mock_camera.return_value.login.call_count == 1
|
||||||
)
|
assert mock_camera.return_value.login.call_args == mock.call()
|
||||||
self.assertEqual(mock_camera.return_value.login.call_count, 1)
|
|
||||||
self.assertEqual(mock_camera.return_value.login.call_args, mock.call())
|
|
||||||
|
|
||||||
@mock.patch('uvcclient.store.get_info_store')
|
@mock.patch('uvcclient.store.get_info_store')
|
||||||
@mock.patch('uvcclient.camera.UVCCameraClientV320')
|
@mock.patch('uvcclient.camera.UVCCameraClientV320')
|
||||||
|
@ -262,45 +253,43 @@ class TestUVC(unittest.TestCase):
|
||||||
mock_store.return_value.get_camera_password.return_value = None
|
mock_store.return_value.get_camera_password.return_value = None
|
||||||
mock_camera.return_value.login.side_effect = mock_login
|
mock_camera.return_value.login.side_effect = mock_login
|
||||||
self.uvc._login()
|
self.uvc._login()
|
||||||
self.assertEqual(2, mock_camera.call_count)
|
assert 2 == mock_camera.call_count
|
||||||
self.assertEqual('host-b', self.uvc._connect_addr)
|
assert 'host-b' == self.uvc._connect_addr
|
||||||
|
|
||||||
mock_camera.reset_mock()
|
mock_camera.reset_mock()
|
||||||
self.uvc._login()
|
self.uvc._login()
|
||||||
self.assertEqual(mock_camera.call_count, 1)
|
assert mock_camera.call_count == 1
|
||||||
self.assertEqual(
|
assert mock_camera.call_args == mock.call('host-b', 'admin', 'seekret')
|
||||||
mock_camera.call_args, mock.call('host-b', 'admin', 'seekret')
|
assert mock_camera.return_value.login.call_count == 1
|
||||||
)
|
assert mock_camera.return_value.login.call_args == mock.call()
|
||||||
self.assertEqual(mock_camera.return_value.login.call_count, 1)
|
|
||||||
self.assertEqual(mock_camera.return_value.login.call_args, mock.call())
|
|
||||||
|
|
||||||
@mock.patch('uvcclient.store.get_info_store')
|
@mock.patch('uvcclient.store.get_info_store')
|
||||||
@mock.patch('uvcclient.camera.UVCCameraClientV320')
|
@mock.patch('uvcclient.camera.UVCCameraClientV320')
|
||||||
def test_login_fails_both_properly(self, mock_camera, mock_store):
|
def test_login_fails_both_properly(self, mock_camera, mock_store):
|
||||||
"""Test if login fails properly."""
|
"""Test if login fails properly."""
|
||||||
mock_camera.return_value.login.side_effect = socket.error
|
mock_camera.return_value.login.side_effect = socket.error
|
||||||
self.assertEqual(None, self.uvc._login())
|
assert self.uvc._login() is None
|
||||||
self.assertEqual(None, self.uvc._connect_addr)
|
assert self.uvc._connect_addr is None
|
||||||
|
|
||||||
def test_camera_image_tries_login_bails_on_failure(self):
|
def test_camera_image_tries_login_bails_on_failure(self):
|
||||||
"""Test retrieving failure."""
|
"""Test retrieving failure."""
|
||||||
with mock.patch.object(self.uvc, '_login') as mock_login:
|
with mock.patch.object(self.uvc, '_login') as mock_login:
|
||||||
mock_login.return_value = False
|
mock_login.return_value = False
|
||||||
self.assertEqual(None, self.uvc.camera_image())
|
assert self.uvc.camera_image() is None
|
||||||
self.assertEqual(mock_login.call_count, 1)
|
assert mock_login.call_count == 1
|
||||||
self.assertEqual(mock_login.call_args, mock.call())
|
assert mock_login.call_args == mock.call()
|
||||||
|
|
||||||
def test_camera_image_logged_in(self):
|
def test_camera_image_logged_in(self):
|
||||||
"""Test the login state."""
|
"""Test the login state."""
|
||||||
self.uvc._camera = mock.MagicMock()
|
self.uvc._camera = mock.MagicMock()
|
||||||
self.assertEqual(self.uvc._camera.get_snapshot.return_value,
|
assert self.uvc._camera.get_snapshot.return_value == \
|
||||||
self.uvc.camera_image())
|
self.uvc.camera_image()
|
||||||
|
|
||||||
def test_camera_image_error(self):
|
def test_camera_image_error(self):
|
||||||
"""Test the camera image error."""
|
"""Test the camera image error."""
|
||||||
self.uvc._camera = mock.MagicMock()
|
self.uvc._camera = mock.MagicMock()
|
||||||
self.uvc._camera.get_snapshot.side_effect = camera.CameraConnectError
|
self.uvc._camera.get_snapshot.side_effect = camera.CameraConnectError
|
||||||
self.assertEqual(None, self.uvc.camera_image())
|
assert self.uvc.camera_image() is None
|
||||||
|
|
||||||
def test_camera_image_reauths(self):
|
def test_camera_image_reauths(self):
|
||||||
"""Test the re-authentication."""
|
"""Test the re-authentication."""
|
||||||
|
@ -318,16 +307,17 @@ class TestUVC(unittest.TestCase):
|
||||||
self.uvc._camera = mock.MagicMock()
|
self.uvc._camera = mock.MagicMock()
|
||||||
self.uvc._camera.get_snapshot.side_effect = mock_snapshot
|
self.uvc._camera.get_snapshot.side_effect = mock_snapshot
|
||||||
with mock.patch.object(self.uvc, '_login') as mock_login:
|
with mock.patch.object(self.uvc, '_login') as mock_login:
|
||||||
self.assertEqual('image', self.uvc.camera_image())
|
assert 'image' == self.uvc.camera_image()
|
||||||
self.assertEqual(mock_login.call_count, 1)
|
assert mock_login.call_count == 1
|
||||||
self.assertEqual(mock_login.call_args, mock.call())
|
assert mock_login.call_args == mock.call()
|
||||||
self.assertEqual([], responses)
|
assert [] == responses
|
||||||
|
|
||||||
def test_camera_image_reauths_only_once(self):
|
def test_camera_image_reauths_only_once(self):
|
||||||
"""Test if the re-authentication only happens once."""
|
"""Test if the re-authentication only happens once."""
|
||||||
self.uvc._camera = mock.MagicMock()
|
self.uvc._camera = mock.MagicMock()
|
||||||
self.uvc._camera.get_snapshot.side_effect = camera.CameraAuthError
|
self.uvc._camera.get_snapshot.side_effect = camera.CameraAuthError
|
||||||
with mock.patch.object(self.uvc, '_login') as mock_login:
|
with mock.patch.object(self.uvc, '_login') as mock_login:
|
||||||
self.assertRaises(camera.CameraAuthError, self.uvc.camera_image)
|
with pytest.raises(camera.CameraAuthError):
|
||||||
self.assertEqual(mock_login.call_count, 1)
|
self.uvc.camera_image()
|
||||||
self.assertEqual(mock_login.call_args, mock.call())
|
assert mock_login.call_count == 1
|
||||||
|
assert mock_login.call_args == mock.call()
|
||||||
|
|
|
@ -23,10 +23,10 @@ class TestDemoClimate(unittest.TestCase):
|
||||||
"""Set up things to be run when tests are started."""
|
"""Set up things to be run when tests are started."""
|
||||||
self.hass = get_test_home_assistant()
|
self.hass = get_test_home_assistant()
|
||||||
self.hass.config.units = METRIC_SYSTEM
|
self.hass.config.units = METRIC_SYSTEM
|
||||||
self.assertTrue(setup_component(self.hass, climate.DOMAIN, {
|
assert setup_component(self.hass, climate.DOMAIN, {
|
||||||
'climate': {
|
'climate': {
|
||||||
'platform': 'demo',
|
'platform': 'demo',
|
||||||
}}))
|
}})
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
"""Stop down everything that was started."""
|
"""Stop down everything that was started."""
|
||||||
|
@ -35,132 +35,132 @@ class TestDemoClimate(unittest.TestCase):
|
||||||
def test_setup_params(self):
|
def test_setup_params(self):
|
||||||
"""Test the initial parameters."""
|
"""Test the initial parameters."""
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(21, state.attributes.get('temperature'))
|
assert 21 == state.attributes.get('temperature')
|
||||||
self.assertEqual('on', state.attributes.get('away_mode'))
|
assert 'on' == state.attributes.get('away_mode')
|
||||||
self.assertEqual(22, state.attributes.get('current_temperature'))
|
assert 22 == state.attributes.get('current_temperature')
|
||||||
self.assertEqual("On High", state.attributes.get('fan_mode'))
|
assert "On High" == state.attributes.get('fan_mode')
|
||||||
self.assertEqual(67, state.attributes.get('humidity'))
|
assert 67 == state.attributes.get('humidity')
|
||||||
self.assertEqual(54, state.attributes.get('current_humidity'))
|
assert 54 == state.attributes.get('current_humidity')
|
||||||
self.assertEqual("Off", state.attributes.get('swing_mode'))
|
assert "Off" == state.attributes.get('swing_mode')
|
||||||
self.assertEqual("cool", state.attributes.get('operation_mode'))
|
assert "cool" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
assert 'off' == state.attributes.get('aux_heat')
|
||||||
|
|
||||||
def test_default_setup_params(self):
|
def test_default_setup_params(self):
|
||||||
"""Test the setup with default parameters."""
|
"""Test the setup with default parameters."""
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(7, state.attributes.get('min_temp'))
|
assert 7 == state.attributes.get('min_temp')
|
||||||
self.assertEqual(35, state.attributes.get('max_temp'))
|
assert 35 == state.attributes.get('max_temp')
|
||||||
self.assertEqual(30, state.attributes.get('min_humidity'))
|
assert 30 == state.attributes.get('min_humidity')
|
||||||
self.assertEqual(99, state.attributes.get('max_humidity'))
|
assert 99 == state.attributes.get('max_humidity')
|
||||||
|
|
||||||
def test_set_only_target_temp_bad_attr(self):
|
def test_set_only_target_temp_bad_attr(self):
|
||||||
"""Test setting the target temperature without required attribute."""
|
"""Test setting the target temperature without required attribute."""
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(21, state.attributes.get('temperature'))
|
assert 21 == state.attributes.get('temperature')
|
||||||
common.set_temperature(self.hass, None, ENTITY_CLIMATE)
|
common.set_temperature(self.hass, None, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(21, state.attributes.get('temperature'))
|
assert 21 == state.attributes.get('temperature')
|
||||||
|
|
||||||
def test_set_only_target_temp(self):
|
def test_set_only_target_temp(self):
|
||||||
"""Test the setting of the target temperature."""
|
"""Test the setting of the target temperature."""
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(21, state.attributes.get('temperature'))
|
assert 21 == state.attributes.get('temperature')
|
||||||
common.set_temperature(self.hass, 30, ENTITY_CLIMATE)
|
common.set_temperature(self.hass, 30, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(30.0, state.attributes.get('temperature'))
|
assert 30.0 == state.attributes.get('temperature')
|
||||||
|
|
||||||
def test_set_only_target_temp_with_convert(self):
|
def test_set_only_target_temp_with_convert(self):
|
||||||
"""Test the setting of the target temperature."""
|
"""Test the setting of the target temperature."""
|
||||||
state = self.hass.states.get(ENTITY_HEATPUMP)
|
state = self.hass.states.get(ENTITY_HEATPUMP)
|
||||||
self.assertEqual(20, state.attributes.get('temperature'))
|
assert 20 == state.attributes.get('temperature')
|
||||||
common.set_temperature(self.hass, 21, ENTITY_HEATPUMP)
|
common.set_temperature(self.hass, 21, ENTITY_HEATPUMP)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_HEATPUMP)
|
state = self.hass.states.get(ENTITY_HEATPUMP)
|
||||||
self.assertEqual(21.0, state.attributes.get('temperature'))
|
assert 21.0 == state.attributes.get('temperature')
|
||||||
|
|
||||||
def test_set_target_temp_range(self):
|
def test_set_target_temp_range(self):
|
||||||
"""Test the setting of the target temperature with range."""
|
"""Test the setting of the target temperature with range."""
|
||||||
state = self.hass.states.get(ENTITY_ECOBEE)
|
state = self.hass.states.get(ENTITY_ECOBEE)
|
||||||
self.assertEqual(None, state.attributes.get('temperature'))
|
assert state.attributes.get('temperature') is None
|
||||||
self.assertEqual(21.0, state.attributes.get('target_temp_low'))
|
assert 21.0 == state.attributes.get('target_temp_low')
|
||||||
self.assertEqual(24.0, state.attributes.get('target_temp_high'))
|
assert 24.0 == state.attributes.get('target_temp_high')
|
||||||
common.set_temperature(self.hass, target_temp_high=25,
|
common.set_temperature(self.hass, target_temp_high=25,
|
||||||
target_temp_low=20, entity_id=ENTITY_ECOBEE)
|
target_temp_low=20, entity_id=ENTITY_ECOBEE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_ECOBEE)
|
state = self.hass.states.get(ENTITY_ECOBEE)
|
||||||
self.assertEqual(None, state.attributes.get('temperature'))
|
assert state.attributes.get('temperature') is None
|
||||||
self.assertEqual(20.0, state.attributes.get('target_temp_low'))
|
assert 20.0 == state.attributes.get('target_temp_low')
|
||||||
self.assertEqual(25.0, state.attributes.get('target_temp_high'))
|
assert 25.0 == state.attributes.get('target_temp_high')
|
||||||
|
|
||||||
def test_set_target_temp_range_bad_attr(self):
|
def test_set_target_temp_range_bad_attr(self):
|
||||||
"""Test setting the target temperature range without attribute."""
|
"""Test setting the target temperature range without attribute."""
|
||||||
state = self.hass.states.get(ENTITY_ECOBEE)
|
state = self.hass.states.get(ENTITY_ECOBEE)
|
||||||
self.assertEqual(None, state.attributes.get('temperature'))
|
assert state.attributes.get('temperature') is None
|
||||||
self.assertEqual(21.0, state.attributes.get('target_temp_low'))
|
assert 21.0 == state.attributes.get('target_temp_low')
|
||||||
self.assertEqual(24.0, state.attributes.get('target_temp_high'))
|
assert 24.0 == state.attributes.get('target_temp_high')
|
||||||
common.set_temperature(self.hass, temperature=None,
|
common.set_temperature(self.hass, temperature=None,
|
||||||
entity_id=ENTITY_ECOBEE, target_temp_low=None,
|
entity_id=ENTITY_ECOBEE, target_temp_low=None,
|
||||||
target_temp_high=None)
|
target_temp_high=None)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_ECOBEE)
|
state = self.hass.states.get(ENTITY_ECOBEE)
|
||||||
self.assertEqual(None, state.attributes.get('temperature'))
|
assert state.attributes.get('temperature') is None
|
||||||
self.assertEqual(21.0, state.attributes.get('target_temp_low'))
|
assert 21.0 == state.attributes.get('target_temp_low')
|
||||||
self.assertEqual(24.0, state.attributes.get('target_temp_high'))
|
assert 24.0 == state.attributes.get('target_temp_high')
|
||||||
|
|
||||||
def test_set_target_humidity_bad_attr(self):
|
def test_set_target_humidity_bad_attr(self):
|
||||||
"""Test setting the target humidity without required attribute."""
|
"""Test setting the target humidity without required attribute."""
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(67, state.attributes.get('humidity'))
|
assert 67 == state.attributes.get('humidity')
|
||||||
common.set_humidity(self.hass, None, ENTITY_CLIMATE)
|
common.set_humidity(self.hass, None, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(67, state.attributes.get('humidity'))
|
assert 67 == state.attributes.get('humidity')
|
||||||
|
|
||||||
def test_set_target_humidity(self):
|
def test_set_target_humidity(self):
|
||||||
"""Test the setting of the target humidity."""
|
"""Test the setting of the target humidity."""
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(67, state.attributes.get('humidity'))
|
assert 67 == state.attributes.get('humidity')
|
||||||
common.set_humidity(self.hass, 64, ENTITY_CLIMATE)
|
common.set_humidity(self.hass, 64, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(64.0, state.attributes.get('humidity'))
|
assert 64.0 == state.attributes.get('humidity')
|
||||||
|
|
||||||
def test_set_fan_mode_bad_attr(self):
|
def test_set_fan_mode_bad_attr(self):
|
||||||
"""Test setting fan mode without required attribute."""
|
"""Test setting fan mode without required attribute."""
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("On High", state.attributes.get('fan_mode'))
|
assert "On High" == state.attributes.get('fan_mode')
|
||||||
common.set_fan_mode(self.hass, None, ENTITY_CLIMATE)
|
common.set_fan_mode(self.hass, None, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("On High", state.attributes.get('fan_mode'))
|
assert "On High" == state.attributes.get('fan_mode')
|
||||||
|
|
||||||
def test_set_fan_mode(self):
|
def test_set_fan_mode(self):
|
||||||
"""Test setting of new fan mode."""
|
"""Test setting of new fan mode."""
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("On High", state.attributes.get('fan_mode'))
|
assert "On High" == state.attributes.get('fan_mode')
|
||||||
common.set_fan_mode(self.hass, "On Low", ENTITY_CLIMATE)
|
common.set_fan_mode(self.hass, "On Low", ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("On Low", state.attributes.get('fan_mode'))
|
assert "On Low" == state.attributes.get('fan_mode')
|
||||||
|
|
||||||
def test_set_swing_mode_bad_attr(self):
|
def test_set_swing_mode_bad_attr(self):
|
||||||
"""Test setting swing mode without required attribute."""
|
"""Test setting swing mode without required attribute."""
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("Off", state.attributes.get('swing_mode'))
|
assert "Off" == state.attributes.get('swing_mode')
|
||||||
common.set_swing_mode(self.hass, None, ENTITY_CLIMATE)
|
common.set_swing_mode(self.hass, None, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("Off", state.attributes.get('swing_mode'))
|
assert "Off" == state.attributes.get('swing_mode')
|
||||||
|
|
||||||
def test_set_swing(self):
|
def test_set_swing(self):
|
||||||
"""Test setting of new swing mode."""
|
"""Test setting of new swing mode."""
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("Off", state.attributes.get('swing_mode'))
|
assert "Off" == state.attributes.get('swing_mode')
|
||||||
common.set_swing_mode(self.hass, "Auto", ENTITY_CLIMATE)
|
common.set_swing_mode(self.hass, "Auto", ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("Auto", state.attributes.get('swing_mode'))
|
assert "Auto" == state.attributes.get('swing_mode')
|
||||||
|
|
||||||
def test_set_operation_bad_attr_and_state(self):
|
def test_set_operation_bad_attr_and_state(self):
|
||||||
"""Test setting operation mode without required attribute.
|
"""Test setting operation mode without required attribute.
|
||||||
|
@ -168,103 +168,103 @@ class TestDemoClimate(unittest.TestCase):
|
||||||
Also check the state.
|
Also check the state.
|
||||||
"""
|
"""
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("cool", state.attributes.get('operation_mode'))
|
assert "cool" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual("cool", state.state)
|
assert "cool" == state.state
|
||||||
common.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
|
common.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("cool", state.attributes.get('operation_mode'))
|
assert "cool" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual("cool", state.state)
|
assert "cool" == state.state
|
||||||
|
|
||||||
def test_set_operation(self):
|
def test_set_operation(self):
|
||||||
"""Test setting of new operation mode."""
|
"""Test setting of new operation mode."""
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("cool", state.attributes.get('operation_mode'))
|
assert "cool" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual("cool", state.state)
|
assert "cool" == state.state
|
||||||
common.set_operation_mode(self.hass, "heat", ENTITY_CLIMATE)
|
common.set_operation_mode(self.hass, "heat", ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("heat", state.attributes.get('operation_mode'))
|
assert "heat" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual("heat", state.state)
|
assert "heat" == state.state
|
||||||
|
|
||||||
def test_set_away_mode_bad_attr(self):
|
def test_set_away_mode_bad_attr(self):
|
||||||
"""Test setting the away mode without required attribute."""
|
"""Test setting the away mode without required attribute."""
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('on', state.attributes.get('away_mode'))
|
assert 'on' == state.attributes.get('away_mode')
|
||||||
common.set_away_mode(self.hass, None, ENTITY_CLIMATE)
|
common.set_away_mode(self.hass, None, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual('on', state.attributes.get('away_mode'))
|
assert 'on' == state.attributes.get('away_mode')
|
||||||
|
|
||||||
def test_set_away_mode_on(self):
|
def test_set_away_mode_on(self):
|
||||||
"""Test setting the away mode on/true."""
|
"""Test setting the away mode on/true."""
|
||||||
common.set_away_mode(self.hass, True, ENTITY_CLIMATE)
|
common.set_away_mode(self.hass, True, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('on', state.attributes.get('away_mode'))
|
assert 'on' == state.attributes.get('away_mode')
|
||||||
|
|
||||||
def test_set_away_mode_off(self):
|
def test_set_away_mode_off(self):
|
||||||
"""Test setting the away mode off/false."""
|
"""Test setting the away mode off/false."""
|
||||||
common.set_away_mode(self.hass, False, ENTITY_CLIMATE)
|
common.set_away_mode(self.hass, False, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
assert 'off' == state.attributes.get('away_mode')
|
||||||
|
|
||||||
def test_set_hold_mode_home(self):
|
def test_set_hold_mode_home(self):
|
||||||
"""Test setting the hold mode home."""
|
"""Test setting the hold mode home."""
|
||||||
common.set_hold_mode(self.hass, 'home', ENTITY_ECOBEE)
|
common.set_hold_mode(self.hass, 'home', ENTITY_ECOBEE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_ECOBEE)
|
state = self.hass.states.get(ENTITY_ECOBEE)
|
||||||
self.assertEqual('home', state.attributes.get('hold_mode'))
|
assert 'home' == state.attributes.get('hold_mode')
|
||||||
|
|
||||||
def test_set_hold_mode_away(self):
|
def test_set_hold_mode_away(self):
|
||||||
"""Test setting the hold mode away."""
|
"""Test setting the hold mode away."""
|
||||||
common.set_hold_mode(self.hass, 'away', ENTITY_ECOBEE)
|
common.set_hold_mode(self.hass, 'away', ENTITY_ECOBEE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_ECOBEE)
|
state = self.hass.states.get(ENTITY_ECOBEE)
|
||||||
self.assertEqual('away', state.attributes.get('hold_mode'))
|
assert 'away' == state.attributes.get('hold_mode')
|
||||||
|
|
||||||
def test_set_hold_mode_none(self):
|
def test_set_hold_mode_none(self):
|
||||||
"""Test setting the hold mode off/false."""
|
"""Test setting the hold mode off/false."""
|
||||||
common.set_hold_mode(self.hass, 'off', ENTITY_ECOBEE)
|
common.set_hold_mode(self.hass, 'off', ENTITY_ECOBEE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_ECOBEE)
|
state = self.hass.states.get(ENTITY_ECOBEE)
|
||||||
self.assertEqual('off', state.attributes.get('hold_mode'))
|
assert 'off' == state.attributes.get('hold_mode')
|
||||||
|
|
||||||
def test_set_aux_heat_bad_attr(self):
|
def test_set_aux_heat_bad_attr(self):
|
||||||
"""Test setting the auxiliary heater without required attribute."""
|
"""Test setting the auxiliary heater without required attribute."""
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
assert 'off' == state.attributes.get('aux_heat')
|
||||||
common.set_aux_heat(self.hass, None, ENTITY_CLIMATE)
|
common.set_aux_heat(self.hass, None, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
assert 'off' == state.attributes.get('aux_heat')
|
||||||
|
|
||||||
def test_set_aux_heat_on(self):
|
def test_set_aux_heat_on(self):
|
||||||
"""Test setting the axillary heater on/true."""
|
"""Test setting the axillary heater on/true."""
|
||||||
common.set_aux_heat(self.hass, True, ENTITY_CLIMATE)
|
common.set_aux_heat(self.hass, True, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('on', state.attributes.get('aux_heat'))
|
assert 'on' == state.attributes.get('aux_heat')
|
||||||
|
|
||||||
def test_set_aux_heat_off(self):
|
def test_set_aux_heat_off(self):
|
||||||
"""Test setting the auxiliary heater off/false."""
|
"""Test setting the auxiliary heater off/false."""
|
||||||
common.set_aux_heat(self.hass, False, ENTITY_CLIMATE)
|
common.set_aux_heat(self.hass, False, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
assert 'off' == state.attributes.get('aux_heat')
|
||||||
|
|
||||||
def test_set_on_off(self):
|
def test_set_on_off(self):
|
||||||
"""Test on/off service."""
|
"""Test on/off service."""
|
||||||
state = self.hass.states.get(ENTITY_ECOBEE)
|
state = self.hass.states.get(ENTITY_ECOBEE)
|
||||||
self.assertEqual('auto', state.state)
|
assert 'auto' == state.state
|
||||||
|
|
||||||
self.hass.services.call(climate.DOMAIN, climate.SERVICE_TURN_OFF,
|
self.hass.services.call(climate.DOMAIN, climate.SERVICE_TURN_OFF,
|
||||||
{climate.ATTR_ENTITY_ID: ENTITY_ECOBEE})
|
{climate.ATTR_ENTITY_ID: ENTITY_ECOBEE})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_ECOBEE)
|
state = self.hass.states.get(ENTITY_ECOBEE)
|
||||||
self.assertEqual('off', state.state)
|
assert 'off' == state.state
|
||||||
|
|
||||||
self.hass.services.call(climate.DOMAIN, climate.SERVICE_TURN_ON,
|
self.hass.services.call(climate.DOMAIN, climate.SERVICE_TURN_ON,
|
||||||
{climate.ATTR_ENTITY_ID: ENTITY_ECOBEE})
|
{climate.ATTR_ENTITY_ID: ENTITY_ECOBEE})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_ECOBEE)
|
state = self.hass.states.get(ENTITY_ECOBEE)
|
||||||
self.assertEqual('auto', state.state)
|
assert 'auto' == state.state
|
||||||
|
|
|
@ -123,7 +123,7 @@ class DysonTest(unittest.TestCase):
|
||||||
dyson_parent.CONF_LANGUAGE: "US",
|
dyson_parent.CONF_LANGUAGE: "US",
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
self.assertEqual(len(self.hass.data[dyson.DYSON_DEVICES]), 2)
|
assert len(self.hass.data[dyson.DYSON_DEVICES]) == 2
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
for m in mocked_devices.return_value:
|
for m in mocked_devices.return_value:
|
||||||
assert m.add_message_listener.called
|
assert m.add_message_listener.called
|
||||||
|
@ -145,7 +145,7 @@ class DysonTest(unittest.TestCase):
|
||||||
self.hass.data[dyson.DYSON_DEVICES] = devices
|
self.hass.data[dyson.DYSON_DEVICES] = devices
|
||||||
add_devices = mock.MagicMock()
|
add_devices = mock.MagicMock()
|
||||||
dyson.setup_platform(self.hass, None, add_devices, discovery_info={})
|
dyson.setup_platform(self.hass, None, add_devices, discovery_info={})
|
||||||
self.assertTrue(add_devices.called)
|
assert add_devices.called
|
||||||
|
|
||||||
def test_setup_component_with_invalid_devices(self):
|
def test_setup_component_with_invalid_devices(self):
|
||||||
"""Test setup component with invalid devices."""
|
"""Test setup component with invalid devices."""
|
||||||
|
@ -175,7 +175,7 @@ class DysonTest(unittest.TestCase):
|
||||||
device = _get_device_heat_on()
|
device = _get_device_heat_on()
|
||||||
device.temp_unit = TEMP_CELSIUS
|
device.temp_unit = TEMP_CELSIUS
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertFalse(entity.should_poll)
|
assert not entity.should_poll
|
||||||
|
|
||||||
# Without target temp.
|
# Without target temp.
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
|
@ -223,7 +223,7 @@ class DysonTest(unittest.TestCase):
|
||||||
"""Test set fan mode."""
|
"""Test set fan mode."""
|
||||||
device = _get_device_heat_on()
|
device = _get_device_heat_on()
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertFalse(entity.should_poll)
|
assert not entity.should_poll
|
||||||
|
|
||||||
entity.set_fan_mode(dyson.STATE_FOCUS)
|
entity.set_fan_mode(dyson.STATE_FOCUS)
|
||||||
set_config = device.set_configuration
|
set_config = device.set_configuration
|
||||||
|
@ -237,27 +237,27 @@ class DysonTest(unittest.TestCase):
|
||||||
"""Test get fan list."""
|
"""Test get fan list."""
|
||||||
device = _get_device_heat_on()
|
device = _get_device_heat_on()
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertEqual(len(entity.fan_list), 2)
|
assert len(entity.fan_list) == 2
|
||||||
self.assertTrue(dyson.STATE_FOCUS in entity.fan_list)
|
assert dyson.STATE_FOCUS in entity.fan_list
|
||||||
self.assertTrue(dyson.STATE_DIFFUSE in entity.fan_list)
|
assert dyson.STATE_DIFFUSE in entity.fan_list
|
||||||
|
|
||||||
def test_dyson_fan_mode_focus(self):
|
def test_dyson_fan_mode_focus(self):
|
||||||
"""Test fan focus mode."""
|
"""Test fan focus mode."""
|
||||||
device = _get_device_focus()
|
device = _get_device_focus()
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertEqual(entity.current_fan_mode, dyson.STATE_FOCUS)
|
assert entity.current_fan_mode == dyson.STATE_FOCUS
|
||||||
|
|
||||||
def test_dyson_fan_mode_diffuse(self):
|
def test_dyson_fan_mode_diffuse(self):
|
||||||
"""Test fan diffuse mode."""
|
"""Test fan diffuse mode."""
|
||||||
device = _get_device_diffuse()
|
device = _get_device_diffuse()
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertEqual(entity.current_fan_mode, dyson.STATE_DIFFUSE)
|
assert entity.current_fan_mode == dyson.STATE_DIFFUSE
|
||||||
|
|
||||||
def test_dyson_set_operation_mode(self):
|
def test_dyson_set_operation_mode(self):
|
||||||
"""Test set operation mode."""
|
"""Test set operation mode."""
|
||||||
device = _get_device_heat_on()
|
device = _get_device_heat_on()
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertFalse(entity.should_poll)
|
assert not entity.should_poll
|
||||||
|
|
||||||
entity.set_operation_mode(dyson.STATE_HEAT)
|
entity.set_operation_mode(dyson.STATE_HEAT)
|
||||||
set_config = device.set_configuration
|
set_config = device.set_configuration
|
||||||
|
@ -271,9 +271,9 @@ class DysonTest(unittest.TestCase):
|
||||||
"""Test get operation list."""
|
"""Test get operation list."""
|
||||||
device = _get_device_heat_on()
|
device = _get_device_heat_on()
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertEqual(len(entity.operation_list), 2)
|
assert len(entity.operation_list) == 2
|
||||||
self.assertTrue(dyson.STATE_HEAT in entity.operation_list)
|
assert dyson.STATE_HEAT in entity.operation_list
|
||||||
self.assertTrue(dyson.STATE_COOL in entity.operation_list)
|
assert dyson.STATE_COOL in entity.operation_list
|
||||||
|
|
||||||
def test_dyson_heat_off(self):
|
def test_dyson_heat_off(self):
|
||||||
"""Test turn off heat."""
|
"""Test turn off heat."""
|
||||||
|
@ -295,19 +295,19 @@ class DysonTest(unittest.TestCase):
|
||||||
"""Test get heat value on."""
|
"""Test get heat value on."""
|
||||||
device = _get_device_heat_on()
|
device = _get_device_heat_on()
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertEqual(entity.current_operation, dyson.STATE_HEAT)
|
assert entity.current_operation == dyson.STATE_HEAT
|
||||||
|
|
||||||
def test_dyson_heat_value_off(self):
|
def test_dyson_heat_value_off(self):
|
||||||
"""Test get heat value off."""
|
"""Test get heat value off."""
|
||||||
device = _get_device_cool()
|
device = _get_device_cool()
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertEqual(entity.current_operation, dyson.STATE_COOL)
|
assert entity.current_operation == dyson.STATE_COOL
|
||||||
|
|
||||||
def test_dyson_heat_value_idle(self):
|
def test_dyson_heat_value_idle(self):
|
||||||
"""Test get heat value idle."""
|
"""Test get heat value idle."""
|
||||||
device = _get_device_heat_off()
|
device = _get_device_heat_off()
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertEqual(entity.current_operation, dyson.STATE_IDLE)
|
assert entity.current_operation == dyson.STATE_IDLE
|
||||||
|
|
||||||
def test_on_message(self):
|
def test_on_message(self):
|
||||||
"""Test when message is received."""
|
"""Test when message is received."""
|
||||||
|
@ -321,38 +321,38 @@ class DysonTest(unittest.TestCase):
|
||||||
"""Test properties of entity."""
|
"""Test properties of entity."""
|
||||||
device = _get_device_with_no_state()
|
device = _get_device_with_no_state()
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertEqual(entity.should_poll, False)
|
assert entity.should_poll is False
|
||||||
self.assertEqual(entity.supported_features, dyson.SUPPORT_FLAGS)
|
assert entity.supported_features == dyson.SUPPORT_FLAGS
|
||||||
self.assertEqual(entity.temperature_unit, TEMP_CELSIUS)
|
assert entity.temperature_unit == TEMP_CELSIUS
|
||||||
|
|
||||||
def test_property_current_humidity(self):
|
def test_property_current_humidity(self):
|
||||||
"""Test properties of current humidity."""
|
"""Test properties of current humidity."""
|
||||||
device = _get_device_heat_on()
|
device = _get_device_heat_on()
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertEqual(entity.current_humidity, 53)
|
assert entity.current_humidity == 53
|
||||||
|
|
||||||
def test_property_current_humidity_with_invalid_env_state(self):
|
def test_property_current_humidity_with_invalid_env_state(self):
|
||||||
"""Test properties of current humidity with invalid env state."""
|
"""Test properties of current humidity with invalid env state."""
|
||||||
device = _get_device_off()
|
device = _get_device_off()
|
||||||
device.environmental_state.humidity = 0
|
device.environmental_state.humidity = 0
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertEqual(entity.current_humidity, None)
|
assert entity.current_humidity is None
|
||||||
|
|
||||||
def test_property_current_humidity_without_env_state(self):
|
def test_property_current_humidity_without_env_state(self):
|
||||||
"""Test properties of current humidity without env state."""
|
"""Test properties of current humidity without env state."""
|
||||||
device = _get_device_with_no_state()
|
device = _get_device_with_no_state()
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertEqual(entity.current_humidity, None)
|
assert entity.current_humidity is None
|
||||||
|
|
||||||
def test_property_current_temperature(self):
|
def test_property_current_temperature(self):
|
||||||
"""Test properties of current temperature."""
|
"""Test properties of current temperature."""
|
||||||
device = _get_device_heat_on()
|
device = _get_device_heat_on()
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
# Result should be in celsius, hence then subtraction of 273.
|
# Result should be in celsius, hence then subtraction of 273.
|
||||||
self.assertEqual(entity.current_temperature, 289 - 273)
|
assert entity.current_temperature == 289 - 273
|
||||||
|
|
||||||
def test_property_target_temperature(self):
|
def test_property_target_temperature(self):
|
||||||
"""Test properties of target temperature."""
|
"""Test properties of target temperature."""
|
||||||
device = _get_device_heat_on()
|
device = _get_device_heat_on()
|
||||||
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
entity = dyson.DysonPureHotCoolLinkDevice(device)
|
||||||
self.assertEqual(entity.target_temperature, 23)
|
assert entity.target_temperature == 23
|
||||||
|
|
|
@ -44,214 +44,214 @@ class TestEcobee(unittest.TestCase):
|
||||||
|
|
||||||
def test_name(self):
|
def test_name(self):
|
||||||
"""Test name property."""
|
"""Test name property."""
|
||||||
self.assertEqual('Ecobee', self.thermostat.name)
|
assert 'Ecobee' == self.thermostat.name
|
||||||
|
|
||||||
def test_temperature_unit(self):
|
def test_temperature_unit(self):
|
||||||
"""Test temperature unit property."""
|
"""Test temperature unit property."""
|
||||||
self.assertEqual(const.TEMP_FAHRENHEIT,
|
assert const.TEMP_FAHRENHEIT == \
|
||||||
self.thermostat.temperature_unit)
|
self.thermostat.temperature_unit
|
||||||
|
|
||||||
def test_current_temperature(self):
|
def test_current_temperature(self):
|
||||||
"""Test current temperature."""
|
"""Test current temperature."""
|
||||||
self.assertEqual(30, self.thermostat.current_temperature)
|
assert 30 == self.thermostat.current_temperature
|
||||||
self.ecobee['runtime']['actualTemperature'] = 404
|
self.ecobee['runtime']['actualTemperature'] = 404
|
||||||
self.assertEqual(40.4, self.thermostat.current_temperature)
|
assert 40.4 == self.thermostat.current_temperature
|
||||||
|
|
||||||
def test_target_temperature_low(self):
|
def test_target_temperature_low(self):
|
||||||
"""Test target low temperature."""
|
"""Test target low temperature."""
|
||||||
self.assertEqual(40, self.thermostat.target_temperature_low)
|
assert 40 == self.thermostat.target_temperature_low
|
||||||
self.ecobee['runtime']['desiredHeat'] = 502
|
self.ecobee['runtime']['desiredHeat'] = 502
|
||||||
self.assertEqual(50.2, self.thermostat.target_temperature_low)
|
assert 50.2 == self.thermostat.target_temperature_low
|
||||||
|
|
||||||
def test_target_temperature_high(self):
|
def test_target_temperature_high(self):
|
||||||
"""Test target high temperature."""
|
"""Test target high temperature."""
|
||||||
self.assertEqual(20, self.thermostat.target_temperature_high)
|
assert 20 == self.thermostat.target_temperature_high
|
||||||
self.ecobee['runtime']['desiredCool'] = 103
|
self.ecobee['runtime']['desiredCool'] = 103
|
||||||
self.assertEqual(10.3, self.thermostat.target_temperature_high)
|
assert 10.3 == self.thermostat.target_temperature_high
|
||||||
|
|
||||||
def test_target_temperature(self):
|
def test_target_temperature(self):
|
||||||
"""Test target temperature."""
|
"""Test target temperature."""
|
||||||
self.assertIsNone(self.thermostat.target_temperature)
|
assert self.thermostat.target_temperature is None
|
||||||
self.ecobee['settings']['hvacMode'] = 'heat'
|
self.ecobee['settings']['hvacMode'] = 'heat'
|
||||||
self.assertEqual(40, self.thermostat.target_temperature)
|
assert 40 == self.thermostat.target_temperature
|
||||||
self.ecobee['settings']['hvacMode'] = 'cool'
|
self.ecobee['settings']['hvacMode'] = 'cool'
|
||||||
self.assertEqual(20, self.thermostat.target_temperature)
|
assert 20 == self.thermostat.target_temperature
|
||||||
self.ecobee['settings']['hvacMode'] = 'auxHeatOnly'
|
self.ecobee['settings']['hvacMode'] = 'auxHeatOnly'
|
||||||
self.assertEqual(40, self.thermostat.target_temperature)
|
assert 40 == self.thermostat.target_temperature
|
||||||
self.ecobee['settings']['hvacMode'] = 'off'
|
self.ecobee['settings']['hvacMode'] = 'off'
|
||||||
self.assertIsNone(self.thermostat.target_temperature)
|
assert self.thermostat.target_temperature is None
|
||||||
|
|
||||||
def test_desired_fan_mode(self):
|
def test_desired_fan_mode(self):
|
||||||
"""Test desired fan mode property."""
|
"""Test desired fan mode property."""
|
||||||
self.assertEqual('on', self.thermostat.current_fan_mode)
|
assert 'on' == self.thermostat.current_fan_mode
|
||||||
self.ecobee['runtime']['desiredFanMode'] = 'auto'
|
self.ecobee['runtime']['desiredFanMode'] = 'auto'
|
||||||
self.assertEqual('auto', self.thermostat.current_fan_mode)
|
assert 'auto' == self.thermostat.current_fan_mode
|
||||||
|
|
||||||
def test_fan(self):
|
def test_fan(self):
|
||||||
"""Test fan property."""
|
"""Test fan property."""
|
||||||
self.assertEqual(const.STATE_ON, self.thermostat.fan)
|
assert const.STATE_ON == self.thermostat.fan
|
||||||
self.ecobee['equipmentStatus'] = ''
|
self.ecobee['equipmentStatus'] = ''
|
||||||
self.assertEqual(STATE_OFF, self.thermostat.fan)
|
assert STATE_OFF == self.thermostat.fan
|
||||||
self.ecobee['equipmentStatus'] = 'heatPump, heatPump2'
|
self.ecobee['equipmentStatus'] = 'heatPump, heatPump2'
|
||||||
self.assertEqual(STATE_OFF, self.thermostat.fan)
|
assert STATE_OFF == self.thermostat.fan
|
||||||
|
|
||||||
def test_current_hold_mode_away_temporary(self):
|
def test_current_hold_mode_away_temporary(self):
|
||||||
"""Test current hold mode when away."""
|
"""Test current hold mode when away."""
|
||||||
# Temporary away hold
|
# Temporary away hold
|
||||||
self.assertEqual('away', self.thermostat.current_hold_mode)
|
assert 'away' == self.thermostat.current_hold_mode
|
||||||
self.ecobee['events'][0]['endDate'] = '2018-01-01 09:49:00'
|
self.ecobee['events'][0]['endDate'] = '2018-01-01 09:49:00'
|
||||||
self.assertEqual('away', self.thermostat.current_hold_mode)
|
assert 'away' == self.thermostat.current_hold_mode
|
||||||
|
|
||||||
def test_current_hold_mode_away_permanent(self):
|
def test_current_hold_mode_away_permanent(self):
|
||||||
"""Test current hold mode when away permanently."""
|
"""Test current hold mode when away permanently."""
|
||||||
# Permanent away hold
|
# Permanent away hold
|
||||||
self.ecobee['events'][0]['endDate'] = '2019-01-01 10:17:00'
|
self.ecobee['events'][0]['endDate'] = '2019-01-01 10:17:00'
|
||||||
self.assertIsNone(self.thermostat.current_hold_mode)
|
assert self.thermostat.current_hold_mode is None
|
||||||
|
|
||||||
def test_current_hold_mode_no_running_events(self):
|
def test_current_hold_mode_no_running_events(self):
|
||||||
"""Test current hold mode when no running events."""
|
"""Test current hold mode when no running events."""
|
||||||
# No running events
|
# No running events
|
||||||
self.ecobee['events'][0]['running'] = False
|
self.ecobee['events'][0]['running'] = False
|
||||||
self.assertIsNone(self.thermostat.current_hold_mode)
|
assert self.thermostat.current_hold_mode is None
|
||||||
|
|
||||||
def test_current_hold_mode_vacation(self):
|
def test_current_hold_mode_vacation(self):
|
||||||
"""Test current hold mode when on vacation."""
|
"""Test current hold mode when on vacation."""
|
||||||
# Vacation Hold
|
# Vacation Hold
|
||||||
self.ecobee['events'][0]['type'] = 'vacation'
|
self.ecobee['events'][0]['type'] = 'vacation'
|
||||||
self.assertEqual('vacation', self.thermostat.current_hold_mode)
|
assert 'vacation' == self.thermostat.current_hold_mode
|
||||||
|
|
||||||
def test_current_hold_mode_climate(self):
|
def test_current_hold_mode_climate(self):
|
||||||
"""Test current hold mode when heat climate is set."""
|
"""Test current hold mode when heat climate is set."""
|
||||||
# Preset climate hold
|
# Preset climate hold
|
||||||
self.ecobee['events'][0]['type'] = 'hold'
|
self.ecobee['events'][0]['type'] = 'hold'
|
||||||
self.ecobee['events'][0]['holdClimateRef'] = 'heatClimate'
|
self.ecobee['events'][0]['holdClimateRef'] = 'heatClimate'
|
||||||
self.assertEqual('heatClimate', self.thermostat.current_hold_mode)
|
assert 'heatClimate' == self.thermostat.current_hold_mode
|
||||||
|
|
||||||
def test_current_hold_mode_temperature_hold(self):
|
def test_current_hold_mode_temperature_hold(self):
|
||||||
"""Test current hold mode when temperature hold is set."""
|
"""Test current hold mode when temperature hold is set."""
|
||||||
# Temperature hold
|
# Temperature hold
|
||||||
self.ecobee['events'][0]['type'] = 'hold'
|
self.ecobee['events'][0]['type'] = 'hold'
|
||||||
self.ecobee['events'][0]['holdClimateRef'] = ''
|
self.ecobee['events'][0]['holdClimateRef'] = ''
|
||||||
self.assertEqual('temp', self.thermostat.current_hold_mode)
|
assert 'temp' == self.thermostat.current_hold_mode
|
||||||
|
|
||||||
def test_current_hold_mode_auto_hold(self):
|
def test_current_hold_mode_auto_hold(self):
|
||||||
"""Test current hold mode when auto heat is set."""
|
"""Test current hold mode when auto heat is set."""
|
||||||
# auto Hold
|
# auto Hold
|
||||||
self.ecobee['events'][0]['type'] = 'autoHeat'
|
self.ecobee['events'][0]['type'] = 'autoHeat'
|
||||||
self.assertEqual('heat', self.thermostat.current_hold_mode)
|
assert 'heat' == self.thermostat.current_hold_mode
|
||||||
|
|
||||||
def test_current_operation(self):
|
def test_current_operation(self):
|
||||||
"""Test current operation property."""
|
"""Test current operation property."""
|
||||||
self.assertEqual('auto', self.thermostat.current_operation)
|
assert 'auto' == self.thermostat.current_operation
|
||||||
self.ecobee['settings']['hvacMode'] = 'heat'
|
self.ecobee['settings']['hvacMode'] = 'heat'
|
||||||
self.assertEqual('heat', self.thermostat.current_operation)
|
assert 'heat' == self.thermostat.current_operation
|
||||||
self.ecobee['settings']['hvacMode'] = 'cool'
|
self.ecobee['settings']['hvacMode'] = 'cool'
|
||||||
self.assertEqual('cool', self.thermostat.current_operation)
|
assert 'cool' == self.thermostat.current_operation
|
||||||
self.ecobee['settings']['hvacMode'] = 'auxHeatOnly'
|
self.ecobee['settings']['hvacMode'] = 'auxHeatOnly'
|
||||||
self.assertEqual('heat', self.thermostat.current_operation)
|
assert 'heat' == self.thermostat.current_operation
|
||||||
self.ecobee['settings']['hvacMode'] = 'off'
|
self.ecobee['settings']['hvacMode'] = 'off'
|
||||||
self.assertEqual('off', self.thermostat.current_operation)
|
assert 'off' == self.thermostat.current_operation
|
||||||
|
|
||||||
def test_operation_list(self):
|
def test_operation_list(self):
|
||||||
"""Test operation list property."""
|
"""Test operation list property."""
|
||||||
self.assertEqual(['auto', 'auxHeatOnly', 'cool',
|
assert ['auto', 'auxHeatOnly', 'cool',
|
||||||
'heat', 'off'], self.thermostat.operation_list)
|
'heat', 'off'] == self.thermostat.operation_list
|
||||||
|
|
||||||
def test_operation_mode(self):
|
def test_operation_mode(self):
|
||||||
"""Test operation mode property."""
|
"""Test operation mode property."""
|
||||||
self.assertEqual('auto', self.thermostat.operation_mode)
|
assert 'auto' == self.thermostat.operation_mode
|
||||||
self.ecobee['settings']['hvacMode'] = 'heat'
|
self.ecobee['settings']['hvacMode'] = 'heat'
|
||||||
self.assertEqual('heat', self.thermostat.operation_mode)
|
assert 'heat' == self.thermostat.operation_mode
|
||||||
|
|
||||||
def test_mode(self):
|
def test_mode(self):
|
||||||
"""Test mode property."""
|
"""Test mode property."""
|
||||||
self.assertEqual('Climate1', self.thermostat.mode)
|
assert 'Climate1' == self.thermostat.mode
|
||||||
self.ecobee['program']['currentClimateRef'] = 'c2'
|
self.ecobee['program']['currentClimateRef'] = 'c2'
|
||||||
self.assertEqual('Climate2', self.thermostat.mode)
|
assert 'Climate2' == self.thermostat.mode
|
||||||
|
|
||||||
def test_fan_min_on_time(self):
|
def test_fan_min_on_time(self):
|
||||||
"""Test fan min on time property."""
|
"""Test fan min on time property."""
|
||||||
self.assertEqual(10, self.thermostat.fan_min_on_time)
|
assert 10 == self.thermostat.fan_min_on_time
|
||||||
self.ecobee['settings']['fanMinOnTime'] = 100
|
self.ecobee['settings']['fanMinOnTime'] = 100
|
||||||
self.assertEqual(100, self.thermostat.fan_min_on_time)
|
assert 100 == self.thermostat.fan_min_on_time
|
||||||
|
|
||||||
def test_device_state_attributes(self):
|
def test_device_state_attributes(self):
|
||||||
"""Test device state attributes property."""
|
"""Test device state attributes property."""
|
||||||
self.ecobee['equipmentStatus'] = 'heatPump2'
|
self.ecobee['equipmentStatus'] = 'heatPump2'
|
||||||
self.assertEqual({'actual_humidity': 15,
|
assert {'actual_humidity': 15,
|
||||||
'climate_list': ['Climate1', 'Climate2'],
|
'climate_list': ['Climate1', 'Climate2'],
|
||||||
'fan': 'off',
|
'fan': 'off',
|
||||||
'fan_min_on_time': 10,
|
'fan_min_on_time': 10,
|
||||||
'climate_mode': 'Climate1',
|
'climate_mode': 'Climate1',
|
||||||
'operation': 'heat'},
|
'operation': 'heat'} == \
|
||||||
self.thermostat.device_state_attributes)
|
self.thermostat.device_state_attributes
|
||||||
|
|
||||||
self.ecobee['equipmentStatus'] = 'auxHeat2'
|
self.ecobee['equipmentStatus'] = 'auxHeat2'
|
||||||
self.assertEqual({'actual_humidity': 15,
|
assert {'actual_humidity': 15,
|
||||||
'climate_list': ['Climate1', 'Climate2'],
|
'climate_list': ['Climate1', 'Climate2'],
|
||||||
'fan': 'off',
|
'fan': 'off',
|
||||||
'fan_min_on_time': 10,
|
'fan_min_on_time': 10,
|
||||||
'climate_mode': 'Climate1',
|
'climate_mode': 'Climate1',
|
||||||
'operation': 'heat'},
|
'operation': 'heat'} == \
|
||||||
self.thermostat.device_state_attributes)
|
self.thermostat.device_state_attributes
|
||||||
self.ecobee['equipmentStatus'] = 'compCool1'
|
self.ecobee['equipmentStatus'] = 'compCool1'
|
||||||
self.assertEqual({'actual_humidity': 15,
|
assert {'actual_humidity': 15,
|
||||||
'climate_list': ['Climate1', 'Climate2'],
|
'climate_list': ['Climate1', 'Climate2'],
|
||||||
'fan': 'off',
|
'fan': 'off',
|
||||||
'fan_min_on_time': 10,
|
'fan_min_on_time': 10,
|
||||||
'climate_mode': 'Climate1',
|
'climate_mode': 'Climate1',
|
||||||
'operation': 'cool'},
|
'operation': 'cool'} == \
|
||||||
self.thermostat.device_state_attributes)
|
self.thermostat.device_state_attributes
|
||||||
self.ecobee['equipmentStatus'] = ''
|
self.ecobee['equipmentStatus'] = ''
|
||||||
self.assertEqual({'actual_humidity': 15,
|
assert {'actual_humidity': 15,
|
||||||
'climate_list': ['Climate1', 'Climate2'],
|
'climate_list': ['Climate1', 'Climate2'],
|
||||||
'fan': 'off',
|
'fan': 'off',
|
||||||
'fan_min_on_time': 10,
|
'fan_min_on_time': 10,
|
||||||
'climate_mode': 'Climate1',
|
'climate_mode': 'Climate1',
|
||||||
'operation': 'idle'},
|
'operation': 'idle'} == \
|
||||||
self.thermostat.device_state_attributes)
|
self.thermostat.device_state_attributes
|
||||||
|
|
||||||
self.ecobee['equipmentStatus'] = 'Unknown'
|
self.ecobee['equipmentStatus'] = 'Unknown'
|
||||||
self.assertEqual({'actual_humidity': 15,
|
assert {'actual_humidity': 15,
|
||||||
'climate_list': ['Climate1', 'Climate2'],
|
'climate_list': ['Climate1', 'Climate2'],
|
||||||
'fan': 'off',
|
'fan': 'off',
|
||||||
'fan_min_on_time': 10,
|
'fan_min_on_time': 10,
|
||||||
'climate_mode': 'Climate1',
|
'climate_mode': 'Climate1',
|
||||||
'operation': 'Unknown'},
|
'operation': 'Unknown'} == \
|
||||||
self.thermostat.device_state_attributes)
|
self.thermostat.device_state_attributes
|
||||||
|
|
||||||
def test_is_away_mode_on(self):
|
def test_is_away_mode_on(self):
|
||||||
"""Test away mode property."""
|
"""Test away mode property."""
|
||||||
self.assertFalse(self.thermostat.is_away_mode_on)
|
assert not self.thermostat.is_away_mode_on
|
||||||
# Temporary away hold
|
# Temporary away hold
|
||||||
self.ecobee['events'][0]['endDate'] = '2018-01-01 11:12:12'
|
self.ecobee['events'][0]['endDate'] = '2018-01-01 11:12:12'
|
||||||
self.assertFalse(self.thermostat.is_away_mode_on)
|
assert not self.thermostat.is_away_mode_on
|
||||||
# Permanent away hold
|
# Permanent away hold
|
||||||
self.ecobee['events'][0]['endDate'] = '2019-01-01 13:12:12'
|
self.ecobee['events'][0]['endDate'] = '2019-01-01 13:12:12'
|
||||||
self.assertTrue(self.thermostat.is_away_mode_on)
|
assert self.thermostat.is_away_mode_on
|
||||||
# No running events
|
# No running events
|
||||||
self.ecobee['events'][0]['running'] = False
|
self.ecobee['events'][0]['running'] = False
|
||||||
self.assertFalse(self.thermostat.is_away_mode_on)
|
assert not self.thermostat.is_away_mode_on
|
||||||
# Vacation Hold
|
# Vacation Hold
|
||||||
self.ecobee['events'][0]['type'] = 'vacation'
|
self.ecobee['events'][0]['type'] = 'vacation'
|
||||||
self.assertFalse(self.thermostat.is_away_mode_on)
|
assert not self.thermostat.is_away_mode_on
|
||||||
# Preset climate hold
|
# Preset climate hold
|
||||||
self.ecobee['events'][0]['type'] = 'hold'
|
self.ecobee['events'][0]['type'] = 'hold'
|
||||||
self.ecobee['events'][0]['holdClimateRef'] = 'heatClimate'
|
self.ecobee['events'][0]['holdClimateRef'] = 'heatClimate'
|
||||||
self.assertFalse(self.thermostat.is_away_mode_on)
|
assert not self.thermostat.is_away_mode_on
|
||||||
# Temperature hold
|
# Temperature hold
|
||||||
self.ecobee['events'][0]['type'] = 'hold'
|
self.ecobee['events'][0]['type'] = 'hold'
|
||||||
self.ecobee['events'][0]['holdClimateRef'] = ''
|
self.ecobee['events'][0]['holdClimateRef'] = ''
|
||||||
self.assertFalse(self.thermostat.is_away_mode_on)
|
assert not self.thermostat.is_away_mode_on
|
||||||
# auto Hold
|
# auto Hold
|
||||||
self.ecobee['events'][0]['type'] = 'autoHeat'
|
self.ecobee['events'][0]['type'] = 'autoHeat'
|
||||||
self.assertFalse(self.thermostat.is_away_mode_on)
|
assert not self.thermostat.is_away_mode_on
|
||||||
|
|
||||||
def test_is_aux_heat_on(self):
|
def test_is_aux_heat_on(self):
|
||||||
"""Test aux heat property."""
|
"""Test aux heat property."""
|
||||||
self.assertFalse(self.thermostat.is_aux_heat_on)
|
assert not self.thermostat.is_aux_heat_on
|
||||||
self.ecobee['equipmentStatus'] = 'fan, auxHeat'
|
self.ecobee['equipmentStatus'] = 'fan, auxHeat'
|
||||||
self.assertTrue(self.thermostat.is_aux_heat_on)
|
assert self.thermostat.is_aux_heat_on
|
||||||
|
|
||||||
def test_turn_away_mode_on_off(self):
|
def test_turn_away_mode_on_off(self):
|
||||||
"""Test turn away mode setter."""
|
"""Test turn away mode setter."""
|
||||||
|
@ -265,7 +265,7 @@ class TestEcobee(unittest.TestCase):
|
||||||
self.data.reset_mock()
|
self.data.reset_mock()
|
||||||
self.ecobee['events'][0]['endDate'] = '2019-01-01 11:12:12'
|
self.ecobee['events'][0]['endDate'] = '2019-01-01 11:12:12'
|
||||||
# Should not call set_climate_hold()
|
# Should not call set_climate_hold()
|
||||||
self.assertFalse(self.data.ecobee.set_climate_hold.called)
|
assert not self.data.ecobee.set_climate_hold.called
|
||||||
|
|
||||||
# Try turning off while hold mode is away hold
|
# Try turning off while hold mode is away hold
|
||||||
self.data.reset_mock()
|
self.data.reset_mock()
|
||||||
|
@ -276,7 +276,7 @@ class TestEcobee(unittest.TestCase):
|
||||||
self.data.reset_mock()
|
self.data.reset_mock()
|
||||||
self.ecobee['events'][0]['endDate'] = '2017-01-01 14:00:00'
|
self.ecobee['events'][0]['endDate'] = '2017-01-01 14:00:00'
|
||||||
self.thermostat.turn_away_mode_off()
|
self.thermostat.turn_away_mode_off()
|
||||||
self.assertFalse(self.data.ecobee.resume_program.called)
|
assert not self.data.ecobee.resume_program.called
|
||||||
|
|
||||||
def test_set_hold_mode(self):
|
def test_set_hold_mode(self):
|
||||||
"""Test hold mode setter."""
|
"""Test hold mode setter."""
|
||||||
|
@ -284,18 +284,18 @@ class TestEcobee(unittest.TestCase):
|
||||||
# Away->Away
|
# Away->Away
|
||||||
self.data.reset_mock()
|
self.data.reset_mock()
|
||||||
self.thermostat.set_hold_mode('away')
|
self.thermostat.set_hold_mode('away')
|
||||||
self.assertFalse(self.data.ecobee.delete_vacation.called)
|
assert not self.data.ecobee.delete_vacation.called
|
||||||
self.assertFalse(self.data.ecobee.resume_program.called)
|
assert not self.data.ecobee.resume_program.called
|
||||||
self.assertFalse(self.data.ecobee.set_hold_temp.called)
|
assert not self.data.ecobee.set_hold_temp.called
|
||||||
self.assertFalse(self.data.ecobee.set_climate_hold.called)
|
assert not self.data.ecobee.set_climate_hold.called
|
||||||
|
|
||||||
# Away->'None'
|
# Away->'None'
|
||||||
self.data.reset_mock()
|
self.data.reset_mock()
|
||||||
self.thermostat.set_hold_mode('None')
|
self.thermostat.set_hold_mode('None')
|
||||||
self.assertFalse(self.data.ecobee.delete_vacation.called)
|
assert not self.data.ecobee.delete_vacation.called
|
||||||
self.data.ecobee.resume_program.assert_has_calls([mock.call(1)])
|
self.data.ecobee.resume_program.assert_has_calls([mock.call(1)])
|
||||||
self.assertFalse(self.data.ecobee.set_hold_temp.called)
|
assert not self.data.ecobee.set_hold_temp.called
|
||||||
self.assertFalse(self.data.ecobee.set_climate_hold.called)
|
assert not self.data.ecobee.set_climate_hold.called
|
||||||
|
|
||||||
# Vacation Hold -> None
|
# Vacation Hold -> None
|
||||||
self.ecobee['events'][0]['type'] = 'vacation'
|
self.ecobee['events'][0]['type'] = 'vacation'
|
||||||
|
@ -303,28 +303,28 @@ class TestEcobee(unittest.TestCase):
|
||||||
self.thermostat.set_hold_mode(None)
|
self.thermostat.set_hold_mode(None)
|
||||||
self.data.ecobee.delete_vacation.assert_has_calls(
|
self.data.ecobee.delete_vacation.assert_has_calls(
|
||||||
[mock.call(1, 'Event1')])
|
[mock.call(1, 'Event1')])
|
||||||
self.assertFalse(self.data.ecobee.resume_program.called)
|
assert not self.data.ecobee.resume_program.called
|
||||||
self.assertFalse(self.data.ecobee.set_hold_temp.called)
|
assert not self.data.ecobee.set_hold_temp.called
|
||||||
self.assertFalse(self.data.ecobee.set_climate_hold.called)
|
assert not self.data.ecobee.set_climate_hold.called
|
||||||
|
|
||||||
# Away -> home, sleep
|
# Away -> home, sleep
|
||||||
for hold in ['home', 'sleep']:
|
for hold in ['home', 'sleep']:
|
||||||
self.data.reset_mock()
|
self.data.reset_mock()
|
||||||
self.thermostat.set_hold_mode(hold)
|
self.thermostat.set_hold_mode(hold)
|
||||||
self.assertFalse(self.data.ecobee.delete_vacation.called)
|
assert not self.data.ecobee.delete_vacation.called
|
||||||
self.assertFalse(self.data.ecobee.resume_program.called)
|
assert not self.data.ecobee.resume_program.called
|
||||||
self.assertFalse(self.data.ecobee.set_hold_temp.called)
|
assert not self.data.ecobee.set_hold_temp.called
|
||||||
self.data.ecobee.set_climate_hold.assert_has_calls(
|
self.data.ecobee.set_climate_hold.assert_has_calls(
|
||||||
[mock.call(1, hold, 'nextTransition')])
|
[mock.call(1, hold, 'nextTransition')])
|
||||||
|
|
||||||
# Away -> temp
|
# Away -> temp
|
||||||
self.data.reset_mock()
|
self.data.reset_mock()
|
||||||
self.thermostat.set_hold_mode('temp')
|
self.thermostat.set_hold_mode('temp')
|
||||||
self.assertFalse(self.data.ecobee.delete_vacation.called)
|
assert not self.data.ecobee.delete_vacation.called
|
||||||
self.assertFalse(self.data.ecobee.resume_program.called)
|
assert not self.data.ecobee.resume_program.called
|
||||||
self.data.ecobee.set_hold_temp.assert_has_calls(
|
self.data.ecobee.set_hold_temp.assert_has_calls(
|
||||||
[mock.call(1, 35.0, 25.0, 'nextTransition')])
|
[mock.call(1, 35.0, 25.0, 'nextTransition')])
|
||||||
self.assertFalse(self.data.ecobee.set_climate_hold.called)
|
assert not self.data.ecobee.set_climate_hold.called
|
||||||
|
|
||||||
def test_set_auto_temp_hold(self):
|
def test_set_auto_temp_hold(self):
|
||||||
"""Test auto temp hold setter."""
|
"""Test auto temp hold setter."""
|
||||||
|
@ -389,7 +389,7 @@ class TestEcobee(unittest.TestCase):
|
||||||
self.ecobee['settings']['hvacMode'] = 'heat'
|
self.ecobee['settings']['hvacMode'] = 'heat'
|
||||||
self.thermostat.set_temperature(target_temp_low=20,
|
self.thermostat.set_temperature(target_temp_low=20,
|
||||||
target_temp_high=30)
|
target_temp_high=30)
|
||||||
self.assertFalse(self.data.ecobee.set_hold_temp.called)
|
assert not self.data.ecobee.set_hold_temp.called
|
||||||
|
|
||||||
def test_set_operation_mode(self):
|
def test_set_operation_mode(self):
|
||||||
"""Test operation mode setter."""
|
"""Test operation mode setter."""
|
||||||
|
@ -441,17 +441,17 @@ class TestEcobee(unittest.TestCase):
|
||||||
|
|
||||||
def test_hold_preference(self):
|
def test_hold_preference(self):
|
||||||
"""Test hold preference."""
|
"""Test hold preference."""
|
||||||
self.assertEqual('nextTransition', self.thermostat.hold_preference())
|
assert 'nextTransition' == self.thermostat.hold_preference()
|
||||||
for action in ['useEndTime4hour', 'useEndTime2hour',
|
for action in ['useEndTime4hour', 'useEndTime2hour',
|
||||||
'nextPeriod', 'indefinite', 'askMe']:
|
'nextPeriod', 'indefinite', 'askMe']:
|
||||||
self.ecobee['settings']['holdAction'] = action
|
self.ecobee['settings']['holdAction'] = action
|
||||||
self.assertEqual('nextTransition',
|
assert 'nextTransition' == \
|
||||||
self.thermostat.hold_preference())
|
self.thermostat.hold_preference()
|
||||||
|
|
||||||
def test_climate_list(self):
|
def test_climate_list(self):
|
||||||
"""Test climate list property."""
|
"""Test climate list property."""
|
||||||
self.assertEqual(['Climate1', 'Climate2'],
|
assert ['Climate1', 'Climate2'] == \
|
||||||
self.thermostat.climate_list)
|
self.thermostat.climate_list
|
||||||
|
|
||||||
def test_set_fan_mode_on(self):
|
def test_set_fan_mode_on(self):
|
||||||
"""Test set fan mode to on."""
|
"""Test set fan mode to on."""
|
||||||
|
|
|
@ -30,46 +30,46 @@ class TestFritzboxClimate(unittest.TestCase):
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
"""Test instance creation."""
|
"""Test instance creation."""
|
||||||
self.assertEqual(18.0, self.thermostat._current_temperature)
|
assert 18.0 == self.thermostat._current_temperature
|
||||||
self.assertEqual(19.5, self.thermostat._target_temperature)
|
assert 19.5 == self.thermostat._target_temperature
|
||||||
self.assertEqual(22.0, self.thermostat._comfort_temperature)
|
assert 22.0 == self.thermostat._comfort_temperature
|
||||||
self.assertEqual(16.0, self.thermostat._eco_temperature)
|
assert 16.0 == self.thermostat._eco_temperature
|
||||||
|
|
||||||
def test_supported_features(self):
|
def test_supported_features(self):
|
||||||
"""Test supported features property."""
|
"""Test supported features property."""
|
||||||
self.assertEqual(129, self.thermostat.supported_features)
|
assert 129 == self.thermostat.supported_features
|
||||||
|
|
||||||
def test_available(self):
|
def test_available(self):
|
||||||
"""Test available property."""
|
"""Test available property."""
|
||||||
self.assertTrue(self.thermostat.available)
|
assert self.thermostat.available
|
||||||
self.thermostat._device.present = False
|
self.thermostat._device.present = False
|
||||||
self.assertFalse(self.thermostat.available)
|
assert not self.thermostat.available
|
||||||
|
|
||||||
def test_name(self):
|
def test_name(self):
|
||||||
"""Test name property."""
|
"""Test name property."""
|
||||||
self.assertEqual('Test Thermostat', self.thermostat.name)
|
assert 'Test Thermostat' == self.thermostat.name
|
||||||
|
|
||||||
def test_temperature_unit(self):
|
def test_temperature_unit(self):
|
||||||
"""Test temperature_unit property."""
|
"""Test temperature_unit property."""
|
||||||
self.assertEqual('°C', self.thermostat.temperature_unit)
|
assert '°C' == self.thermostat.temperature_unit
|
||||||
|
|
||||||
def test_precision(self):
|
def test_precision(self):
|
||||||
"""Test precision property."""
|
"""Test precision property."""
|
||||||
self.assertEqual(0.5, self.thermostat.precision)
|
assert 0.5 == self.thermostat.precision
|
||||||
|
|
||||||
def test_current_temperature(self):
|
def test_current_temperature(self):
|
||||||
"""Test current_temperature property incl. special temperatures."""
|
"""Test current_temperature property incl. special temperatures."""
|
||||||
self.assertEqual(18, self.thermostat.current_temperature)
|
assert 18 == self.thermostat.current_temperature
|
||||||
|
|
||||||
def test_target_temperature(self):
|
def test_target_temperature(self):
|
||||||
"""Test target_temperature property."""
|
"""Test target_temperature property."""
|
||||||
self.assertEqual(19.5, self.thermostat.target_temperature)
|
assert 19.5 == self.thermostat.target_temperature
|
||||||
|
|
||||||
self.thermostat._target_temperature = 126.5
|
self.thermostat._target_temperature = 126.5
|
||||||
self.assertEqual(None, self.thermostat.target_temperature)
|
assert self.thermostat.target_temperature is None
|
||||||
|
|
||||||
self.thermostat._target_temperature = 127.0
|
self.thermostat._target_temperature = 127.0
|
||||||
self.assertEqual(None, self.thermostat.target_temperature)
|
assert self.thermostat.target_temperature is None
|
||||||
|
|
||||||
@patch.object(FritzboxThermostat, 'set_operation_mode')
|
@patch.object(FritzboxThermostat, 'set_operation_mode')
|
||||||
def test_set_temperature_operation_mode(self, mock_set_op):
|
def test_set_temperature_operation_mode(self, mock_set_op):
|
||||||
|
@ -101,20 +101,20 @@ class TestFritzboxClimate(unittest.TestCase):
|
||||||
def test_current_operation(self):
|
def test_current_operation(self):
|
||||||
"""Test operation mode property for different temperatures."""
|
"""Test operation mode property for different temperatures."""
|
||||||
self.thermostat._target_temperature = 127.0
|
self.thermostat._target_temperature = 127.0
|
||||||
self.assertEqual('on', self.thermostat.current_operation)
|
assert 'on' == self.thermostat.current_operation
|
||||||
self.thermostat._target_temperature = 126.5
|
self.thermostat._target_temperature = 126.5
|
||||||
self.assertEqual('off', self.thermostat.current_operation)
|
assert 'off' == self.thermostat.current_operation
|
||||||
self.thermostat._target_temperature = 22.0
|
self.thermostat._target_temperature = 22.0
|
||||||
self.assertEqual('heat', self.thermostat.current_operation)
|
assert 'heat' == self.thermostat.current_operation
|
||||||
self.thermostat._target_temperature = 16.0
|
self.thermostat._target_temperature = 16.0
|
||||||
self.assertEqual('eco', self.thermostat.current_operation)
|
assert 'eco' == self.thermostat.current_operation
|
||||||
self.thermostat._target_temperature = 12.5
|
self.thermostat._target_temperature = 12.5
|
||||||
self.assertEqual('manual', self.thermostat.current_operation)
|
assert 'manual' == self.thermostat.current_operation
|
||||||
|
|
||||||
def test_operation_list(self):
|
def test_operation_list(self):
|
||||||
"""Test operation_list property."""
|
"""Test operation_list property."""
|
||||||
self.assertEqual(['heat', 'eco', 'off', 'on'],
|
assert ['heat', 'eco', 'off', 'on'] == \
|
||||||
self.thermostat.operation_list)
|
self.thermostat.operation_list
|
||||||
|
|
||||||
@patch.object(FritzboxThermostat, 'set_temperature')
|
@patch.object(FritzboxThermostat, 'set_temperature')
|
||||||
def test_set_operation_mode(self, mock_set_temp):
|
def test_set_operation_mode(self, mock_set_temp):
|
||||||
|
@ -137,15 +137,15 @@ class TestFritzboxClimate(unittest.TestCase):
|
||||||
|
|
||||||
def test_min_max_temperature(self):
|
def test_min_max_temperature(self):
|
||||||
"""Test min_temp and max_temp properties."""
|
"""Test min_temp and max_temp properties."""
|
||||||
self.assertEqual(8.0, self.thermostat.min_temp)
|
assert 8.0 == self.thermostat.min_temp
|
||||||
self.assertEqual(28.0, self.thermostat.max_temp)
|
assert 28.0 == self.thermostat.max_temp
|
||||||
|
|
||||||
def test_device_state_attributes(self):
|
def test_device_state_attributes(self):
|
||||||
"""Test device_state property."""
|
"""Test device_state property."""
|
||||||
attr = self.thermostat.device_state_attributes
|
attr = self.thermostat.device_state_attributes
|
||||||
self.assertEqual(attr['device_locked'], True)
|
assert attr['device_locked'] is True
|
||||||
self.assertEqual(attr['locked'], False)
|
assert attr['locked'] is False
|
||||||
self.assertEqual(attr['battery_low'], True)
|
assert attr['battery_low'] is True
|
||||||
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
"""Test update function."""
|
"""Test update function."""
|
||||||
|
@ -160,10 +160,10 @@ class TestFritzboxClimate(unittest.TestCase):
|
||||||
self.thermostat.update()
|
self.thermostat.update()
|
||||||
|
|
||||||
device.update.assert_called_once_with()
|
device.update.assert_called_once_with()
|
||||||
self.assertEqual(10.0, self.thermostat._current_temperature)
|
assert 10.0 == self.thermostat._current_temperature
|
||||||
self.assertEqual(11.0, self.thermostat._target_temperature)
|
assert 11.0 == self.thermostat._target_temperature
|
||||||
self.assertEqual(12.0, self.thermostat._comfort_temperature)
|
assert 12.0 == self.thermostat._comfort_temperature
|
||||||
self.assertEqual(13.0, self.thermostat._eco_temperature)
|
assert 13.0 == self.thermostat._eco_temperature
|
||||||
|
|
||||||
def test_update_http_error(self):
|
def test_update_http_error(self):
|
||||||
"""Test exception handling of update function."""
|
"""Test exception handling of update function."""
|
||||||
|
|
|
@ -62,15 +62,13 @@ class TestSetupClimateGenericThermostat(unittest.TestCase):
|
||||||
|
|
||||||
def test_valid_conf(self):
|
def test_valid_conf(self):
|
||||||
"""Test set up generic_thermostat with valid config values."""
|
"""Test set up generic_thermostat with valid config values."""
|
||||||
self.assertTrue(
|
assert setup_component(self.hass, 'climate', {
|
||||||
setup_component(self.hass, 'climate',
|
'climate': {
|
||||||
{'climate': {
|
'platform': 'generic_thermostat',
|
||||||
'platform': 'generic_thermostat',
|
'name': 'test',
|
||||||
'name': 'test',
|
'heater': ENT_SWITCH,
|
||||||
'heater': ENT_SWITCH,
|
'target_sensor': ENT_SENSOR
|
||||||
'target_sensor': ENT_SENSOR
|
}})
|
||||||
}})
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TestGenericThermostatHeaterSwitching(unittest.TestCase):
|
class TestGenericThermostatHeaterSwitching(unittest.TestCase):
|
||||||
|
@ -83,9 +81,9 @@ class TestGenericThermostatHeaterSwitching(unittest.TestCase):
|
||||||
"""Set up things to be run when tests are started."""
|
"""Set up things to be run when tests are started."""
|
||||||
self.hass = get_test_home_assistant()
|
self.hass = get_test_home_assistant()
|
||||||
self.hass.config.units = METRIC_SYSTEM
|
self.hass.config.units = METRIC_SYSTEM
|
||||||
self.assertTrue(run_coroutine_threadsafe(
|
assert run_coroutine_threadsafe(
|
||||||
comps.async_setup(self.hass, {}), self.hass.loop
|
comps.async_setup(self.hass, {}), self.hass.loop
|
||||||
).result())
|
).result()
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
"""Stop down everything that was started."""
|
"""Stop down everything that was started."""
|
||||||
|
@ -104,16 +102,16 @@ class TestGenericThermostatHeaterSwitching(unittest.TestCase):
|
||||||
'target_sensor': ENT_SENSOR
|
'target_sensor': ENT_SENSOR
|
||||||
}})
|
}})
|
||||||
|
|
||||||
self.assertEqual(STATE_OFF,
|
assert STATE_OFF == \
|
||||||
self.hass.states.get(heater_switch).state)
|
self.hass.states.get(heater_switch).state
|
||||||
|
|
||||||
self._setup_sensor(18)
|
self._setup_sensor(18)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
common.set_temperature(self.hass, 23)
|
common.set_temperature(self.hass, 23)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(STATE_ON,
|
assert STATE_ON == \
|
||||||
self.hass.states.get(heater_switch).state)
|
self.hass.states.get(heater_switch).state
|
||||||
|
|
||||||
def test_heater_switch(self):
|
def test_heater_switch(self):
|
||||||
"""Test heater switching test switch."""
|
"""Test heater switching test switch."""
|
||||||
|
@ -131,16 +129,16 @@ class TestGenericThermostatHeaterSwitching(unittest.TestCase):
|
||||||
'target_sensor': ENT_SENSOR
|
'target_sensor': ENT_SENSOR
|
||||||
}})
|
}})
|
||||||
|
|
||||||
self.assertEqual(STATE_OFF,
|
assert STATE_OFF == \
|
||||||
self.hass.states.get(heater_switch).state)
|
self.hass.states.get(heater_switch).state
|
||||||
|
|
||||||
self._setup_sensor(18)
|
self._setup_sensor(18)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
common.set_temperature(self.hass, 23)
|
common.set_temperature(self.hass, 23)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(STATE_ON,
|
assert STATE_ON == \
|
||||||
self.hass.states.get(heater_switch).state)
|
self.hass.states.get(heater_switch).state
|
||||||
|
|
||||||
def _setup_sensor(self, temp):
|
def _setup_sensor(self, temp):
|
||||||
"""Set up the test sensor."""
|
"""Set up the test sensor."""
|
||||||
|
@ -170,31 +168,31 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||||
|
|
||||||
def test_setup_defaults_to_unknown(self):
|
def test_setup_defaults_to_unknown(self):
|
||||||
"""Test the setting of defaults to unknown."""
|
"""Test the setting of defaults to unknown."""
|
||||||
self.assertEqual(STATE_IDLE, self.hass.states.get(ENTITY).state)
|
assert STATE_IDLE == self.hass.states.get(ENTITY).state
|
||||||
|
|
||||||
def test_default_setup_params(self):
|
def test_default_setup_params(self):
|
||||||
"""Test the setup with default parameters."""
|
"""Test the setup with default parameters."""
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
self.assertEqual(7, state.attributes.get('min_temp'))
|
assert 7 == state.attributes.get('min_temp')
|
||||||
self.assertEqual(35, state.attributes.get('max_temp'))
|
assert 35 == state.attributes.get('max_temp')
|
||||||
self.assertEqual(7, state.attributes.get('temperature'))
|
assert 7 == state.attributes.get('temperature')
|
||||||
|
|
||||||
def test_get_operation_modes(self):
|
def test_get_operation_modes(self):
|
||||||
"""Test that the operation list returns the correct modes."""
|
"""Test that the operation list returns the correct modes."""
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
modes = state.attributes.get('operation_list')
|
modes = state.attributes.get('operation_list')
|
||||||
self.assertEqual([climate.STATE_HEAT, STATE_OFF], modes)
|
assert [climate.STATE_HEAT, STATE_OFF] == modes
|
||||||
|
|
||||||
def test_set_target_temp(self):
|
def test_set_target_temp(self):
|
||||||
"""Test the setting of the target temperature."""
|
"""Test the setting of the target temperature."""
|
||||||
common.set_temperature(self.hass, 30)
|
common.set_temperature(self.hass, 30)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
self.assertEqual(30.0, state.attributes.get('temperature'))
|
assert 30.0 == state.attributes.get('temperature')
|
||||||
common.set_temperature(self.hass, None)
|
common.set_temperature(self.hass, None)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
self.assertEqual(30.0, state.attributes.get('temperature'))
|
assert 30.0 == state.attributes.get('temperature')
|
||||||
|
|
||||||
def test_set_away_mode(self):
|
def test_set_away_mode(self):
|
||||||
"""Test the setting away mode."""
|
"""Test the setting away mode."""
|
||||||
|
@ -203,7 +201,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||||
common.set_away_mode(self.hass, True)
|
common.set_away_mode(self.hass, True)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
self.assertEqual(16, state.attributes.get('temperature'))
|
assert 16 == state.attributes.get('temperature')
|
||||||
|
|
||||||
def test_set_away_mode_and_restore_prev_temp(self):
|
def test_set_away_mode_and_restore_prev_temp(self):
|
||||||
"""Test the setting and removing away mode.
|
"""Test the setting and removing away mode.
|
||||||
|
@ -215,11 +213,11 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||||
common.set_away_mode(self.hass, True)
|
common.set_away_mode(self.hass, True)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
self.assertEqual(16, state.attributes.get('temperature'))
|
assert 16 == state.attributes.get('temperature')
|
||||||
common.set_away_mode(self.hass, False)
|
common.set_away_mode(self.hass, False)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
self.assertEqual(23, state.attributes.get('temperature'))
|
assert 23 == state.attributes.get('temperature')
|
||||||
|
|
||||||
def test_set_away_mode_twice_and_restore_prev_temp(self):
|
def test_set_away_mode_twice_and_restore_prev_temp(self):
|
||||||
"""Test the setting away mode twice in a row.
|
"""Test the setting away mode twice in a row.
|
||||||
|
@ -233,11 +231,11 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||||
common.set_away_mode(self.hass, True)
|
common.set_away_mode(self.hass, True)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
self.assertEqual(16, state.attributes.get('temperature'))
|
assert 16 == state.attributes.get('temperature')
|
||||||
common.set_away_mode(self.hass, False)
|
common.set_away_mode(self.hass, False)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
self.assertEqual(23, state.attributes.get('temperature'))
|
assert 23 == state.attributes.get('temperature')
|
||||||
|
|
||||||
def test_sensor_bad_value(self):
|
def test_sensor_bad_value(self):
|
||||||
"""Test sensor that have None as state."""
|
"""Test sensor that have None as state."""
|
||||||
|
@ -248,7 +246,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
self.assertEqual(temp, state.attributes.get('current_temperature'))
|
assert temp == state.attributes.get('current_temperature')
|
||||||
|
|
||||||
def test_set_target_temp_heater_on(self):
|
def test_set_target_temp_heater_on(self):
|
||||||
"""Test if target temperature turn heater on."""
|
"""Test if target temperature turn heater on."""
|
||||||
|
@ -257,11 +255,11 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
common.set_temperature(self.hass, 30)
|
common.set_temperature(self.hass, 30)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
assert SERVICE_TURN_ON == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_set_target_temp_heater_off(self):
|
def test_set_target_temp_heater_off(self):
|
||||||
"""Test if target temperature turn heater off."""
|
"""Test if target temperature turn heater off."""
|
||||||
|
@ -270,11 +268,11 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
common.set_temperature(self.hass, 25)
|
common.set_temperature(self.hass, 25)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(2, len(self.calls))
|
assert 2 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
assert SERVICE_TURN_OFF == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_temp_change_heater_on_within_tolerance(self):
|
def test_temp_change_heater_on_within_tolerance(self):
|
||||||
"""Test if temperature change doesn't turn on within tolerance."""
|
"""Test if temperature change doesn't turn on within tolerance."""
|
||||||
|
@ -283,7 +281,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(29)
|
self._setup_sensor(29)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_temp_change_heater_on_outside_tolerance(self):
|
def test_temp_change_heater_on_outside_tolerance(self):
|
||||||
"""Test if temperature change turn heater on outside cold tolerance."""
|
"""Test if temperature change turn heater on outside cold tolerance."""
|
||||||
|
@ -292,11 +290,11 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(27)
|
self._setup_sensor(27)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
assert SERVICE_TURN_ON == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_temp_change_heater_off_within_tolerance(self):
|
def test_temp_change_heater_off_within_tolerance(self):
|
||||||
"""Test if temperature change doesn't turn off within tolerance."""
|
"""Test if temperature change doesn't turn off within tolerance."""
|
||||||
|
@ -305,7 +303,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(33)
|
self._setup_sensor(33)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_temp_change_heater_off_outside_tolerance(self):
|
def test_temp_change_heater_off_outside_tolerance(self):
|
||||||
"""Test if temperature change turn heater off outside hot tolerance."""
|
"""Test if temperature change turn heater off outside hot tolerance."""
|
||||||
|
@ -314,11 +312,11 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(35)
|
self._setup_sensor(35)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
assert SERVICE_TURN_OFF == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_running_when_operating_mode_is_off(self):
|
def test_running_when_operating_mode_is_off(self):
|
||||||
"""Test that the switch turns off when enabled is set False."""
|
"""Test that the switch turns off when enabled is set False."""
|
||||||
|
@ -327,11 +325,11 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
common.set_operation_mode(self.hass, STATE_OFF)
|
common.set_operation_mode(self.hass, STATE_OFF)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
assert SERVICE_TURN_OFF == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_no_state_change_when_operation_mode_off(self):
|
def test_no_state_change_when_operation_mode_off(self):
|
||||||
"""Test that the switch doesn't turn on when enabled is False."""
|
"""Test that the switch doesn't turn on when enabled is False."""
|
||||||
|
@ -342,14 +340,14 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(25)
|
self._setup_sensor(25)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
@mock.patch('logging.Logger.error')
|
@mock.patch('logging.Logger.error')
|
||||||
def test_invalid_operating_mode(self, log_mock):
|
def test_invalid_operating_mode(self, log_mock):
|
||||||
"""Test error handling for invalid operation mode."""
|
"""Test error handling for invalid operation mode."""
|
||||||
common.set_operation_mode(self.hass, 'invalid mode')
|
common.set_operation_mode(self.hass, 'invalid mode')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(log_mock.call_count, 1)
|
assert log_mock.call_count == 1
|
||||||
|
|
||||||
def test_operating_mode_heat(self):
|
def test_operating_mode_heat(self):
|
||||||
"""Test change mode from OFF to HEAT.
|
"""Test change mode from OFF to HEAT.
|
||||||
|
@ -363,11 +361,11 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||||
self._setup_switch(False)
|
self._setup_switch(False)
|
||||||
common.set_operation_mode(self.hass, climate.STATE_HEAT)
|
common.set_operation_mode(self.hass, climate.STATE_HEAT)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
assert SERVICE_TURN_ON == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def _setup_sensor(self, temp):
|
def _setup_sensor(self, temp):
|
||||||
"""Set up the test sensor."""
|
"""Set up the test sensor."""
|
||||||
|
@ -416,11 +414,11 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
common.set_temperature(self.hass, 30)
|
common.set_temperature(self.hass, 30)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(2, len(self.calls))
|
assert 2 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
assert SERVICE_TURN_OFF == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_turn_away_mode_on_cooling(self):
|
def test_turn_away_mode_on_cooling(self):
|
||||||
"""Test the setting away mode when cooling."""
|
"""Test the setting away mode when cooling."""
|
||||||
|
@ -431,7 +429,7 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
|
||||||
common.set_away_mode(self.hass, True)
|
common.set_away_mode(self.hass, True)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
self.assertEqual(30, state.attributes.get('temperature'))
|
assert 30 == state.attributes.get('temperature')
|
||||||
|
|
||||||
def test_operating_mode_cool(self):
|
def test_operating_mode_cool(self):
|
||||||
"""Test change mode from OFF to COOL.
|
"""Test change mode from OFF to COOL.
|
||||||
|
@ -445,11 +443,11 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
|
||||||
self._setup_switch(False)
|
self._setup_switch(False)
|
||||||
common.set_operation_mode(self.hass, climate.STATE_COOL)
|
common.set_operation_mode(self.hass, climate.STATE_COOL)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
assert SERVICE_TURN_ON == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_set_target_temp_ac_on(self):
|
def test_set_target_temp_ac_on(self):
|
||||||
"""Test if target temperature turn ac on."""
|
"""Test if target temperature turn ac on."""
|
||||||
|
@ -458,11 +456,11 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
common.set_temperature(self.hass, 25)
|
common.set_temperature(self.hass, 25)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
assert SERVICE_TURN_ON == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_temp_change_ac_off_within_tolerance(self):
|
def test_temp_change_ac_off_within_tolerance(self):
|
||||||
"""Test if temperature change doesn't turn ac off within tolerance."""
|
"""Test if temperature change doesn't turn ac off within tolerance."""
|
||||||
|
@ -471,7 +469,7 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(29.8)
|
self._setup_sensor(29.8)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_set_temp_change_ac_off_outside_tolerance(self):
|
def test_set_temp_change_ac_off_outside_tolerance(self):
|
||||||
"""Test if temperature change turn ac off."""
|
"""Test if temperature change turn ac off."""
|
||||||
|
@ -480,11 +478,11 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(27)
|
self._setup_sensor(27)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
assert SERVICE_TURN_OFF == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_temp_change_ac_on_within_tolerance(self):
|
def test_temp_change_ac_on_within_tolerance(self):
|
||||||
"""Test if temperature change doesn't turn ac on within tolerance."""
|
"""Test if temperature change doesn't turn ac on within tolerance."""
|
||||||
|
@ -493,7 +491,7 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(25.2)
|
self._setup_sensor(25.2)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_temp_change_ac_on_outside_tolerance(self):
|
def test_temp_change_ac_on_outside_tolerance(self):
|
||||||
"""Test if temperature change turn ac on."""
|
"""Test if temperature change turn ac on."""
|
||||||
|
@ -502,11 +500,11 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(30)
|
self._setup_sensor(30)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
assert SERVICE_TURN_ON == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_running_when_operating_mode_is_off(self):
|
def test_running_when_operating_mode_is_off(self):
|
||||||
"""Test that the switch turns off when enabled is set False."""
|
"""Test that the switch turns off when enabled is set False."""
|
||||||
|
@ -515,11 +513,11 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
common.set_operation_mode(self.hass, STATE_OFF)
|
common.set_operation_mode(self.hass, STATE_OFF)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
assert SERVICE_TURN_OFF == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_no_state_change_when_operation_mode_off(self):
|
def test_no_state_change_when_operation_mode_off(self):
|
||||||
"""Test that the switch doesn't turn on when enabled is False."""
|
"""Test that the switch doesn't turn on when enabled is False."""
|
||||||
|
@ -530,7 +528,7 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(35)
|
self._setup_sensor(35)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def _setup_sensor(self, temp):
|
def _setup_sensor(self, temp):
|
||||||
"""Set up the test sensor."""
|
"""Set up the test sensor."""
|
||||||
|
@ -579,7 +577,7 @@ class TestClimateGenericThermostatACModeMinCycle(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(30)
|
self._setup_sensor(30)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_temp_change_ac_trigger_on_long_enough(self):
|
def test_temp_change_ac_trigger_on_long_enough(self):
|
||||||
"""Test if temperature change turn ac on."""
|
"""Test if temperature change turn ac on."""
|
||||||
|
@ -592,11 +590,11 @@ class TestClimateGenericThermostatACModeMinCycle(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(30)
|
self._setup_sensor(30)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
assert SERVICE_TURN_ON == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_temp_change_ac_trigger_off_not_long_enough(self):
|
def test_temp_change_ac_trigger_off_not_long_enough(self):
|
||||||
"""Test if temperature change turn ac on."""
|
"""Test if temperature change turn ac on."""
|
||||||
|
@ -605,7 +603,7 @@ class TestClimateGenericThermostatACModeMinCycle(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(25)
|
self._setup_sensor(25)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_temp_change_ac_trigger_off_long_enough(self):
|
def test_temp_change_ac_trigger_off_long_enough(self):
|
||||||
"""Test if temperature change turn ac on."""
|
"""Test if temperature change turn ac on."""
|
||||||
|
@ -618,11 +616,11 @@ class TestClimateGenericThermostatACModeMinCycle(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(25)
|
self._setup_sensor(25)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
assert SERVICE_TURN_OFF == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def _setup_sensor(self, temp):
|
def _setup_sensor(self, temp):
|
||||||
"""Set up the test sensor."""
|
"""Set up the test sensor."""
|
||||||
|
@ -670,7 +668,7 @@ class TestClimateGenericThermostatMinCycle(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(30)
|
self._setup_sensor(30)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_temp_change_heater_trigger_on_not_long_enough(self):
|
def test_temp_change_heater_trigger_on_not_long_enough(self):
|
||||||
"""Test if temp change doesn't turn heater on because of time."""
|
"""Test if temp change doesn't turn heater on because of time."""
|
||||||
|
@ -679,7 +677,7 @@ class TestClimateGenericThermostatMinCycle(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(25)
|
self._setup_sensor(25)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_temp_change_heater_trigger_on_long_enough(self):
|
def test_temp_change_heater_trigger_on_long_enough(self):
|
||||||
"""Test if temperature change turn heater on after min cycle."""
|
"""Test if temperature change turn heater on after min cycle."""
|
||||||
|
@ -692,11 +690,11 @@ class TestClimateGenericThermostatMinCycle(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(25)
|
self._setup_sensor(25)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
assert SERVICE_TURN_ON == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_temp_change_heater_trigger_off_long_enough(self):
|
def test_temp_change_heater_trigger_off_long_enough(self):
|
||||||
"""Test if temperature change turn heater off after min cycle."""
|
"""Test if temperature change turn heater off after min cycle."""
|
||||||
|
@ -709,11 +707,11 @@ class TestClimateGenericThermostatMinCycle(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self._setup_sensor(30)
|
self._setup_sensor(30)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
assert SERVICE_TURN_OFF == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def _setup_sensor(self, temp):
|
def _setup_sensor(self, temp):
|
||||||
"""Set up the test sensor."""
|
"""Set up the test sensor."""
|
||||||
|
@ -767,17 +765,17 @@ class TestClimateGenericThermostatACKeepAlive(unittest.TestCase):
|
||||||
test_time = datetime.datetime.now(pytz.UTC)
|
test_time = datetime.datetime.now(pytz.UTC)
|
||||||
self._send_time_changed(test_time)
|
self._send_time_changed(test_time)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
self._send_time_changed(test_time + datetime.timedelta(minutes=5))
|
self._send_time_changed(test_time + datetime.timedelta(minutes=5))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
self._send_time_changed(test_time + datetime.timedelta(minutes=10))
|
self._send_time_changed(test_time + datetime.timedelta(minutes=10))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
assert SERVICE_TURN_ON == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_temp_change_ac_trigger_off_long_enough(self):
|
def test_temp_change_ac_trigger_off_long_enough(self):
|
||||||
"""Test if turn on signal is sent at keep-alive intervals."""
|
"""Test if turn on signal is sent at keep-alive intervals."""
|
||||||
|
@ -790,17 +788,17 @@ class TestClimateGenericThermostatACKeepAlive(unittest.TestCase):
|
||||||
test_time = datetime.datetime.now(pytz.UTC)
|
test_time = datetime.datetime.now(pytz.UTC)
|
||||||
self._send_time_changed(test_time)
|
self._send_time_changed(test_time)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
self._send_time_changed(test_time + datetime.timedelta(minutes=5))
|
self._send_time_changed(test_time + datetime.timedelta(minutes=5))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
self._send_time_changed(test_time + datetime.timedelta(minutes=10))
|
self._send_time_changed(test_time + datetime.timedelta(minutes=10))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
assert SERVICE_TURN_OFF == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def _send_time_changed(self, now):
|
def _send_time_changed(self, now):
|
||||||
"""Send a time changed event."""
|
"""Send a time changed event."""
|
||||||
|
@ -857,17 +855,17 @@ class TestClimateGenericThermostatKeepAlive(unittest.TestCase):
|
||||||
test_time = datetime.datetime.now(pytz.UTC)
|
test_time = datetime.datetime.now(pytz.UTC)
|
||||||
self._send_time_changed(test_time)
|
self._send_time_changed(test_time)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
self._send_time_changed(test_time + datetime.timedelta(minutes=5))
|
self._send_time_changed(test_time + datetime.timedelta(minutes=5))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
self._send_time_changed(test_time + datetime.timedelta(minutes=10))
|
self._send_time_changed(test_time + datetime.timedelta(minutes=10))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
assert SERVICE_TURN_ON == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def test_temp_change_heater_trigger_off_long_enough(self):
|
def test_temp_change_heater_trigger_off_long_enough(self):
|
||||||
"""Test if turn on signal is sent at keep-alive intervals."""
|
"""Test if turn on signal is sent at keep-alive intervals."""
|
||||||
|
@ -880,17 +878,17 @@ class TestClimateGenericThermostatKeepAlive(unittest.TestCase):
|
||||||
test_time = datetime.datetime.now(pytz.UTC)
|
test_time = datetime.datetime.now(pytz.UTC)
|
||||||
self._send_time_changed(test_time)
|
self._send_time_changed(test_time)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
self._send_time_changed(test_time + datetime.timedelta(minutes=5))
|
self._send_time_changed(test_time + datetime.timedelta(minutes=5))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
self._send_time_changed(test_time + datetime.timedelta(minutes=10))
|
self._send_time_changed(test_time + datetime.timedelta(minutes=10))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
call = self.calls[0]
|
call = self.calls[0]
|
||||||
self.assertEqual('homeassistant', call.domain)
|
assert 'homeassistant' == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
assert SERVICE_TURN_OFF == call.service
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
assert ENT_SWITCH == call.data['entity_id']
|
||||||
|
|
||||||
def _send_time_changed(self, now):
|
def _send_time_changed(self, now):
|
||||||
"""Send a time changed event."""
|
"""Send a time changed event."""
|
||||||
|
@ -951,10 +949,10 @@ class TestClimateGenericThermostatTurnOnOff(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state_heat = self.hass.states.get(self.HEAT_ENTITY)
|
state_heat = self.hass.states.get(self.HEAT_ENTITY)
|
||||||
state_cool = self.hass.states.get(self.COOL_ENTITY)
|
state_cool = self.hass.states.get(self.COOL_ENTITY)
|
||||||
self.assertEqual(STATE_HEAT,
|
assert STATE_HEAT == \
|
||||||
state_heat.attributes.get('operation_mode'))
|
state_heat.attributes.get('operation_mode')
|
||||||
self.assertEqual(STATE_COOL,
|
assert STATE_COOL == \
|
||||||
state_cool.attributes.get('operation_mode'))
|
state_cool.attributes.get('operation_mode')
|
||||||
|
|
||||||
def test_turn_on_when_on(self):
|
def test_turn_on_when_on(self):
|
||||||
"""Test if climate.turn_on does nothing to a turned on device."""
|
"""Test if climate.turn_on does nothing to a turned on device."""
|
||||||
|
@ -965,10 +963,10 @@ class TestClimateGenericThermostatTurnOnOff(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state_heat = self.hass.states.get(self.HEAT_ENTITY)
|
state_heat = self.hass.states.get(self.HEAT_ENTITY)
|
||||||
state_cool = self.hass.states.get(self.COOL_ENTITY)
|
state_cool = self.hass.states.get(self.COOL_ENTITY)
|
||||||
self.assertEqual(STATE_HEAT,
|
assert STATE_HEAT == \
|
||||||
state_heat.attributes.get('operation_mode'))
|
state_heat.attributes.get('operation_mode')
|
||||||
self.assertEqual(STATE_COOL,
|
assert STATE_COOL == \
|
||||||
state_cool.attributes.get('operation_mode'))
|
state_cool.attributes.get('operation_mode')
|
||||||
|
|
||||||
def test_turn_off_when_on(self):
|
def test_turn_off_when_on(self):
|
||||||
"""Test if climate.turn_off turns off a turned on device."""
|
"""Test if climate.turn_off turns off a turned on device."""
|
||||||
|
@ -979,10 +977,10 @@ class TestClimateGenericThermostatTurnOnOff(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state_heat = self.hass.states.get(self.HEAT_ENTITY)
|
state_heat = self.hass.states.get(self.HEAT_ENTITY)
|
||||||
state_cool = self.hass.states.get(self.COOL_ENTITY)
|
state_cool = self.hass.states.get(self.COOL_ENTITY)
|
||||||
self.assertEqual(STATE_OFF,
|
assert STATE_OFF == \
|
||||||
state_heat.attributes.get('operation_mode'))
|
state_heat.attributes.get('operation_mode')
|
||||||
self.assertEqual(STATE_OFF,
|
assert STATE_OFF == \
|
||||||
state_cool.attributes.get('operation_mode'))
|
state_cool.attributes.get('operation_mode')
|
||||||
|
|
||||||
def test_turn_off_when_off(self):
|
def test_turn_off_when_off(self):
|
||||||
"""Test if climate.turn_off does nothing to a turned off device."""
|
"""Test if climate.turn_off does nothing to a turned off device."""
|
||||||
|
@ -992,10 +990,10 @@ class TestClimateGenericThermostatTurnOnOff(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state_heat = self.hass.states.get(self.HEAT_ENTITY)
|
state_heat = self.hass.states.get(self.HEAT_ENTITY)
|
||||||
state_cool = self.hass.states.get(self.COOL_ENTITY)
|
state_cool = self.hass.states.get(self.COOL_ENTITY)
|
||||||
self.assertEqual(STATE_OFF,
|
assert STATE_OFF == \
|
||||||
state_heat.attributes.get('operation_mode'))
|
state_heat.attributes.get('operation_mode')
|
||||||
self.assertEqual(STATE_OFF,
|
assert STATE_OFF == \
|
||||||
state_cool.attributes.get('operation_mode'))
|
state_cool.attributes.get('operation_mode')
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -1096,18 +1094,18 @@ class TestClimateGenericThermostatRestoreState(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
self.assertEqual(20, state.attributes[ATTR_TEMPERATURE])
|
assert 20 == state.attributes[ATTR_TEMPERATURE]
|
||||||
self.assertEqual(STATE_OFF,
|
assert STATE_OFF == \
|
||||||
state.attributes[climate.ATTR_OPERATION_MODE])
|
state.attributes[climate.ATTR_OPERATION_MODE]
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
self._setup_switch(False)
|
self._setup_switch(False)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
self.assertEqual(STATE_OFF,
|
assert STATE_OFF == \
|
||||||
state.attributes[climate.ATTR_OPERATION_MODE])
|
state.attributes[climate.ATTR_OPERATION_MODE]
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
def _setup_climate(self):
|
def _setup_climate(self):
|
||||||
assert setup_component(self.hass, climate.DOMAIN, {'climate': {
|
assert setup_component(self.hass, climate.DOMAIN, {'climate': {
|
||||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.components.climate import (
|
||||||
ATTR_FAN_MODE, ATTR_OPERATION_MODE, ATTR_FAN_LIST, ATTR_OPERATION_LIST)
|
ATTR_FAN_MODE, ATTR_OPERATION_MODE, ATTR_FAN_LIST, ATTR_OPERATION_LIST)
|
||||||
|
|
||||||
import homeassistant.components.climate.honeywell as honeywell
|
import homeassistant.components.climate.honeywell as honeywell
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
class TestHoneywell(unittest.TestCase):
|
class TestHoneywell(unittest.TestCase):
|
||||||
|
@ -43,16 +44,16 @@ class TestHoneywell(unittest.TestCase):
|
||||||
honeywell.CONF_REGION: 'un',
|
honeywell.CONF_REGION: 'un',
|
||||||
}
|
}
|
||||||
|
|
||||||
with self.assertRaises(vol.Invalid):
|
with pytest.raises(vol.Invalid):
|
||||||
honeywell.PLATFORM_SCHEMA(None)
|
honeywell.PLATFORM_SCHEMA(None)
|
||||||
|
|
||||||
with self.assertRaises(vol.Invalid):
|
with pytest.raises(vol.Invalid):
|
||||||
honeywell.PLATFORM_SCHEMA({})
|
honeywell.PLATFORM_SCHEMA({})
|
||||||
|
|
||||||
with self.assertRaises(vol.Invalid):
|
with pytest.raises(vol.Invalid):
|
||||||
honeywell.PLATFORM_SCHEMA(bad_pass_config)
|
honeywell.PLATFORM_SCHEMA(bad_pass_config)
|
||||||
|
|
||||||
with self.assertRaises(vol.Invalid):
|
with pytest.raises(vol.Invalid):
|
||||||
honeywell.PLATFORM_SCHEMA(bad_region_config)
|
honeywell.PLATFORM_SCHEMA(bad_region_config)
|
||||||
|
|
||||||
hass = mock.MagicMock()
|
hass = mock.MagicMock()
|
||||||
|
@ -70,9 +71,9 @@ class TestHoneywell(unittest.TestCase):
|
||||||
locations[1].devices_by_id.values.return_value = devices_2
|
locations[1].devices_by_id.values.return_value = devices_2
|
||||||
|
|
||||||
result = honeywell.setup_platform(hass, config, add_entities)
|
result = honeywell.setup_platform(hass, config, add_entities)
|
||||||
self.assertTrue(result)
|
assert result
|
||||||
self.assertEqual(mock_sc.call_count, 1)
|
assert mock_sc.call_count == 1
|
||||||
self.assertEqual(mock_sc.call_args, mock.call('user', 'pass'))
|
assert mock_sc.call_args == mock.call('user', 'pass')
|
||||||
mock_ht.assert_has_calls([
|
mock_ht.assert_has_calls([
|
||||||
mock.call(mock_sc.return_value, devices_1[0], 18, 28,
|
mock.call(mock_sc.return_value, devices_1[0], 18, 28,
|
||||||
'user', 'pass'),
|
'user', 'pass'),
|
||||||
|
@ -95,13 +96,13 @@ class TestHoneywell(unittest.TestCase):
|
||||||
|
|
||||||
mock_sc.side_effect = somecomfort.AuthError
|
mock_sc.side_effect = somecomfort.AuthError
|
||||||
result = honeywell.setup_platform(hass, config, add_entities)
|
result = honeywell.setup_platform(hass, config, add_entities)
|
||||||
self.assertFalse(result)
|
assert not result
|
||||||
self.assertFalse(add_entities.called)
|
assert not add_entities.called
|
||||||
|
|
||||||
mock_sc.side_effect = somecomfort.SomeComfortError
|
mock_sc.side_effect = somecomfort.SomeComfortError
|
||||||
result = honeywell.setup_platform(hass, config, add_entities)
|
result = honeywell.setup_platform(hass, config, add_entities)
|
||||||
self.assertFalse(result)
|
assert not result
|
||||||
self.assertFalse(add_entities.called)
|
assert not add_entities.called
|
||||||
|
|
||||||
@mock.patch('somecomfort.SomeComfort')
|
@mock.patch('somecomfort.SomeComfort')
|
||||||
@mock.patch('homeassistant.components.climate.'
|
@mock.patch('homeassistant.components.climate.'
|
||||||
|
@ -137,8 +138,7 @@ class TestHoneywell(unittest.TestCase):
|
||||||
mock_sc.return_value = mock.MagicMock(locations_by_id=locations)
|
mock_sc.return_value = mock.MagicMock(locations_by_id=locations)
|
||||||
hass = mock.MagicMock()
|
hass = mock.MagicMock()
|
||||||
add_entities = mock.MagicMock()
|
add_entities = mock.MagicMock()
|
||||||
self.assertEqual(True,
|
assert honeywell.setup_platform(hass, config, add_entities) is True
|
||||||
honeywell.setup_platform(hass, config, add_entities))
|
|
||||||
|
|
||||||
return mock_ht.call_args_list, mock_sc
|
return mock_ht.call_args_list, mock_sc
|
||||||
|
|
||||||
|
@ -147,29 +147,28 @@ class TestHoneywell(unittest.TestCase):
|
||||||
result, client = self._test_us_filtered_devices(
|
result, client = self._test_us_filtered_devices(
|
||||||
dev=mock.sentinel.loc1dev1)
|
dev=mock.sentinel.loc1dev1)
|
||||||
devices = [x[0][1].deviceid for x in result]
|
devices = [x[0][1].deviceid for x in result]
|
||||||
self.assertEqual([mock.sentinel.loc1dev1], devices)
|
assert [mock.sentinel.loc1dev1] == devices
|
||||||
|
|
||||||
def test_us_filtered_thermostat_2(self):
|
def test_us_filtered_thermostat_2(self):
|
||||||
"""Test for US filtered location."""
|
"""Test for US filtered location."""
|
||||||
result, client = self._test_us_filtered_devices(
|
result, client = self._test_us_filtered_devices(
|
||||||
dev=mock.sentinel.loc2dev1)
|
dev=mock.sentinel.loc2dev1)
|
||||||
devices = [x[0][1].deviceid for x in result]
|
devices = [x[0][1].deviceid for x in result]
|
||||||
self.assertEqual([mock.sentinel.loc2dev1], devices)
|
assert [mock.sentinel.loc2dev1] == devices
|
||||||
|
|
||||||
def test_us_filtered_location_1(self):
|
def test_us_filtered_location_1(self):
|
||||||
"""Test for US filtered locations."""
|
"""Test for US filtered locations."""
|
||||||
result, client = self._test_us_filtered_devices(
|
result, client = self._test_us_filtered_devices(
|
||||||
loc=mock.sentinel.loc1)
|
loc=mock.sentinel.loc1)
|
||||||
devices = [x[0][1].deviceid for x in result]
|
devices = [x[0][1].deviceid for x in result]
|
||||||
self.assertEqual([mock.sentinel.loc1dev1,
|
assert [mock.sentinel.loc1dev1, mock.sentinel.loc1dev2] == devices
|
||||||
mock.sentinel.loc1dev2], devices)
|
|
||||||
|
|
||||||
def test_us_filtered_location_2(self):
|
def test_us_filtered_location_2(self):
|
||||||
"""Test for US filtered locations."""
|
"""Test for US filtered locations."""
|
||||||
result, client = self._test_us_filtered_devices(
|
result, client = self._test_us_filtered_devices(
|
||||||
loc=mock.sentinel.loc2)
|
loc=mock.sentinel.loc2)
|
||||||
devices = [x[0][1].deviceid for x in result]
|
devices = [x[0][1].deviceid for x in result]
|
||||||
self.assertEqual([mock.sentinel.loc2dev1], devices)
|
assert [mock.sentinel.loc2dev1] == devices
|
||||||
|
|
||||||
@mock.patch('evohomeclient.EvohomeClient')
|
@mock.patch('evohomeclient.EvohomeClient')
|
||||||
@mock.patch('homeassistant.components.climate.honeywell.'
|
@mock.patch('homeassistant.components.climate.honeywell.'
|
||||||
|
@ -186,19 +185,17 @@ class TestHoneywell(unittest.TestCase):
|
||||||
{'id': 'foo'}, {'id': 'bar'}]
|
{'id': 'foo'}, {'id': 'bar'}]
|
||||||
hass = mock.MagicMock()
|
hass = mock.MagicMock()
|
||||||
add_entities = mock.MagicMock()
|
add_entities = mock.MagicMock()
|
||||||
self.assertTrue(honeywell.setup_platform(hass, config, add_entities))
|
assert honeywell.setup_platform(hass, config, add_entities)
|
||||||
self.assertEqual(mock_evo.call_count, 1)
|
assert mock_evo.call_count == 1
|
||||||
self.assertEqual(mock_evo.call_args, mock.call('user', 'pass'))
|
assert mock_evo.call_args == mock.call('user', 'pass')
|
||||||
self.assertEqual(mock_evo.return_value.temperatures.call_count, 1)
|
assert mock_evo.return_value.temperatures.call_count == 1
|
||||||
self.assertEqual(
|
assert mock_evo.return_value.temperatures.call_args == \
|
||||||
mock_evo.return_value.temperatures.call_args,
|
|
||||||
mock.call(force_refresh=True)
|
mock.call(force_refresh=True)
|
||||||
)
|
|
||||||
mock_round.assert_has_calls([
|
mock_round.assert_has_calls([
|
||||||
mock.call(mock_evo.return_value, 'foo', True, 20.0),
|
mock.call(mock_evo.return_value, 'foo', True, 20.0),
|
||||||
mock.call(mock_evo.return_value, 'bar', False, 20.0),
|
mock.call(mock_evo.return_value, 'bar', False, 20.0),
|
||||||
])
|
])
|
||||||
self.assertEqual(2, add_entities.call_count)
|
assert 2 == add_entities.call_count
|
||||||
|
|
||||||
@mock.patch('evohomeclient.EvohomeClient')
|
@mock.patch('evohomeclient.EvohomeClient')
|
||||||
@mock.patch('homeassistant.components.climate.honeywell.'
|
@mock.patch('homeassistant.components.climate.honeywell.'
|
||||||
|
@ -218,7 +215,7 @@ class TestHoneywell(unittest.TestCase):
|
||||||
|
|
||||||
hass = mock.MagicMock()
|
hass = mock.MagicMock()
|
||||||
add_entities = mock.MagicMock()
|
add_entities = mock.MagicMock()
|
||||||
self.assertTrue(honeywell.setup_platform(hass, config, add_entities))
|
assert honeywell.setup_platform(hass, config, add_entities)
|
||||||
mock_round.assert_has_calls([
|
mock_round.assert_has_calls([
|
||||||
mock.call(mock_evo.return_value, 'foo', True, 16),
|
mock.call(mock_evo.return_value, 'foo', True, 16),
|
||||||
mock.call(mock_evo.return_value, 'bar', False, 16),
|
mock.call(mock_evo.return_value, 'bar', False, 16),
|
||||||
|
@ -236,7 +233,7 @@ class TestHoneywell(unittest.TestCase):
|
||||||
honeywell.CONF_REGION: 'eu',
|
honeywell.CONF_REGION: 'eu',
|
||||||
}
|
}
|
||||||
|
|
||||||
with self.assertRaises(vol.Invalid):
|
with pytest.raises(vol.Invalid):
|
||||||
honeywell.PLATFORM_SCHEMA(config)
|
honeywell.PLATFORM_SCHEMA(config)
|
||||||
|
|
||||||
@mock.patch('evohomeclient.EvohomeClient')
|
@mock.patch('evohomeclient.EvohomeClient')
|
||||||
|
@ -253,7 +250,7 @@ class TestHoneywell(unittest.TestCase):
|
||||||
mock_evo.return_value.temperatures.side_effect = socket.error
|
mock_evo.return_value.temperatures.side_effect = socket.error
|
||||||
add_entities = mock.MagicMock()
|
add_entities = mock.MagicMock()
|
||||||
hass = mock.MagicMock()
|
hass = mock.MagicMock()
|
||||||
self.assertFalse(honeywell.setup_platform(hass, config, add_entities))
|
assert not honeywell.setup_platform(hass, config, add_entities)
|
||||||
|
|
||||||
|
|
||||||
class TestHoneywellRound(unittest.TestCase):
|
class TestHoneywellRound(unittest.TestCase):
|
||||||
|
@ -282,53 +279,47 @@ class TestHoneywellRound(unittest.TestCase):
|
||||||
|
|
||||||
def test_attributes(self):
|
def test_attributes(self):
|
||||||
"""Test the attributes."""
|
"""Test the attributes."""
|
||||||
self.assertEqual('House', self.round1.name)
|
assert 'House' == self.round1.name
|
||||||
self.assertEqual(TEMP_CELSIUS, self.round1.temperature_unit)
|
assert TEMP_CELSIUS == self.round1.temperature_unit
|
||||||
self.assertEqual(20, self.round1.current_temperature)
|
assert 20 == self.round1.current_temperature
|
||||||
self.assertEqual(21, self.round1.target_temperature)
|
assert 21 == self.round1.target_temperature
|
||||||
self.assertFalse(self.round1.is_away_mode_on)
|
assert not self.round1.is_away_mode_on
|
||||||
|
|
||||||
self.assertEqual('Hot Water', self.round2.name)
|
assert 'Hot Water' == self.round2.name
|
||||||
self.assertEqual(TEMP_CELSIUS, self.round2.temperature_unit)
|
assert TEMP_CELSIUS == self.round2.temperature_unit
|
||||||
self.assertEqual(21, self.round2.current_temperature)
|
assert 21 == self.round2.current_temperature
|
||||||
self.assertEqual(None, self.round2.target_temperature)
|
assert self.round2.target_temperature is None
|
||||||
self.assertFalse(self.round2.is_away_mode_on)
|
assert not self.round2.is_away_mode_on
|
||||||
|
|
||||||
def test_away_mode(self):
|
def test_away_mode(self):
|
||||||
"""Test setting the away mode."""
|
"""Test setting the away mode."""
|
||||||
self.assertFalse(self.round1.is_away_mode_on)
|
assert not self.round1.is_away_mode_on
|
||||||
self.round1.turn_away_mode_on()
|
self.round1.turn_away_mode_on()
|
||||||
self.assertTrue(self.round1.is_away_mode_on)
|
assert self.round1.is_away_mode_on
|
||||||
self.assertEqual(self.device.set_temperature.call_count, 1)
|
assert self.device.set_temperature.call_count == 1
|
||||||
self.assertEqual(
|
assert self.device.set_temperature.call_args == mock.call('House', 16)
|
||||||
self.device.set_temperature.call_args, mock.call('House', 16)
|
|
||||||
)
|
|
||||||
|
|
||||||
self.device.set_temperature.reset_mock()
|
self.device.set_temperature.reset_mock()
|
||||||
self.round1.turn_away_mode_off()
|
self.round1.turn_away_mode_off()
|
||||||
self.assertFalse(self.round1.is_away_mode_on)
|
assert not self.round1.is_away_mode_on
|
||||||
self.assertEqual(self.device.cancel_temp_override.call_count, 1)
|
assert self.device.cancel_temp_override.call_count == 1
|
||||||
self.assertEqual(
|
assert self.device.cancel_temp_override.call_args == mock.call('House')
|
||||||
self.device.cancel_temp_override.call_args, mock.call('House')
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_set_temperature(self):
|
def test_set_temperature(self):
|
||||||
"""Test setting the temperature."""
|
"""Test setting the temperature."""
|
||||||
self.round1.set_temperature(temperature=25)
|
self.round1.set_temperature(temperature=25)
|
||||||
self.assertEqual(self.device.set_temperature.call_count, 1)
|
assert self.device.set_temperature.call_count == 1
|
||||||
self.assertEqual(
|
assert self.device.set_temperature.call_args == mock.call('House', 25)
|
||||||
self.device.set_temperature.call_args, mock.call('House', 25)
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_set_operation_mode(self) -> None:
|
def test_set_operation_mode(self) -> None:
|
||||||
"""Test setting the system operation."""
|
"""Test setting the system operation."""
|
||||||
self.round1.set_operation_mode('cool')
|
self.round1.set_operation_mode('cool')
|
||||||
self.assertEqual('cool', self.round1.current_operation)
|
assert 'cool' == self.round1.current_operation
|
||||||
self.assertEqual('cool', self.device.system_mode)
|
assert 'cool' == self.device.system_mode
|
||||||
|
|
||||||
self.round1.set_operation_mode('heat')
|
self.round1.set_operation_mode('heat')
|
||||||
self.assertEqual('heat', self.round1.current_operation)
|
assert 'heat' == self.round1.current_operation
|
||||||
self.assertEqual('heat', self.device.system_mode)
|
assert 'heat' == self.device.system_mode
|
||||||
|
|
||||||
|
|
||||||
class TestHoneywellUS(unittest.TestCase):
|
class TestHoneywellUS(unittest.TestCase):
|
||||||
|
@ -356,41 +347,41 @@ class TestHoneywellUS(unittest.TestCase):
|
||||||
|
|
||||||
def test_properties(self):
|
def test_properties(self):
|
||||||
"""Test the properties."""
|
"""Test the properties."""
|
||||||
self.assertTrue(self.honeywell.is_fan_on)
|
assert self.honeywell.is_fan_on
|
||||||
self.assertEqual('test', self.honeywell.name)
|
assert 'test' == self.honeywell.name
|
||||||
self.assertEqual(72, self.honeywell.current_temperature)
|
assert 72 == self.honeywell.current_temperature
|
||||||
|
|
||||||
def test_unit_of_measurement(self):
|
def test_unit_of_measurement(self):
|
||||||
"""Test the unit of measurement."""
|
"""Test the unit of measurement."""
|
||||||
self.assertEqual(TEMP_FAHRENHEIT, self.honeywell.temperature_unit)
|
assert TEMP_FAHRENHEIT == self.honeywell.temperature_unit
|
||||||
self.device.temperature_unit = 'C'
|
self.device.temperature_unit = 'C'
|
||||||
self.assertEqual(TEMP_CELSIUS, self.honeywell.temperature_unit)
|
assert TEMP_CELSIUS == self.honeywell.temperature_unit
|
||||||
|
|
||||||
def test_target_temp(self):
|
def test_target_temp(self):
|
||||||
"""Test the target temperature."""
|
"""Test the target temperature."""
|
||||||
self.assertEqual(65, self.honeywell.target_temperature)
|
assert 65 == self.honeywell.target_temperature
|
||||||
self.device.system_mode = 'cool'
|
self.device.system_mode = 'cool'
|
||||||
self.assertEqual(78, self.honeywell.target_temperature)
|
assert 78 == self.honeywell.target_temperature
|
||||||
|
|
||||||
def test_set_temp(self):
|
def test_set_temp(self):
|
||||||
"""Test setting the temperature."""
|
"""Test setting the temperature."""
|
||||||
self.honeywell.set_temperature(temperature=70)
|
self.honeywell.set_temperature(temperature=70)
|
||||||
self.assertEqual(70, self.device.setpoint_heat)
|
assert 70 == self.device.setpoint_heat
|
||||||
self.assertEqual(70, self.honeywell.target_temperature)
|
assert 70 == self.honeywell.target_temperature
|
||||||
|
|
||||||
self.device.system_mode = 'cool'
|
self.device.system_mode = 'cool'
|
||||||
self.assertEqual(78, self.honeywell.target_temperature)
|
assert 78 == self.honeywell.target_temperature
|
||||||
self.honeywell.set_temperature(temperature=74)
|
self.honeywell.set_temperature(temperature=74)
|
||||||
self.assertEqual(74, self.device.setpoint_cool)
|
assert 74 == self.device.setpoint_cool
|
||||||
self.assertEqual(74, self.honeywell.target_temperature)
|
assert 74 == self.honeywell.target_temperature
|
||||||
|
|
||||||
def test_set_operation_mode(self) -> None:
|
def test_set_operation_mode(self) -> None:
|
||||||
"""Test setting the operation mode."""
|
"""Test setting the operation mode."""
|
||||||
self.honeywell.set_operation_mode('cool')
|
self.honeywell.set_operation_mode('cool')
|
||||||
self.assertEqual('cool', self.device.system_mode)
|
assert 'cool' == self.device.system_mode
|
||||||
|
|
||||||
self.honeywell.set_operation_mode('heat')
|
self.honeywell.set_operation_mode('heat')
|
||||||
self.assertEqual('heat', self.device.system_mode)
|
assert 'heat' == self.device.system_mode
|
||||||
|
|
||||||
def test_set_temp_fail(self):
|
def test_set_temp_fail(self):
|
||||||
"""Test if setting the temperature fails."""
|
"""Test if setting the temperature fails."""
|
||||||
|
@ -407,10 +398,10 @@ class TestHoneywellUS(unittest.TestCase):
|
||||||
ATTR_FAN_LIST: somecomfort.FAN_MODES,
|
ATTR_FAN_LIST: somecomfort.FAN_MODES,
|
||||||
ATTR_OPERATION_LIST: somecomfort.SYSTEM_MODES,
|
ATTR_OPERATION_LIST: somecomfort.SYSTEM_MODES,
|
||||||
}
|
}
|
||||||
self.assertEqual(expected, self.honeywell.device_state_attributes)
|
assert expected == self.honeywell.device_state_attributes
|
||||||
expected['fan'] = 'idle'
|
expected['fan'] = 'idle'
|
||||||
self.device.fan_running = False
|
self.device.fan_running = False
|
||||||
self.assertEqual(expected, self.honeywell.device_state_attributes)
|
assert expected == self.honeywell.device_state_attributes
|
||||||
|
|
||||||
def test_with_no_fan(self):
|
def test_with_no_fan(self):
|
||||||
"""Test if there is on fan."""
|
"""Test if there is on fan."""
|
||||||
|
@ -423,24 +414,24 @@ class TestHoneywellUS(unittest.TestCase):
|
||||||
ATTR_FAN_LIST: somecomfort.FAN_MODES,
|
ATTR_FAN_LIST: somecomfort.FAN_MODES,
|
||||||
ATTR_OPERATION_LIST: somecomfort.SYSTEM_MODES,
|
ATTR_OPERATION_LIST: somecomfort.SYSTEM_MODES,
|
||||||
}
|
}
|
||||||
self.assertEqual(expected, self.honeywell.device_state_attributes)
|
assert expected == self.honeywell.device_state_attributes
|
||||||
|
|
||||||
def test_heat_away_mode(self):
|
def test_heat_away_mode(self):
|
||||||
"""Test setting the heat away mode."""
|
"""Test setting the heat away mode."""
|
||||||
self.honeywell.set_operation_mode('heat')
|
self.honeywell.set_operation_mode('heat')
|
||||||
self.assertFalse(self.honeywell.is_away_mode_on)
|
assert not self.honeywell.is_away_mode_on
|
||||||
self.honeywell.turn_away_mode_on()
|
self.honeywell.turn_away_mode_on()
|
||||||
self.assertTrue(self.honeywell.is_away_mode_on)
|
assert self.honeywell.is_away_mode_on
|
||||||
self.assertEqual(self.device.setpoint_heat, self.heat_away_temp)
|
assert self.device.setpoint_heat == self.heat_away_temp
|
||||||
self.assertEqual(self.device.hold_heat, True)
|
assert self.device.hold_heat is True
|
||||||
|
|
||||||
self.honeywell.turn_away_mode_off()
|
self.honeywell.turn_away_mode_off()
|
||||||
self.assertFalse(self.honeywell.is_away_mode_on)
|
assert not self.honeywell.is_away_mode_on
|
||||||
self.assertEqual(self.device.hold_heat, False)
|
assert self.device.hold_heat is False
|
||||||
|
|
||||||
@mock.patch('somecomfort.SomeComfort')
|
@mock.patch('somecomfort.SomeComfort')
|
||||||
def test_retry(self, test_somecomfort):
|
def test_retry(self, test_somecomfort):
|
||||||
"""Test retry connection."""
|
"""Test retry connection."""
|
||||||
old_device = self.honeywell._device
|
old_device = self.honeywell._device
|
||||||
self.honeywell._retry()
|
self.honeywell._retry()
|
||||||
self.assertEqual(self.honeywell._device, old_device)
|
assert self.honeywell._device == old_device
|
||||||
|
|
|
@ -84,133 +84,129 @@ class TestMelissa(unittest.TestCase):
|
||||||
|
|
||||||
def test_get_name(self):
|
def test_get_name(self):
|
||||||
"""Test name property."""
|
"""Test name property."""
|
||||||
self.assertEqual("Melissa 12345678", self.thermostat.name)
|
assert "Melissa 12345678" == self.thermostat.name
|
||||||
|
|
||||||
def test_is_on(self):
|
def test_is_on(self):
|
||||||
"""Test name property."""
|
"""Test name property."""
|
||||||
self.assertTrue(self.thermostat.is_on)
|
assert self.thermostat.is_on
|
||||||
self.thermostat._cur_settings = None
|
self.thermostat._cur_settings = None
|
||||||
self.assertFalse(self.thermostat.is_on)
|
assert not self.thermostat.is_on
|
||||||
|
|
||||||
def test_current_fan_mode(self):
|
def test_current_fan_mode(self):
|
||||||
"""Test current_fan_mode property."""
|
"""Test current_fan_mode property."""
|
||||||
self.thermostat.update()
|
self.thermostat.update()
|
||||||
self.assertEqual(SPEED_LOW, self.thermostat.current_fan_mode)
|
assert SPEED_LOW == self.thermostat.current_fan_mode
|
||||||
self.thermostat._cur_settings = None
|
self.thermostat._cur_settings = None
|
||||||
self.assertEqual(None, self.thermostat.current_fan_mode)
|
assert self.thermostat.current_fan_mode is None
|
||||||
|
|
||||||
def test_current_temperature(self):
|
def test_current_temperature(self):
|
||||||
"""Test current temperature."""
|
"""Test current temperature."""
|
||||||
self.assertEqual(27.4, self.thermostat.current_temperature)
|
assert 27.4 == self.thermostat.current_temperature
|
||||||
|
|
||||||
def test_current_temperature_no_data(self):
|
def test_current_temperature_no_data(self):
|
||||||
"""Test current temperature without data."""
|
"""Test current temperature without data."""
|
||||||
self.thermostat._data = None
|
self.thermostat._data = None
|
||||||
self.assertIsNone(self.thermostat.current_temperature)
|
assert self.thermostat.current_temperature is None
|
||||||
|
|
||||||
def test_target_temperature_step(self):
|
def test_target_temperature_step(self):
|
||||||
"""Test current target_temperature_step."""
|
"""Test current target_temperature_step."""
|
||||||
self.assertEqual(1, self.thermostat.target_temperature_step)
|
assert 1 == self.thermostat.target_temperature_step
|
||||||
|
|
||||||
def test_current_operation(self):
|
def test_current_operation(self):
|
||||||
"""Test current operation."""
|
"""Test current operation."""
|
||||||
self.thermostat.update()
|
self.thermostat.update()
|
||||||
self.assertEqual(self.thermostat.current_operation, STATE_HEAT)
|
assert self.thermostat.current_operation == STATE_HEAT
|
||||||
self.thermostat._cur_settings = None
|
self.thermostat._cur_settings = None
|
||||||
self.assertEqual(None, self.thermostat.current_operation)
|
assert self.thermostat.current_operation is None
|
||||||
|
|
||||||
def test_operation_list(self):
|
def test_operation_list(self):
|
||||||
"""Test the operation list."""
|
"""Test the operation list."""
|
||||||
self.assertEqual(
|
assert [STATE_COOL, STATE_DRY, STATE_FAN_ONLY, STATE_HEAT] == \
|
||||||
[STATE_COOL, STATE_DRY, STATE_FAN_ONLY, STATE_HEAT],
|
|
||||||
self.thermostat.operation_list
|
self.thermostat.operation_list
|
||||||
)
|
|
||||||
|
|
||||||
def test_fan_list(self):
|
def test_fan_list(self):
|
||||||
"""Test the fan list."""
|
"""Test the fan list."""
|
||||||
self.assertEqual(
|
assert [STATE_AUTO, SPEED_HIGH, SPEED_LOW, SPEED_MEDIUM] == \
|
||||||
[STATE_AUTO, SPEED_HIGH, SPEED_LOW, SPEED_MEDIUM],
|
|
||||||
self.thermostat.fan_list
|
self.thermostat.fan_list
|
||||||
)
|
|
||||||
|
|
||||||
def test_target_temperature(self):
|
def test_target_temperature(self):
|
||||||
"""Test target temperature."""
|
"""Test target temperature."""
|
||||||
self.assertEqual(16, self.thermostat.target_temperature)
|
assert 16 == self.thermostat.target_temperature
|
||||||
self.thermostat._cur_settings = None
|
self.thermostat._cur_settings = None
|
||||||
self.assertEqual(None, self.thermostat.target_temperature)
|
assert self.thermostat.target_temperature is None
|
||||||
|
|
||||||
def test_state(self):
|
def test_state(self):
|
||||||
"""Test state."""
|
"""Test state."""
|
||||||
self.assertEqual(STATE_ON, self.thermostat.state)
|
assert STATE_ON == self.thermostat.state
|
||||||
self.thermostat._cur_settings = None
|
self.thermostat._cur_settings = None
|
||||||
self.assertEqual(None, self.thermostat.state)
|
assert self.thermostat.state is None
|
||||||
|
|
||||||
def test_temperature_unit(self):
|
def test_temperature_unit(self):
|
||||||
"""Test temperature unit."""
|
"""Test temperature unit."""
|
||||||
self.assertEqual(TEMP_CELSIUS, self.thermostat.temperature_unit)
|
assert TEMP_CELSIUS == self.thermostat.temperature_unit
|
||||||
|
|
||||||
def test_min_temp(self):
|
def test_min_temp(self):
|
||||||
"""Test min temp."""
|
"""Test min temp."""
|
||||||
self.assertEqual(16, self.thermostat.min_temp)
|
assert 16 == self.thermostat.min_temp
|
||||||
|
|
||||||
def test_max_temp(self):
|
def test_max_temp(self):
|
||||||
"""Test max temp."""
|
"""Test max temp."""
|
||||||
self.assertEqual(30, self.thermostat.max_temp)
|
assert 30 == self.thermostat.max_temp
|
||||||
|
|
||||||
def test_supported_features(self):
|
def test_supported_features(self):
|
||||||
"""Test supported_features property."""
|
"""Test supported_features property."""
|
||||||
features = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE |
|
features = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE |
|
||||||
SUPPORT_ON_OFF | SUPPORT_FAN_MODE)
|
SUPPORT_ON_OFF | SUPPORT_FAN_MODE)
|
||||||
self.assertEqual(features, self.thermostat.supported_features)
|
assert features == self.thermostat.supported_features
|
||||||
|
|
||||||
def test_set_temperature(self):
|
def test_set_temperature(self):
|
||||||
"""Test set_temperature."""
|
"""Test set_temperature."""
|
||||||
self.api.send.return_value = True
|
self.api.send.return_value = True
|
||||||
self.thermostat.update()
|
self.thermostat.update()
|
||||||
self.thermostat.set_temperature(**{ATTR_TEMPERATURE: 25})
|
self.thermostat.set_temperature(**{ATTR_TEMPERATURE: 25})
|
||||||
self.assertEqual(25, self.thermostat.target_temperature)
|
assert 25 == self.thermostat.target_temperature
|
||||||
|
|
||||||
def test_fan_mode(self):
|
def test_fan_mode(self):
|
||||||
"""Test set_fan_mode."""
|
"""Test set_fan_mode."""
|
||||||
self.api.send.return_value = True
|
self.api.send.return_value = True
|
||||||
self.thermostat.set_fan_mode(SPEED_HIGH)
|
self.thermostat.set_fan_mode(SPEED_HIGH)
|
||||||
self.assertEqual(SPEED_HIGH, self.thermostat.current_fan_mode)
|
assert SPEED_HIGH == self.thermostat.current_fan_mode
|
||||||
|
|
||||||
def test_set_operation_mode(self):
|
def test_set_operation_mode(self):
|
||||||
"""Test set_operation_mode."""
|
"""Test set_operation_mode."""
|
||||||
self.api.send.return_value = True
|
self.api.send.return_value = True
|
||||||
self.thermostat.set_operation_mode(STATE_COOL)
|
self.thermostat.set_operation_mode(STATE_COOL)
|
||||||
self.assertEqual(STATE_COOL, self.thermostat.current_operation)
|
assert STATE_COOL == self.thermostat.current_operation
|
||||||
|
|
||||||
def test_turn_on(self):
|
def test_turn_on(self):
|
||||||
"""Test turn_on."""
|
"""Test turn_on."""
|
||||||
self.thermostat.turn_on()
|
self.thermostat.turn_on()
|
||||||
self.assertTrue(self.thermostat.state)
|
assert self.thermostat.state
|
||||||
|
|
||||||
def test_turn_off(self):
|
def test_turn_off(self):
|
||||||
"""Test turn_off."""
|
"""Test turn_off."""
|
||||||
self.thermostat.turn_off()
|
self.thermostat.turn_off()
|
||||||
self.assertEqual(STATE_OFF, self.thermostat.state)
|
assert STATE_OFF == self.thermostat.state
|
||||||
|
|
||||||
def test_send(self):
|
def test_send(self):
|
||||||
"""Test send."""
|
"""Test send."""
|
||||||
self.thermostat.update()
|
self.thermostat.update()
|
||||||
self.assertTrue(self.thermostat.send(
|
assert self.thermostat.send(
|
||||||
{'fan': self.api.FAN_MEDIUM}))
|
{'fan': self.api.FAN_MEDIUM})
|
||||||
self.assertEqual(SPEED_MEDIUM, self.thermostat.current_fan_mode)
|
assert SPEED_MEDIUM == self.thermostat.current_fan_mode
|
||||||
self.api.send.return_value = False
|
self.api.send.return_value = False
|
||||||
self.thermostat._cur_settings = None
|
self.thermostat._cur_settings = None
|
||||||
self.assertFalse(self.thermostat.send({
|
assert not self.thermostat.send({
|
||||||
'fan': self.api.FAN_LOW}))
|
'fan': self.api.FAN_LOW})
|
||||||
self.assertNotEqual(SPEED_LOW, self.thermostat.current_fan_mode)
|
assert SPEED_LOW != self.thermostat.current_fan_mode
|
||||||
self.assertIsNone(self.thermostat._cur_settings)
|
assert self.thermostat._cur_settings is None
|
||||||
|
|
||||||
@mock.patch('homeassistant.components.climate.melissa._LOGGER.warning')
|
@mock.patch('homeassistant.components.climate.melissa._LOGGER.warning')
|
||||||
def test_update(self, mocked_warning):
|
def test_update(self, mocked_warning):
|
||||||
"""Test update."""
|
"""Test update."""
|
||||||
self.thermostat.update()
|
self.thermostat.update()
|
||||||
self.assertEqual(SPEED_LOW, self.thermostat.current_fan_mode)
|
assert SPEED_LOW == self.thermostat.current_fan_mode
|
||||||
self.assertEqual(STATE_HEAT, self.thermostat.current_operation)
|
assert STATE_HEAT == self.thermostat.current_operation
|
||||||
self.thermostat._api.status.side_effect = KeyError('boom')
|
self.thermostat._api.status.side_effect = KeyError('boom')
|
||||||
self.thermostat.update()
|
self.thermostat.update()
|
||||||
mocked_warning.assert_called_once_with(
|
mocked_warning.assert_called_once_with(
|
||||||
|
@ -218,37 +214,34 @@ class TestMelissa(unittest.TestCase):
|
||||||
|
|
||||||
def test_melissa_state_to_hass(self):
|
def test_melissa_state_to_hass(self):
|
||||||
"""Test for translate melissa states to hass."""
|
"""Test for translate melissa states to hass."""
|
||||||
self.assertEqual(STATE_OFF, self.thermostat.melissa_state_to_hass(0))
|
assert STATE_OFF == self.thermostat.melissa_state_to_hass(0)
|
||||||
self.assertEqual(STATE_ON, self.thermostat.melissa_state_to_hass(1))
|
assert STATE_ON == self.thermostat.melissa_state_to_hass(1)
|
||||||
self.assertEqual(STATE_IDLE, self.thermostat.melissa_state_to_hass(2))
|
assert STATE_IDLE == self.thermostat.melissa_state_to_hass(2)
|
||||||
self.assertEqual(None,
|
assert self.thermostat.melissa_state_to_hass(3) is None
|
||||||
self.thermostat.melissa_state_to_hass(3))
|
|
||||||
|
|
||||||
def test_melissa_op_to_hass(self):
|
def test_melissa_op_to_hass(self):
|
||||||
"""Test for translate melissa operations to hass."""
|
"""Test for translate melissa operations to hass."""
|
||||||
self.assertEqual(STATE_FAN_ONLY, self.thermostat.melissa_op_to_hass(1))
|
assert STATE_FAN_ONLY == self.thermostat.melissa_op_to_hass(1)
|
||||||
self.assertEqual(STATE_HEAT, self.thermostat.melissa_op_to_hass(2))
|
assert STATE_HEAT == self.thermostat.melissa_op_to_hass(2)
|
||||||
self.assertEqual(STATE_COOL, self.thermostat.melissa_op_to_hass(3))
|
assert STATE_COOL == self.thermostat.melissa_op_to_hass(3)
|
||||||
self.assertEqual(STATE_DRY, self.thermostat.melissa_op_to_hass(4))
|
assert STATE_DRY == self.thermostat.melissa_op_to_hass(4)
|
||||||
self.assertEqual(
|
assert self.thermostat.melissa_op_to_hass(5) is None
|
||||||
None, self.thermostat.melissa_op_to_hass(5))
|
|
||||||
|
|
||||||
def test_melissa_fan_to_hass(self):
|
def test_melissa_fan_to_hass(self):
|
||||||
"""Test for translate melissa fan state to hass."""
|
"""Test for translate melissa fan state to hass."""
|
||||||
self.assertEqual(STATE_AUTO, self.thermostat.melissa_fan_to_hass(0))
|
assert STATE_AUTO == self.thermostat.melissa_fan_to_hass(0)
|
||||||
self.assertEqual(SPEED_LOW, self.thermostat.melissa_fan_to_hass(1))
|
assert SPEED_LOW == self.thermostat.melissa_fan_to_hass(1)
|
||||||
self.assertEqual(SPEED_MEDIUM, self.thermostat.melissa_fan_to_hass(2))
|
assert SPEED_MEDIUM == self.thermostat.melissa_fan_to_hass(2)
|
||||||
self.assertEqual(SPEED_HIGH, self.thermostat.melissa_fan_to_hass(3))
|
assert SPEED_HIGH == self.thermostat.melissa_fan_to_hass(3)
|
||||||
self.assertEqual(None, self.thermostat.melissa_fan_to_hass(4))
|
assert self.thermostat.melissa_fan_to_hass(4) is None
|
||||||
|
|
||||||
@mock.patch('homeassistant.components.climate.melissa._LOGGER.warning')
|
@mock.patch('homeassistant.components.climate.melissa._LOGGER.warning')
|
||||||
def test_hass_mode_to_melissa(self, mocked_warning):
|
def test_hass_mode_to_melissa(self, mocked_warning):
|
||||||
"""Test for hass operations to melssa."""
|
"""Test for hass operations to melssa."""
|
||||||
self.assertEqual(
|
assert 1 == self.thermostat.hass_mode_to_melissa(STATE_FAN_ONLY)
|
||||||
1, self.thermostat.hass_mode_to_melissa(STATE_FAN_ONLY))
|
assert 2 == self.thermostat.hass_mode_to_melissa(STATE_HEAT)
|
||||||
self.assertEqual(2, self.thermostat.hass_mode_to_melissa(STATE_HEAT))
|
assert 3 == self.thermostat.hass_mode_to_melissa(STATE_COOL)
|
||||||
self.assertEqual(3, self.thermostat.hass_mode_to_melissa(STATE_COOL))
|
assert 4 == self.thermostat.hass_mode_to_melissa(STATE_DRY)
|
||||||
self.assertEqual(4, self.thermostat.hass_mode_to_melissa(STATE_DRY))
|
|
||||||
self.thermostat.hass_mode_to_melissa("test")
|
self.thermostat.hass_mode_to_melissa("test")
|
||||||
mocked_warning.assert_called_once_with(
|
mocked_warning.assert_called_once_with(
|
||||||
"Melissa have no setting for %s mode", "test")
|
"Melissa have no setting for %s mode", "test")
|
||||||
|
@ -256,10 +249,10 @@ class TestMelissa(unittest.TestCase):
|
||||||
@mock.patch('homeassistant.components.climate.melissa._LOGGER.warning')
|
@mock.patch('homeassistant.components.climate.melissa._LOGGER.warning')
|
||||||
def test_hass_fan_to_melissa(self, mocked_warning):
|
def test_hass_fan_to_melissa(self, mocked_warning):
|
||||||
"""Test for translate melissa states to hass."""
|
"""Test for translate melissa states to hass."""
|
||||||
self.assertEqual(0, self.thermostat.hass_fan_to_melissa(STATE_AUTO))
|
assert 0 == self.thermostat.hass_fan_to_melissa(STATE_AUTO)
|
||||||
self.assertEqual(1, self.thermostat.hass_fan_to_melissa(SPEED_LOW))
|
assert 1 == self.thermostat.hass_fan_to_melissa(SPEED_LOW)
|
||||||
self.assertEqual(2, self.thermostat.hass_fan_to_melissa(SPEED_MEDIUM))
|
assert 2 == self.thermostat.hass_fan_to_melissa(SPEED_MEDIUM)
|
||||||
self.assertEqual(3, self.thermostat.hass_fan_to_melissa(SPEED_HIGH))
|
assert 3 == self.thermostat.hass_fan_to_melissa(SPEED_HIGH)
|
||||||
self.thermostat.hass_fan_to_melissa("test")
|
self.thermostat.hass_fan_to_melissa("test")
|
||||||
mocked_warning.assert_called_once_with(
|
mocked_warning.assert_called_once_with(
|
||||||
"Melissa have no setting for %s fan mode", "test")
|
"Melissa have no setting for %s fan mode", "test")
|
||||||
|
|
|
@ -52,12 +52,12 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(21, state.attributes.get('temperature'))
|
assert 21 == state.attributes.get('temperature')
|
||||||
self.assertEqual("low", state.attributes.get('fan_mode'))
|
assert "low" == state.attributes.get('fan_mode')
|
||||||
self.assertEqual("off", state.attributes.get('swing_mode'))
|
assert "off" == state.attributes.get('swing_mode')
|
||||||
self.assertEqual("off", state.attributes.get('operation_mode'))
|
assert "off" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual(DEFAULT_MIN_TEMP, state.attributes.get('min_temp'))
|
assert DEFAULT_MIN_TEMP == state.attributes.get('min_temp')
|
||||||
self.assertEqual(DEFAULT_MAX_TEMP, state.attributes.get('max_temp'))
|
assert DEFAULT_MAX_TEMP == state.attributes.get('max_temp')
|
||||||
|
|
||||||
def test_supported_features(self):
|
def test_supported_features(self):
|
||||||
"""Test the supported_features."""
|
"""Test the supported_features."""
|
||||||
|
@ -68,7 +68,7 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
SUPPORT_SWING_MODE | SUPPORT_FAN_MODE | SUPPORT_AWAY_MODE |
|
SUPPORT_SWING_MODE | SUPPORT_FAN_MODE | SUPPORT_AWAY_MODE |
|
||||||
SUPPORT_HOLD_MODE | SUPPORT_AUX_HEAT)
|
SUPPORT_HOLD_MODE | SUPPORT_AUX_HEAT)
|
||||||
|
|
||||||
self.assertEqual(state.attributes.get("supported_features"), support)
|
assert state.attributes.get("supported_features") == support
|
||||||
|
|
||||||
def test_get_operation_modes(self):
|
def test_get_operation_modes(self):
|
||||||
"""Test that the operation list returns the correct modes."""
|
"""Test that the operation list returns the correct modes."""
|
||||||
|
@ -76,10 +76,10 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
modes = state.attributes.get('operation_list')
|
modes = state.attributes.get('operation_list')
|
||||||
self.assertEqual([
|
assert [
|
||||||
climate.STATE_AUTO, STATE_OFF, climate.STATE_COOL,
|
climate.STATE_AUTO, STATE_OFF, climate.STATE_COOL,
|
||||||
climate.STATE_HEAT, climate.STATE_DRY, climate.STATE_FAN_ONLY
|
climate.STATE_HEAT, climate.STATE_DRY, climate.STATE_FAN_ONLY
|
||||||
], modes)
|
] == modes
|
||||||
|
|
||||||
def test_set_operation_bad_attr_and_state(self):
|
def test_set_operation_bad_attr_and_state(self):
|
||||||
"""Test setting operation mode without required attribute.
|
"""Test setting operation mode without required attribute.
|
||||||
|
@ -89,26 +89,26 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("off", state.attributes.get('operation_mode'))
|
assert "off" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual("off", state.state)
|
assert "off" == state.state
|
||||||
common.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
|
common.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("off", state.attributes.get('operation_mode'))
|
assert "off" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual("off", state.state)
|
assert "off" == state.state
|
||||||
|
|
||||||
def test_set_operation(self):
|
def test_set_operation(self):
|
||||||
"""Test setting of new operation mode."""
|
"""Test setting of new operation mode."""
|
||||||
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("off", state.attributes.get('operation_mode'))
|
assert "off" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual("off", state.state)
|
assert "off" == state.state
|
||||||
common.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
|
common.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("cool", state.attributes.get('operation_mode'))
|
assert "cool" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual("cool", state.state)
|
assert "cool" == state.state
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'mode-topic', 'cool', 0, False)
|
'mode-topic', 'cool', 0, False)
|
||||||
|
|
||||||
|
@ -119,26 +119,26 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
assert setup_component(self.hass, climate.DOMAIN, config)
|
assert setup_component(self.hass, climate.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(None, state.attributes.get('operation_mode'))
|
assert state.attributes.get('operation_mode') is None
|
||||||
self.assertEqual("unknown", state.state)
|
assert "unknown" == state.state
|
||||||
|
|
||||||
common.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
|
common.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(None, state.attributes.get('operation_mode'))
|
assert state.attributes.get('operation_mode') is None
|
||||||
self.assertEqual("unknown", state.state)
|
assert "unknown" == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'mode-state', 'cool')
|
fire_mqtt_message(self.hass, 'mode-state', 'cool')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("cool", state.attributes.get('operation_mode'))
|
assert "cool" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual("cool", state.state)
|
assert "cool" == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'mode-state', 'bogus mode')
|
fire_mqtt_message(self.hass, 'mode-state', 'bogus mode')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("cool", state.attributes.get('operation_mode'))
|
assert "cool" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual("cool", state.state)
|
assert "cool" == state.state
|
||||||
|
|
||||||
def test_set_operation_with_power_command(self):
|
def test_set_operation_with_power_command(self):
|
||||||
"""Test setting of new operation mode with power command enabled."""
|
"""Test setting of new operation mode with power command enabled."""
|
||||||
|
@ -147,13 +147,13 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
assert setup_component(self.hass, climate.DOMAIN, config)
|
assert setup_component(self.hass, climate.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("off", state.attributes.get('operation_mode'))
|
assert "off" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual("off", state.state)
|
assert "off" == state.state
|
||||||
common.set_operation_mode(self.hass, "on", ENTITY_CLIMATE)
|
common.set_operation_mode(self.hass, "on", ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("on", state.attributes.get('operation_mode'))
|
assert "on" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual("on", state.state)
|
assert "on" == state.state
|
||||||
self.mock_publish.async_publish.assert_has_calls([
|
self.mock_publish.async_publish.assert_has_calls([
|
||||||
unittest.mock.call('power-command', 'ON', 0, False),
|
unittest.mock.call('power-command', 'ON', 0, False),
|
||||||
unittest.mock.call('mode-topic', 'on', 0, False)
|
unittest.mock.call('mode-topic', 'on', 0, False)
|
||||||
|
@ -163,8 +163,8 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
common.set_operation_mode(self.hass, "off", ENTITY_CLIMATE)
|
common.set_operation_mode(self.hass, "off", ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("off", state.attributes.get('operation_mode'))
|
assert "off" == state.attributes.get('operation_mode')
|
||||||
self.assertEqual("off", state.state)
|
assert "off" == state.state
|
||||||
self.mock_publish.async_publish.assert_has_calls([
|
self.mock_publish.async_publish.assert_has_calls([
|
||||||
unittest.mock.call('power-command', 'OFF', 0, False),
|
unittest.mock.call('power-command', 'OFF', 0, False),
|
||||||
unittest.mock.call('mode-topic', 'off', 0, False)
|
unittest.mock.call('mode-topic', 'off', 0, False)
|
||||||
|
@ -176,11 +176,11 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("low", state.attributes.get('fan_mode'))
|
assert "low" == state.attributes.get('fan_mode')
|
||||||
common.set_fan_mode(self.hass, None, ENTITY_CLIMATE)
|
common.set_fan_mode(self.hass, None, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("low", state.attributes.get('fan_mode'))
|
assert "low" == state.attributes.get('fan_mode')
|
||||||
|
|
||||||
def test_set_fan_mode_pessimistic(self):
|
def test_set_fan_mode_pessimistic(self):
|
||||||
"""Test setting of new fan mode in pessimistic mode."""
|
"""Test setting of new fan mode in pessimistic mode."""
|
||||||
|
@ -189,46 +189,46 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
assert setup_component(self.hass, climate.DOMAIN, config)
|
assert setup_component(self.hass, climate.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(None, state.attributes.get('fan_mode'))
|
assert state.attributes.get('fan_mode') is None
|
||||||
|
|
||||||
common.set_fan_mode(self.hass, 'high', ENTITY_CLIMATE)
|
common.set_fan_mode(self.hass, 'high', ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(None, state.attributes.get('fan_mode'))
|
assert state.attributes.get('fan_mode') is None
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'fan-state', 'high')
|
fire_mqtt_message(self.hass, 'fan-state', 'high')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('high', state.attributes.get('fan_mode'))
|
assert 'high' == state.attributes.get('fan_mode')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'fan-state', 'bogus mode')
|
fire_mqtt_message(self.hass, 'fan-state', 'bogus mode')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('high', state.attributes.get('fan_mode'))
|
assert 'high' == state.attributes.get('fan_mode')
|
||||||
|
|
||||||
def test_set_fan_mode(self):
|
def test_set_fan_mode(self):
|
||||||
"""Test setting of new fan mode."""
|
"""Test setting of new fan mode."""
|
||||||
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("low", state.attributes.get('fan_mode'))
|
assert "low" == state.attributes.get('fan_mode')
|
||||||
common.set_fan_mode(self.hass, 'high', ENTITY_CLIMATE)
|
common.set_fan_mode(self.hass, 'high', ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'fan-mode-topic', 'high', 0, False)
|
'fan-mode-topic', 'high', 0, False)
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('high', state.attributes.get('fan_mode'))
|
assert 'high' == state.attributes.get('fan_mode')
|
||||||
|
|
||||||
def test_set_swing_mode_bad_attr(self):
|
def test_set_swing_mode_bad_attr(self):
|
||||||
"""Test setting swing mode without required attribute."""
|
"""Test setting swing mode without required attribute."""
|
||||||
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("off", state.attributes.get('swing_mode'))
|
assert "off" == state.attributes.get('swing_mode')
|
||||||
common.set_swing_mode(self.hass, None, ENTITY_CLIMATE)
|
common.set_swing_mode(self.hass, None, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("off", state.attributes.get('swing_mode'))
|
assert "off" == state.attributes.get('swing_mode')
|
||||||
|
|
||||||
def test_set_swing_pessimistic(self):
|
def test_set_swing_pessimistic(self):
|
||||||
"""Test setting swing mode in pessimistic mode."""
|
"""Test setting swing mode in pessimistic mode."""
|
||||||
|
@ -237,46 +237,46 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
assert setup_component(self.hass, climate.DOMAIN, config)
|
assert setup_component(self.hass, climate.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(None, state.attributes.get('swing_mode'))
|
assert state.attributes.get('swing_mode') is None
|
||||||
|
|
||||||
common.set_swing_mode(self.hass, 'on', ENTITY_CLIMATE)
|
common.set_swing_mode(self.hass, 'on', ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(None, state.attributes.get('swing_mode'))
|
assert state.attributes.get('swing_mode') is None
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'swing-state', 'on')
|
fire_mqtt_message(self.hass, 'swing-state', 'on')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("on", state.attributes.get('swing_mode'))
|
assert "on" == state.attributes.get('swing_mode')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'swing-state', 'bogus state')
|
fire_mqtt_message(self.hass, 'swing-state', 'bogus state')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("on", state.attributes.get('swing_mode'))
|
assert "on" == state.attributes.get('swing_mode')
|
||||||
|
|
||||||
def test_set_swing(self):
|
def test_set_swing(self):
|
||||||
"""Test setting of new swing mode."""
|
"""Test setting of new swing mode."""
|
||||||
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("off", state.attributes.get('swing_mode'))
|
assert "off" == state.attributes.get('swing_mode')
|
||||||
common.set_swing_mode(self.hass, 'on', ENTITY_CLIMATE)
|
common.set_swing_mode(self.hass, 'on', ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'swing-mode-topic', 'on', 0, False)
|
'swing-mode-topic', 'on', 0, False)
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("on", state.attributes.get('swing_mode'))
|
assert "on" == state.attributes.get('swing_mode')
|
||||||
|
|
||||||
def test_set_target_temperature(self):
|
def test_set_target_temperature(self):
|
||||||
"""Test setting the target temperature."""
|
"""Test setting the target temperature."""
|
||||||
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(21, state.attributes.get('temperature'))
|
assert 21 == state.attributes.get('temperature')
|
||||||
common.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
|
common.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('heat', state.attributes.get('operation_mode'))
|
assert 'heat' == state.attributes.get('operation_mode')
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'mode-topic', 'heat', 0, False)
|
'mode-topic', 'heat', 0, False)
|
||||||
self.mock_publish.async_publish.reset_mock()
|
self.mock_publish.async_publish.reset_mock()
|
||||||
|
@ -284,7 +284,7 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
entity_id=ENTITY_CLIMATE)
|
entity_id=ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(47, state.attributes.get('temperature'))
|
assert 47 == state.attributes.get('temperature')
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'temperature-topic', 47, 0, False)
|
'temperature-topic', 47, 0, False)
|
||||||
|
|
||||||
|
@ -295,8 +295,8 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
entity_id=ENTITY_CLIMATE)
|
entity_id=ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('cool', state.attributes.get('operation_mode'))
|
assert 'cool' == state.attributes.get('operation_mode')
|
||||||
self.assertEqual(21, state.attributes.get('temperature'))
|
assert 21 == state.attributes.get('temperature')
|
||||||
self.mock_publish.async_publish.assert_has_calls([
|
self.mock_publish.async_publish.assert_has_calls([
|
||||||
unittest.mock.call('mode-topic', 'cool', 0, False),
|
unittest.mock.call('mode-topic', 'cool', 0, False),
|
||||||
unittest.mock.call('temperature-topic', 21, 0, False)
|
unittest.mock.call('temperature-topic', 21, 0, False)
|
||||||
|
@ -310,24 +310,24 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
assert setup_component(self.hass, climate.DOMAIN, config)
|
assert setup_component(self.hass, climate.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(None, state.attributes.get('temperature'))
|
assert state.attributes.get('temperature') is None
|
||||||
common.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
|
common.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
common.set_temperature(self.hass, temperature=47,
|
common.set_temperature(self.hass, temperature=47,
|
||||||
entity_id=ENTITY_CLIMATE)
|
entity_id=ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(None, state.attributes.get('temperature'))
|
assert state.attributes.get('temperature') is None
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'temperature-state', '1701')
|
fire_mqtt_message(self.hass, 'temperature-state', '1701')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(1701, state.attributes.get('temperature'))
|
assert 1701 == state.attributes.get('temperature')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'temperature-state', 'not a number')
|
fire_mqtt_message(self.hass, 'temperature-state', 'not a number')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(1701, state.attributes.get('temperature'))
|
assert 1701 == state.attributes.get('temperature')
|
||||||
|
|
||||||
def test_receive_mqtt_temperature(self):
|
def test_receive_mqtt_temperature(self):
|
||||||
"""Test getting the current temperature via MQTT."""
|
"""Test getting the current temperature via MQTT."""
|
||||||
|
@ -339,7 +339,7 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'current_temperature', '47')
|
fire_mqtt_message(self.hass, 'current_temperature', '47')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(47, state.attributes.get('current_temperature'))
|
assert 47 == state.attributes.get('current_temperature')
|
||||||
|
|
||||||
def test_set_away_mode_pessimistic(self):
|
def test_set_away_mode_pessimistic(self):
|
||||||
"""Test setting of the away mode."""
|
"""Test setting of the away mode."""
|
||||||
|
@ -348,27 +348,27 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
assert setup_component(self.hass, climate.DOMAIN, config)
|
assert setup_component(self.hass, climate.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
assert 'off' == state.attributes.get('away_mode')
|
||||||
|
|
||||||
common.set_away_mode(self.hass, True, ENTITY_CLIMATE)
|
common.set_away_mode(self.hass, True, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
assert 'off' == state.attributes.get('away_mode')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'away-state', 'ON')
|
fire_mqtt_message(self.hass, 'away-state', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('on', state.attributes.get('away_mode'))
|
assert 'on' == state.attributes.get('away_mode')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'away-state', 'OFF')
|
fire_mqtt_message(self.hass, 'away-state', 'OFF')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
assert 'off' == state.attributes.get('away_mode')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'away-state', 'nonsense')
|
fire_mqtt_message(self.hass, 'away-state', 'nonsense')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
assert 'off' == state.attributes.get('away_mode')
|
||||||
|
|
||||||
def test_set_away_mode(self):
|
def test_set_away_mode(self):
|
||||||
"""Test setting of the away mode."""
|
"""Test setting of the away mode."""
|
||||||
|
@ -379,21 +379,21 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
assert setup_component(self.hass, climate.DOMAIN, config)
|
assert setup_component(self.hass, climate.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
assert 'off' == state.attributes.get('away_mode')
|
||||||
common.set_away_mode(self.hass, True, ENTITY_CLIMATE)
|
common.set_away_mode(self.hass, True, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'away-mode-topic', 'AN', 0, False)
|
'away-mode-topic', 'AN', 0, False)
|
||||||
self.mock_publish.async_publish.reset_mock()
|
self.mock_publish.async_publish.reset_mock()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('on', state.attributes.get('away_mode'))
|
assert 'on' == state.attributes.get('away_mode')
|
||||||
|
|
||||||
common.set_away_mode(self.hass, False, ENTITY_CLIMATE)
|
common.set_away_mode(self.hass, False, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'away-mode-topic', 'AUS', 0, False)
|
'away-mode-topic', 'AUS', 0, False)
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
assert 'off' == state.attributes.get('away_mode')
|
||||||
|
|
||||||
def test_set_hold_pessimistic(self):
|
def test_set_hold_pessimistic(self):
|
||||||
"""Test setting the hold mode in pessimistic mode."""
|
"""Test setting the hold mode in pessimistic mode."""
|
||||||
|
@ -402,43 +402,43 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
assert setup_component(self.hass, climate.DOMAIN, config)
|
assert setup_component(self.hass, climate.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(None, state.attributes.get('hold_mode'))
|
assert state.attributes.get('hold_mode') is None
|
||||||
|
|
||||||
common.set_hold_mode(self.hass, 'on', ENTITY_CLIMATE)
|
common.set_hold_mode(self.hass, 'on', ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(None, state.attributes.get('hold_mode'))
|
assert state.attributes.get('hold_mode') is None
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'hold-state', 'on')
|
fire_mqtt_message(self.hass, 'hold-state', 'on')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('on', state.attributes.get('hold_mode'))
|
assert 'on' == state.attributes.get('hold_mode')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'hold-state', 'off')
|
fire_mqtt_message(self.hass, 'hold-state', 'off')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('hold_mode'))
|
assert 'off' == state.attributes.get('hold_mode')
|
||||||
|
|
||||||
def test_set_hold(self):
|
def test_set_hold(self):
|
||||||
"""Test setting the hold mode."""
|
"""Test setting the hold mode."""
|
||||||
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(None, state.attributes.get('hold_mode'))
|
assert state.attributes.get('hold_mode') is None
|
||||||
common.set_hold_mode(self.hass, 'on', ENTITY_CLIMATE)
|
common.set_hold_mode(self.hass, 'on', ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'hold-topic', 'on', 0, False)
|
'hold-topic', 'on', 0, False)
|
||||||
self.mock_publish.async_publish.reset_mock()
|
self.mock_publish.async_publish.reset_mock()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('on', state.attributes.get('hold_mode'))
|
assert 'on' == state.attributes.get('hold_mode')
|
||||||
|
|
||||||
common.set_hold_mode(self.hass, 'off', ENTITY_CLIMATE)
|
common.set_hold_mode(self.hass, 'off', ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'hold-topic', 'off', 0, False)
|
'hold-topic', 'off', 0, False)
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('hold_mode'))
|
assert 'off' == state.attributes.get('hold_mode')
|
||||||
|
|
||||||
def test_set_aux_pessimistic(self):
|
def test_set_aux_pessimistic(self):
|
||||||
"""Test setting of the aux heating in pessimistic mode."""
|
"""Test setting of the aux heating in pessimistic mode."""
|
||||||
|
@ -447,48 +447,48 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
assert setup_component(self.hass, climate.DOMAIN, config)
|
assert setup_component(self.hass, climate.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
assert 'off' == state.attributes.get('aux_heat')
|
||||||
|
|
||||||
common.set_aux_heat(self.hass, True, ENTITY_CLIMATE)
|
common.set_aux_heat(self.hass, True, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
assert 'off' == state.attributes.get('aux_heat')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'aux-state', 'ON')
|
fire_mqtt_message(self.hass, 'aux-state', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('on', state.attributes.get('aux_heat'))
|
assert 'on' == state.attributes.get('aux_heat')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'aux-state', 'OFF')
|
fire_mqtt_message(self.hass, 'aux-state', 'OFF')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
assert 'off' == state.attributes.get('aux_heat')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'aux-state', 'nonsense')
|
fire_mqtt_message(self.hass, 'aux-state', 'nonsense')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
assert 'off' == state.attributes.get('aux_heat')
|
||||||
|
|
||||||
def test_set_aux(self):
|
def test_set_aux(self):
|
||||||
"""Test setting of the aux heating."""
|
"""Test setting of the aux heating."""
|
||||||
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG)
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
assert 'off' == state.attributes.get('aux_heat')
|
||||||
common.set_aux_heat(self.hass, True, ENTITY_CLIMATE)
|
common.set_aux_heat(self.hass, True, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'aux-topic', 'ON', 0, False)
|
'aux-topic', 'ON', 0, False)
|
||||||
self.mock_publish.async_publish.reset_mock()
|
self.mock_publish.async_publish.reset_mock()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('on', state.attributes.get('aux_heat'))
|
assert 'on' == state.attributes.get('aux_heat')
|
||||||
|
|
||||||
common.set_aux_heat(self.hass, False, ENTITY_CLIMATE)
|
common.set_aux_heat(self.hass, False, ENTITY_CLIMATE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'aux-topic', 'OFF', 0, False)
|
'aux-topic', 'OFF', 0, False)
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
assert 'off' == state.attributes.get('aux_heat')
|
||||||
|
|
||||||
def test_custom_availability_payload(self):
|
def test_custom_availability_payload(self):
|
||||||
"""Test availability by custom payload with defined topic."""
|
"""Test availability by custom payload with defined topic."""
|
||||||
|
@ -500,19 +500,19 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
assert setup_component(self.hass, climate.DOMAIN, config)
|
assert setup_component(self.hass, climate.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('climate.test')
|
state = self.hass.states.get('climate.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('climate.test')
|
state = self.hass.states.get('climate.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('climate.test')
|
state = self.hass.states.get('climate.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
def test_set_with_templates(self):
|
def test_set_with_templates(self):
|
||||||
"""Test setting of new fan mode in pessimistic mode."""
|
"""Test setting of new fan mode in pessimistic mode."""
|
||||||
|
@ -539,32 +539,32 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
|
|
||||||
# Operation Mode
|
# Operation Mode
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(None, state.attributes.get('operation_mode'))
|
assert state.attributes.get('operation_mode') is None
|
||||||
fire_mqtt_message(self.hass, 'mode-state', '"cool"')
|
fire_mqtt_message(self.hass, 'mode-state', '"cool"')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("cool", state.attributes.get('operation_mode'))
|
assert "cool" == state.attributes.get('operation_mode')
|
||||||
|
|
||||||
# Fan Mode
|
# Fan Mode
|
||||||
self.assertEqual(None, state.attributes.get('fan_mode'))
|
assert state.attributes.get('fan_mode') is None
|
||||||
fire_mqtt_message(self.hass, 'fan-state', '"high"')
|
fire_mqtt_message(self.hass, 'fan-state', '"high"')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('high', state.attributes.get('fan_mode'))
|
assert 'high' == state.attributes.get('fan_mode')
|
||||||
|
|
||||||
# Swing Mode
|
# Swing Mode
|
||||||
self.assertEqual(None, state.attributes.get('swing_mode'))
|
assert state.attributes.get('swing_mode') is None
|
||||||
fire_mqtt_message(self.hass, 'swing-state', '"on"')
|
fire_mqtt_message(self.hass, 'swing-state', '"on"')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual("on", state.attributes.get('swing_mode'))
|
assert "on" == state.attributes.get('swing_mode')
|
||||||
|
|
||||||
# Temperature - with valid value
|
# Temperature - with valid value
|
||||||
self.assertEqual(None, state.attributes.get('temperature'))
|
assert state.attributes.get('temperature') is None
|
||||||
fire_mqtt_message(self.hass, 'temperature-state', '"1031"')
|
fire_mqtt_message(self.hass, 'temperature-state', '"1031"')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(1031, state.attributes.get('temperature'))
|
assert 1031 == state.attributes.get('temperature')
|
||||||
|
|
||||||
# Temperature - with invalid value
|
# Temperature - with invalid value
|
||||||
with self.assertLogs(level='ERROR') as log:
|
with self.assertLogs(level='ERROR') as log:
|
||||||
|
@ -572,60 +572,58 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
# make sure, the invalid value gets logged...
|
# make sure, the invalid value gets logged...
|
||||||
self.assertEqual(len(log.output), 1)
|
assert len(log.output) == 1
|
||||||
self.assertEqual(len(log.records), 1)
|
assert len(log.records) == 1
|
||||||
self.assertIn(
|
assert "Could not parse temperature from -INVALID-" in \
|
||||||
"Could not parse temperature from -INVALID-",
|
|
||||||
log.output[0]
|
log.output[0]
|
||||||
)
|
|
||||||
# ... but the actual value stays unchanged.
|
# ... but the actual value stays unchanged.
|
||||||
self.assertEqual(1031, state.attributes.get('temperature'))
|
assert 1031 == state.attributes.get('temperature')
|
||||||
|
|
||||||
# Away Mode
|
# Away Mode
|
||||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
assert 'off' == state.attributes.get('away_mode')
|
||||||
fire_mqtt_message(self.hass, 'away-state', '"ON"')
|
fire_mqtt_message(self.hass, 'away-state', '"ON"')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('on', state.attributes.get('away_mode'))
|
assert 'on' == state.attributes.get('away_mode')
|
||||||
|
|
||||||
# Away Mode with JSON values
|
# Away Mode with JSON values
|
||||||
fire_mqtt_message(self.hass, 'away-state', 'false')
|
fire_mqtt_message(self.hass, 'away-state', 'false')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
assert 'off' == state.attributes.get('away_mode')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'away-state', 'true')
|
fire_mqtt_message(self.hass, 'away-state', 'true')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('on', state.attributes.get('away_mode'))
|
assert 'on' == state.attributes.get('away_mode')
|
||||||
|
|
||||||
# Hold Mode
|
# Hold Mode
|
||||||
self.assertEqual(None, state.attributes.get('hold_mode'))
|
assert state.attributes.get('hold_mode') is None
|
||||||
fire_mqtt_message(self.hass, 'hold-state', """
|
fire_mqtt_message(self.hass, 'hold-state', """
|
||||||
{ "attribute": "somemode" }
|
{ "attribute": "somemode" }
|
||||||
""")
|
""")
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('somemode', state.attributes.get('hold_mode'))
|
assert 'somemode' == state.attributes.get('hold_mode')
|
||||||
|
|
||||||
# Aux mode
|
# Aux mode
|
||||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
assert 'off' == state.attributes.get('aux_heat')
|
||||||
fire_mqtt_message(self.hass, 'aux-state', 'switchmeon')
|
fire_mqtt_message(self.hass, 'aux-state', 'switchmeon')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('on', state.attributes.get('aux_heat'))
|
assert 'on' == state.attributes.get('aux_heat')
|
||||||
|
|
||||||
# anything other than 'switchmeon' should turn Aux mode off
|
# anything other than 'switchmeon' should turn Aux mode off
|
||||||
fire_mqtt_message(self.hass, 'aux-state', 'somerandomstring')
|
fire_mqtt_message(self.hass, 'aux-state', 'somerandomstring')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
assert 'off' == state.attributes.get('aux_heat')
|
||||||
|
|
||||||
# Current temperature
|
# Current temperature
|
||||||
fire_mqtt_message(self.hass, 'current-temperature', '"74656"')
|
fire_mqtt_message(self.hass, 'current-temperature', '"74656"')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
self.assertEqual(74656, state.attributes.get('current_temperature'))
|
assert 74656 == state.attributes.get('current_temperature')
|
||||||
|
|
||||||
def test_min_temp_custom(self):
|
def test_min_temp_custom(self):
|
||||||
"""Test a custom min temp."""
|
"""Test a custom min temp."""
|
||||||
|
@ -637,8 +635,8 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
min_temp = state.attributes.get('min_temp')
|
min_temp = state.attributes.get('min_temp')
|
||||||
|
|
||||||
self.assertIsInstance(min_temp, float)
|
assert isinstance(min_temp, float)
|
||||||
self.assertEqual(26, state.attributes.get('min_temp'))
|
assert 26 == state.attributes.get('min_temp')
|
||||||
|
|
||||||
def test_max_temp_custom(self):
|
def test_max_temp_custom(self):
|
||||||
"""Test a custom max temp."""
|
"""Test a custom max temp."""
|
||||||
|
@ -650,8 +648,8 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
max_temp = state.attributes.get('max_temp')
|
max_temp = state.attributes.get('max_temp')
|
||||||
|
|
||||||
self.assertIsInstance(max_temp, float)
|
assert isinstance(max_temp, float)
|
||||||
self.assertEqual(60, max_temp)
|
assert 60 == max_temp
|
||||||
|
|
||||||
def test_temp_step_custom(self):
|
def test_temp_step_custom(self):
|
||||||
"""Test a custom temp step."""
|
"""Test a custom temp step."""
|
||||||
|
@ -663,8 +661,8 @@ class TestMQTTClimate(unittest.TestCase):
|
||||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||||
temp_step = state.attributes.get('target_temp_step')
|
temp_step = state.attributes.get('target_temp_step')
|
||||||
|
|
||||||
self.assertIsInstance(temp_step, float)
|
assert isinstance(temp_step, float)
|
||||||
self.assertEqual(0.01, temp_step)
|
assert 0.01 == temp_step
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_climate(hass, mqtt_mock, caplog):
|
async def test_discovery_removal_climate(hass, mqtt_mock, caplog):
|
||||||
|
|
|
@ -104,111 +104,105 @@ class TestNuHeat(unittest.TestCase):
|
||||||
|
|
||||||
def test_name(self):
|
def test_name(self):
|
||||||
"""Test name property."""
|
"""Test name property."""
|
||||||
self.assertEqual(self.thermostat.name, "Master bathroom")
|
assert self.thermostat.name == "Master bathroom"
|
||||||
|
|
||||||
def test_icon(self):
|
def test_icon(self):
|
||||||
"""Test name property."""
|
"""Test name property."""
|
||||||
self.assertEqual(self.thermostat.icon, "mdi:thermometer")
|
assert self.thermostat.icon == "mdi:thermometer"
|
||||||
|
|
||||||
def test_supported_features(self):
|
def test_supported_features(self):
|
||||||
"""Test name property."""
|
"""Test name property."""
|
||||||
features = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_HOLD_MODE |
|
features = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_HOLD_MODE |
|
||||||
SUPPORT_OPERATION_MODE)
|
SUPPORT_OPERATION_MODE)
|
||||||
self.assertEqual(self.thermostat.supported_features, features)
|
assert self.thermostat.supported_features == features
|
||||||
|
|
||||||
def test_temperature_unit(self):
|
def test_temperature_unit(self):
|
||||||
"""Test temperature unit."""
|
"""Test temperature unit."""
|
||||||
self.assertEqual(self.thermostat.temperature_unit, TEMP_FAHRENHEIT)
|
assert self.thermostat.temperature_unit == TEMP_FAHRENHEIT
|
||||||
self.thermostat._temperature_unit = "C"
|
self.thermostat._temperature_unit = "C"
|
||||||
self.assertEqual(self.thermostat.temperature_unit, TEMP_CELSIUS)
|
assert self.thermostat.temperature_unit == TEMP_CELSIUS
|
||||||
|
|
||||||
def test_current_temperature(self):
|
def test_current_temperature(self):
|
||||||
"""Test current temperature."""
|
"""Test current temperature."""
|
||||||
self.assertEqual(self.thermostat.current_temperature, 72)
|
assert self.thermostat.current_temperature == 72
|
||||||
self.thermostat._temperature_unit = "C"
|
self.thermostat._temperature_unit = "C"
|
||||||
self.assertEqual(self.thermostat.current_temperature, 22)
|
assert self.thermostat.current_temperature == 22
|
||||||
|
|
||||||
def test_current_operation(self):
|
def test_current_operation(self):
|
||||||
"""Test current operation."""
|
"""Test current operation."""
|
||||||
self.assertEqual(self.thermostat.current_operation, STATE_HEAT)
|
assert self.thermostat.current_operation == STATE_HEAT
|
||||||
self.thermostat._thermostat.heating = False
|
self.thermostat._thermostat.heating = False
|
||||||
self.assertEqual(self.thermostat.current_operation, STATE_IDLE)
|
assert self.thermostat.current_operation == STATE_IDLE
|
||||||
|
|
||||||
def test_min_temp(self):
|
def test_min_temp(self):
|
||||||
"""Test min temp."""
|
"""Test min temp."""
|
||||||
self.assertEqual(self.thermostat.min_temp, 41)
|
assert self.thermostat.min_temp == 41
|
||||||
self.thermostat._temperature_unit = "C"
|
self.thermostat._temperature_unit = "C"
|
||||||
self.assertEqual(self.thermostat.min_temp, 5)
|
assert self.thermostat.min_temp == 5
|
||||||
|
|
||||||
def test_max_temp(self):
|
def test_max_temp(self):
|
||||||
"""Test max temp."""
|
"""Test max temp."""
|
||||||
self.assertEqual(self.thermostat.max_temp, 157)
|
assert self.thermostat.max_temp == 157
|
||||||
self.thermostat._temperature_unit = "C"
|
self.thermostat._temperature_unit = "C"
|
||||||
self.assertEqual(self.thermostat.max_temp, 69)
|
assert self.thermostat.max_temp == 69
|
||||||
|
|
||||||
def test_target_temperature(self):
|
def test_target_temperature(self):
|
||||||
"""Test target temperature."""
|
"""Test target temperature."""
|
||||||
self.assertEqual(self.thermostat.target_temperature, 72)
|
assert self.thermostat.target_temperature == 72
|
||||||
self.thermostat._temperature_unit = "C"
|
self.thermostat._temperature_unit = "C"
|
||||||
self.assertEqual(self.thermostat.target_temperature, 22)
|
assert self.thermostat.target_temperature == 22
|
||||||
|
|
||||||
def test_current_hold_mode(self):
|
def test_current_hold_mode(self):
|
||||||
"""Test current hold mode."""
|
"""Test current hold mode."""
|
||||||
self.thermostat._thermostat.schedule_mode = SCHEDULE_RUN
|
self.thermostat._thermostat.schedule_mode = SCHEDULE_RUN
|
||||||
self.assertEqual(self.thermostat.current_hold_mode, nuheat.MODE_AUTO)
|
assert self.thermostat.current_hold_mode == nuheat.MODE_AUTO
|
||||||
|
|
||||||
self.thermostat._thermostat.schedule_mode = SCHEDULE_HOLD
|
self.thermostat._thermostat.schedule_mode = SCHEDULE_HOLD
|
||||||
self.assertEqual(
|
assert self.thermostat.current_hold_mode == \
|
||||||
self.thermostat.current_hold_mode, nuheat.MODE_HOLD_TEMPERATURE)
|
nuheat.MODE_HOLD_TEMPERATURE
|
||||||
|
|
||||||
self.thermostat._thermostat.schedule_mode = SCHEDULE_TEMPORARY_HOLD
|
self.thermostat._thermostat.schedule_mode = SCHEDULE_TEMPORARY_HOLD
|
||||||
self.assertEqual(
|
assert self.thermostat.current_hold_mode == nuheat.MODE_TEMPORARY_HOLD
|
||||||
self.thermostat.current_hold_mode, nuheat.MODE_TEMPORARY_HOLD)
|
|
||||||
|
|
||||||
self.thermostat._thermostat.schedule_mode = None
|
self.thermostat._thermostat.schedule_mode = None
|
||||||
self.assertEqual(
|
assert self.thermostat.current_hold_mode == nuheat.MODE_AUTO
|
||||||
self.thermostat.current_hold_mode, nuheat.MODE_AUTO)
|
|
||||||
|
|
||||||
def test_operation_list(self):
|
def test_operation_list(self):
|
||||||
"""Test the operation list."""
|
"""Test the operation list."""
|
||||||
self.assertEqual(
|
assert self.thermostat.operation_list == \
|
||||||
self.thermostat.operation_list,
|
|
||||||
[STATE_HEAT, STATE_IDLE]
|
[STATE_HEAT, STATE_IDLE]
|
||||||
)
|
|
||||||
|
|
||||||
def test_resume_program(self):
|
def test_resume_program(self):
|
||||||
"""Test resume schedule."""
|
"""Test resume schedule."""
|
||||||
self.thermostat.resume_program()
|
self.thermostat.resume_program()
|
||||||
self.thermostat._thermostat.resume_schedule.assert_called_once_with()
|
self.thermostat._thermostat.resume_schedule.assert_called_once_with()
|
||||||
self.assertTrue(self.thermostat._force_update)
|
assert self.thermostat._force_update
|
||||||
|
|
||||||
def test_set_hold_mode(self):
|
def test_set_hold_mode(self):
|
||||||
"""Test set hold mode."""
|
"""Test set hold mode."""
|
||||||
self.thermostat.set_hold_mode("temperature")
|
self.thermostat.set_hold_mode("temperature")
|
||||||
self.assertEqual(
|
assert self.thermostat._thermostat.schedule_mode == SCHEDULE_HOLD
|
||||||
self.thermostat._thermostat.schedule_mode, SCHEDULE_HOLD)
|
assert self.thermostat._force_update
|
||||||
self.assertTrue(self.thermostat._force_update)
|
|
||||||
|
|
||||||
self.thermostat.set_hold_mode("temporary_temperature")
|
self.thermostat.set_hold_mode("temporary_temperature")
|
||||||
self.assertEqual(
|
assert self.thermostat._thermostat.schedule_mode == \
|
||||||
self.thermostat._thermostat.schedule_mode, SCHEDULE_TEMPORARY_HOLD)
|
SCHEDULE_TEMPORARY_HOLD
|
||||||
self.assertTrue(self.thermostat._force_update)
|
assert self.thermostat._force_update
|
||||||
|
|
||||||
self.thermostat.set_hold_mode("auto")
|
self.thermostat.set_hold_mode("auto")
|
||||||
self.assertEqual(
|
assert self.thermostat._thermostat.schedule_mode == SCHEDULE_RUN
|
||||||
self.thermostat._thermostat.schedule_mode, SCHEDULE_RUN)
|
assert self.thermostat._force_update
|
||||||
self.assertTrue(self.thermostat._force_update)
|
|
||||||
|
|
||||||
def test_set_temperature(self):
|
def test_set_temperature(self):
|
||||||
"""Test set temperature."""
|
"""Test set temperature."""
|
||||||
self.thermostat.set_temperature(temperature=85)
|
self.thermostat.set_temperature(temperature=85)
|
||||||
self.assertEqual(self.thermostat._thermostat.target_fahrenheit, 85)
|
assert self.thermostat._thermostat.target_fahrenheit == 85
|
||||||
self.assertTrue(self.thermostat._force_update)
|
assert self.thermostat._force_update
|
||||||
|
|
||||||
self.thermostat._temperature_unit = "C"
|
self.thermostat._temperature_unit = "C"
|
||||||
self.thermostat.set_temperature(temperature=23)
|
self.thermostat.set_temperature(temperature=23)
|
||||||
self.assertEqual(self.thermostat._thermostat.target_celsius, 23)
|
assert self.thermostat._thermostat.target_celsius == 23
|
||||||
self.assertTrue(self.thermostat._force_update)
|
assert self.thermostat._force_update
|
||||||
|
|
||||||
@patch.object(nuheat.NuHeatThermostat, "_throttled_update")
|
@patch.object(nuheat.NuHeatThermostat, "_throttled_update")
|
||||||
def test_update_without_throttle(self, throttled_update):
|
def test_update_without_throttle(self, throttled_update):
|
||||||
|
@ -216,7 +210,7 @@ class TestNuHeat(unittest.TestCase):
|
||||||
self.thermostat._force_update = True
|
self.thermostat._force_update = True
|
||||||
self.thermostat.update()
|
self.thermostat.update()
|
||||||
throttled_update.assert_called_once_with(no_throttle=True)
|
throttled_update.assert_called_once_with(no_throttle=True)
|
||||||
self.assertFalse(self.thermostat._force_update)
|
assert not self.thermostat._force_update
|
||||||
|
|
||||||
@patch.object(nuheat.NuHeatThermostat, "_throttled_update")
|
@patch.object(nuheat.NuHeatThermostat, "_throttled_update")
|
||||||
def test_update_with_throttle(self, throttled_update):
|
def test_update_with_throttle(self, throttled_update):
|
||||||
|
@ -224,7 +218,7 @@ class TestNuHeat(unittest.TestCase):
|
||||||
self.thermostat._force_update = False
|
self.thermostat._force_update = False
|
||||||
self.thermostat.update()
|
self.thermostat.update()
|
||||||
throttled_update.assert_called_once_with()
|
throttled_update.assert_called_once_with()
|
||||||
self.assertFalse(self.thermostat._force_update)
|
assert not self.thermostat._force_update
|
||||||
|
|
||||||
def test_throttled_update(self):
|
def test_throttled_update(self):
|
||||||
"""Test update with throttle."""
|
"""Test update with throttle."""
|
||||||
|
|
|
@ -39,8 +39,7 @@ class TestCounter(unittest.TestCase):
|
||||||
]
|
]
|
||||||
|
|
||||||
for cfg in invalid_configs:
|
for cfg in invalid_configs:
|
||||||
self.assertFalse(
|
assert not setup_component(self.hass, DOMAIN, {DOMAIN: cfg})
|
||||||
setup_component(self.hass, DOMAIN, {DOMAIN: cfg}))
|
|
||||||
|
|
||||||
def test_config_options(self):
|
def test_config_options(self):
|
||||||
"""Test configuration options."""
|
"""Test configuration options."""
|
||||||
|
@ -66,23 +65,23 @@ class TestCounter(unittest.TestCase):
|
||||||
|
|
||||||
_LOGGER.debug('ENTITIES: %s', self.hass.states.entity_ids())
|
_LOGGER.debug('ENTITIES: %s', self.hass.states.entity_ids())
|
||||||
|
|
||||||
self.assertEqual(count_start + 2, len(self.hass.states.entity_ids()))
|
assert count_start + 2 == len(self.hass.states.entity_ids())
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state_1 = self.hass.states.get('counter.test_1')
|
state_1 = self.hass.states.get('counter.test_1')
|
||||||
state_2 = self.hass.states.get('counter.test_2')
|
state_2 = self.hass.states.get('counter.test_2')
|
||||||
|
|
||||||
self.assertIsNotNone(state_1)
|
assert state_1 is not None
|
||||||
self.assertIsNotNone(state_2)
|
assert state_2 is not None
|
||||||
|
|
||||||
self.assertEqual(0, int(state_1.state))
|
assert 0 == int(state_1.state)
|
||||||
self.assertNotIn(ATTR_ICON, state_1.attributes)
|
assert ATTR_ICON not in state_1.attributes
|
||||||
self.assertNotIn(ATTR_FRIENDLY_NAME, state_1.attributes)
|
assert ATTR_FRIENDLY_NAME not in state_1.attributes
|
||||||
|
|
||||||
self.assertEqual(10, int(state_2.state))
|
assert 10 == int(state_2.state)
|
||||||
self.assertEqual('Hello World',
|
assert 'Hello World' == \
|
||||||
state_2.attributes.get(ATTR_FRIENDLY_NAME))
|
state_2.attributes.get(ATTR_FRIENDLY_NAME)
|
||||||
self.assertEqual('mdi:work', state_2.attributes.get(ATTR_ICON))
|
assert 'mdi:work' == state_2.attributes.get(ATTR_ICON)
|
||||||
|
|
||||||
def test_methods(self):
|
def test_methods(self):
|
||||||
"""Test increment, decrement, and reset methods."""
|
"""Test increment, decrement, and reset methods."""
|
||||||
|
@ -97,31 +96,31 @@ class TestCounter(unittest.TestCase):
|
||||||
entity_id = 'counter.test_1'
|
entity_id = 'counter.test_1'
|
||||||
|
|
||||||
state = self.hass.states.get(entity_id)
|
state = self.hass.states.get(entity_id)
|
||||||
self.assertEqual(0, int(state.state))
|
assert 0 == int(state.state)
|
||||||
|
|
||||||
increment(self.hass, entity_id)
|
increment(self.hass, entity_id)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get(entity_id)
|
state = self.hass.states.get(entity_id)
|
||||||
self.assertEqual(1, int(state.state))
|
assert 1 == int(state.state)
|
||||||
|
|
||||||
increment(self.hass, entity_id)
|
increment(self.hass, entity_id)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get(entity_id)
|
state = self.hass.states.get(entity_id)
|
||||||
self.assertEqual(2, int(state.state))
|
assert 2 == int(state.state)
|
||||||
|
|
||||||
decrement(self.hass, entity_id)
|
decrement(self.hass, entity_id)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get(entity_id)
|
state = self.hass.states.get(entity_id)
|
||||||
self.assertEqual(1, int(state.state))
|
assert 1 == int(state.state)
|
||||||
|
|
||||||
reset(self.hass, entity_id)
|
reset(self.hass, entity_id)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get(entity_id)
|
state = self.hass.states.get(entity_id)
|
||||||
self.assertEqual(0, int(state.state))
|
assert 0 == int(state.state)
|
||||||
|
|
||||||
def test_methods_with_config(self):
|
def test_methods_with_config(self):
|
||||||
"""Test increment, decrement, and reset methods with configuration."""
|
"""Test increment, decrement, and reset methods with configuration."""
|
||||||
|
@ -140,25 +139,25 @@ class TestCounter(unittest.TestCase):
|
||||||
entity_id = 'counter.test'
|
entity_id = 'counter.test'
|
||||||
|
|
||||||
state = self.hass.states.get(entity_id)
|
state = self.hass.states.get(entity_id)
|
||||||
self.assertEqual(10, int(state.state))
|
assert 10 == int(state.state)
|
||||||
|
|
||||||
increment(self.hass, entity_id)
|
increment(self.hass, entity_id)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get(entity_id)
|
state = self.hass.states.get(entity_id)
|
||||||
self.assertEqual(15, int(state.state))
|
assert 15 == int(state.state)
|
||||||
|
|
||||||
increment(self.hass, entity_id)
|
increment(self.hass, entity_id)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get(entity_id)
|
state = self.hass.states.get(entity_id)
|
||||||
self.assertEqual(20, int(state.state))
|
assert 20 == int(state.state)
|
||||||
|
|
||||||
decrement(self.hass, entity_id)
|
decrement(self.hass, entity_id)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get(entity_id)
|
state = self.hass.states.get(entity_id)
|
||||||
self.assertEqual(15, int(state.state))
|
assert 15 == int(state.state)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
|
|
@ -33,7 +33,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
|
|
||||||
def test_state_via_state_topic(self):
|
def test_state_via_state_topic(self):
|
||||||
"""Test the controlling state via topic."""
|
"""Test the controlling state via topic."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -44,45 +44,45 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'payload_close': 'CLOSE',
|
'payload_close': 'CLOSE',
|
||||||
'payload_stop': 'STOP'
|
'payload_stop': 'STOP'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
assert STATE_UNKNOWN == state.state
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', '0')
|
fire_mqtt_message(self.hass, 'state-topic', '0')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_CLOSED, state.state)
|
assert STATE_CLOSED == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', '50')
|
fire_mqtt_message(self.hass, 'state-topic', '50')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_OPEN, state.state)
|
assert STATE_OPEN == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', '100')
|
fire_mqtt_message(self.hass, 'state-topic', '100')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_OPEN, state.state)
|
assert STATE_OPEN == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', STATE_CLOSED)
|
fire_mqtt_message(self.hass, 'state-topic', STATE_CLOSED)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_CLOSED, state.state)
|
assert STATE_CLOSED == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', STATE_OPEN)
|
fire_mqtt_message(self.hass, 'state-topic', STATE_OPEN)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_OPEN, state.state)
|
assert STATE_OPEN == state.state
|
||||||
|
|
||||||
def test_state_via_template(self):
|
def test_state_via_template(self):
|
||||||
"""Test the controlling state via topic."""
|
"""Test the controlling state via topic."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -91,37 +91,37 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'qos': 0,
|
'qos': 0,
|
||||||
'value_template': '{{ (value | multiply(0.01)) | int }}',
|
'value_template': '{{ (value | multiply(0.01)) | int }}',
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
assert STATE_UNKNOWN == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', '10000')
|
fire_mqtt_message(self.hass, 'state-topic', '10000')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_OPEN, state.state)
|
assert STATE_OPEN == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', '99')
|
fire_mqtt_message(self.hass, 'state-topic', '99')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_CLOSED, state.state)
|
assert STATE_CLOSED == state.state
|
||||||
|
|
||||||
def test_optimistic_state_change(self):
|
def test_optimistic_state_change(self):
|
||||||
"""Test changing state optimistically."""
|
"""Test changing state optimistically."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'command_topic': 'command-topic',
|
'command_topic': 'command-topic',
|
||||||
'qos': 0,
|
'qos': 0,
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
assert STATE_UNKNOWN == state.state
|
||||||
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
self.hass.services.call(
|
self.hass.services.call(
|
||||||
cover.DOMAIN, SERVICE_OPEN_COVER,
|
cover.DOMAIN, SERVICE_OPEN_COVER,
|
||||||
|
@ -132,7 +132,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'command-topic', 'OPEN', 0, False)
|
'command-topic', 'OPEN', 0, False)
|
||||||
self.mock_publish.async_publish.reset_mock()
|
self.mock_publish.async_publish.reset_mock()
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_OPEN, state.state)
|
assert STATE_OPEN == state.state
|
||||||
|
|
||||||
self.hass.services.call(
|
self.hass.services.call(
|
||||||
cover.DOMAIN, SERVICE_CLOSE_COVER,
|
cover.DOMAIN, SERVICE_CLOSE_COVER,
|
||||||
|
@ -142,11 +142,11 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'command-topic', 'CLOSE', 0, False)
|
'command-topic', 'CLOSE', 0, False)
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_CLOSED, state.state)
|
assert STATE_CLOSED == state.state
|
||||||
|
|
||||||
def test_send_open_cover_command(self):
|
def test_send_open_cover_command(self):
|
||||||
"""Test the sending of open_cover."""
|
"""Test the sending of open_cover."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -154,10 +154,10 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'command_topic': 'command-topic',
|
'command_topic': 'command-topic',
|
||||||
'qos': 2
|
'qos': 2
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
assert STATE_UNKNOWN == state.state
|
||||||
|
|
||||||
self.hass.services.call(
|
self.hass.services.call(
|
||||||
cover.DOMAIN, SERVICE_OPEN_COVER,
|
cover.DOMAIN, SERVICE_OPEN_COVER,
|
||||||
|
@ -167,11 +167,11 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'command-topic', 'OPEN', 2, False)
|
'command-topic', 'OPEN', 2, False)
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
assert STATE_UNKNOWN == state.state
|
||||||
|
|
||||||
def test_send_close_cover_command(self):
|
def test_send_close_cover_command(self):
|
||||||
"""Test the sending of close_cover."""
|
"""Test the sending of close_cover."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -179,10 +179,10 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'command_topic': 'command-topic',
|
'command_topic': 'command-topic',
|
||||||
'qos': 2
|
'qos': 2
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
assert STATE_UNKNOWN == state.state
|
||||||
|
|
||||||
self.hass.services.call(
|
self.hass.services.call(
|
||||||
cover.DOMAIN, SERVICE_CLOSE_COVER,
|
cover.DOMAIN, SERVICE_CLOSE_COVER,
|
||||||
|
@ -192,11 +192,11 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'command-topic', 'CLOSE', 2, False)
|
'command-topic', 'CLOSE', 2, False)
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
assert STATE_UNKNOWN == state.state
|
||||||
|
|
||||||
def test_send_stop__cover_command(self):
|
def test_send_stop__cover_command(self):
|
||||||
"""Test the sending of stop_cover."""
|
"""Test the sending of stop_cover."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -204,10 +204,10 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'command_topic': 'command-topic',
|
'command_topic': 'command-topic',
|
||||||
'qos': 2
|
'qos': 2
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
assert STATE_UNKNOWN == state.state
|
||||||
|
|
||||||
self.hass.services.call(
|
self.hass.services.call(
|
||||||
cover.DOMAIN, SERVICE_STOP_COVER,
|
cover.DOMAIN, SERVICE_STOP_COVER,
|
||||||
|
@ -217,11 +217,11 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'command-topic', 'STOP', 2, False)
|
'command-topic', 'STOP', 2, False)
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
assert STATE_UNKNOWN == state.state
|
||||||
|
|
||||||
def test_current_cover_position(self):
|
def test_current_cover_position(self):
|
||||||
"""Test the current cover position."""
|
"""Test the current cover position."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -231,42 +231,42 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'payload_close': 'CLOSE',
|
'payload_close': 'CLOSE',
|
||||||
'payload_stop': 'STOP'
|
'payload_stop': 'STOP'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state_attributes_dict = self.hass.states.get(
|
state_attributes_dict = self.hass.states.get(
|
||||||
'cover.test').attributes
|
'cover.test').attributes
|
||||||
self.assertFalse('current_position' in state_attributes_dict)
|
assert not ('current_position' in state_attributes_dict)
|
||||||
self.assertFalse('current_tilt_position' in state_attributes_dict)
|
assert not ('current_tilt_position' in state_attributes_dict)
|
||||||
self.assertFalse(4 & self.hass.states.get(
|
assert not (4 & self.hass.states.get(
|
||||||
'cover.test').attributes['supported_features'] == 4)
|
'cover.test').attributes['supported_features'] == 4)
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', '0')
|
fire_mqtt_message(self.hass, 'state-topic', '0')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
current_cover_position = self.hass.states.get(
|
current_cover_position = self.hass.states.get(
|
||||||
'cover.test').attributes['current_position']
|
'cover.test').attributes['current_position']
|
||||||
self.assertEqual(0, current_cover_position)
|
assert 0 == current_cover_position
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', '50')
|
fire_mqtt_message(self.hass, 'state-topic', '50')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
current_cover_position = self.hass.states.get(
|
current_cover_position = self.hass.states.get(
|
||||||
'cover.test').attributes['current_position']
|
'cover.test').attributes['current_position']
|
||||||
self.assertEqual(50, current_cover_position)
|
assert 50 == current_cover_position
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', '101')
|
fire_mqtt_message(self.hass, 'state-topic', '101')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
current_cover_position = self.hass.states.get(
|
current_cover_position = self.hass.states.get(
|
||||||
'cover.test').attributes['current_position']
|
'cover.test').attributes['current_position']
|
||||||
self.assertEqual(50, current_cover_position)
|
assert 50 == current_cover_position
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', 'non-numeric')
|
fire_mqtt_message(self.hass, 'state-topic', 'non-numeric')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
current_cover_position = self.hass.states.get(
|
current_cover_position = self.hass.states.get(
|
||||||
'cover.test').attributes['current_position']
|
'cover.test').attributes['current_position']
|
||||||
self.assertEqual(50, current_cover_position)
|
assert 50 == current_cover_position
|
||||||
|
|
||||||
def test_set_cover_position(self):
|
def test_set_cover_position(self):
|
||||||
"""Test setting cover position."""
|
"""Test setting cover position."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -277,29 +277,29 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'payload_close': 'CLOSE',
|
'payload_close': 'CLOSE',
|
||||||
'payload_stop': 'STOP'
|
'payload_stop': 'STOP'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state_attributes_dict = self.hass.states.get(
|
state_attributes_dict = self.hass.states.get(
|
||||||
'cover.test').attributes
|
'cover.test').attributes
|
||||||
self.assertFalse('current_position' in state_attributes_dict)
|
assert not ('current_position' in state_attributes_dict)
|
||||||
self.assertFalse('current_tilt_position' in state_attributes_dict)
|
assert not ('current_tilt_position' in state_attributes_dict)
|
||||||
|
|
||||||
self.assertTrue(4 & self.hass.states.get(
|
assert 4 & self.hass.states.get(
|
||||||
'cover.test').attributes['supported_features'] == 4)
|
'cover.test').attributes['supported_features'] == 4
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', '22')
|
fire_mqtt_message(self.hass, 'state-topic', '22')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state_attributes_dict = self.hass.states.get(
|
state_attributes_dict = self.hass.states.get(
|
||||||
'cover.test').attributes
|
'cover.test').attributes
|
||||||
self.assertTrue('current_position' in state_attributes_dict)
|
assert 'current_position' in state_attributes_dict
|
||||||
self.assertFalse('current_tilt_position' in state_attributes_dict)
|
assert not ('current_tilt_position' in state_attributes_dict)
|
||||||
current_cover_position = self.hass.states.get(
|
current_cover_position = self.hass.states.get(
|
||||||
'cover.test').attributes['current_position']
|
'cover.test').attributes['current_position']
|
||||||
self.assertEqual(22, current_cover_position)
|
assert 22 == current_cover_position
|
||||||
|
|
||||||
def test_set_position_templated(self):
|
def test_set_position_templated(self):
|
||||||
"""Test setting cover position via template."""
|
"""Test setting cover position via template."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -311,7 +311,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'payload_close': 'CLOSE',
|
'payload_close': 'CLOSE',
|
||||||
'payload_stop': 'STOP'
|
'payload_stop': 'STOP'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
self.hass.services.call(
|
self.hass.services.call(
|
||||||
cover.DOMAIN, SERVICE_SET_COVER_POSITION,
|
cover.DOMAIN, SERVICE_SET_COVER_POSITION,
|
||||||
|
@ -323,7 +323,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
|
|
||||||
def test_set_position_untemplated(self):
|
def test_set_position_untemplated(self):
|
||||||
"""Test setting cover position via template."""
|
"""Test setting cover position via template."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -334,7 +334,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'payload_close': 'CLOSE',
|
'payload_close': 'CLOSE',
|
||||||
'payload_stop': 'STOP'
|
'payload_stop': 'STOP'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
self.hass.services.call(
|
self.hass.services.call(
|
||||||
cover.DOMAIN, SERVICE_SET_COVER_POSITION,
|
cover.DOMAIN, SERVICE_SET_COVER_POSITION,
|
||||||
|
@ -346,7 +346,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
|
|
||||||
def test_no_command_topic(self):
|
def test_no_command_topic(self):
|
||||||
"""Test with no command topic."""
|
"""Test with no command topic."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -357,14 +357,14 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'tilt_command_topic': 'tilt-command',
|
'tilt_command_topic': 'tilt-command',
|
||||||
'tilt_status_topic': 'tilt-status'
|
'tilt_status_topic': 'tilt-status'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
self.assertEqual(240, self.hass.states.get(
|
assert 240 == self.hass.states.get(
|
||||||
'cover.test').attributes['supported_features'])
|
'cover.test').attributes['supported_features']
|
||||||
|
|
||||||
def test_with_command_topic_and_tilt(self):
|
def test_with_command_topic_and_tilt(self):
|
||||||
"""Test with command topic and tilt config."""
|
"""Test with command topic and tilt config."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'command_topic': 'test',
|
'command_topic': 'test',
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
|
@ -376,14 +376,14 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'tilt_command_topic': 'tilt-command',
|
'tilt_command_topic': 'tilt-command',
|
||||||
'tilt_status_topic': 'tilt-status'
|
'tilt_status_topic': 'tilt-status'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
self.assertEqual(251, self.hass.states.get(
|
assert 251 == self.hass.states.get(
|
||||||
'cover.test').attributes['supported_features'])
|
'cover.test').attributes['supported_features']
|
||||||
|
|
||||||
def test_tilt_defaults(self):
|
def test_tilt_defaults(self):
|
||||||
"""Test the defaults."""
|
"""Test the defaults."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -396,19 +396,19 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'tilt_command_topic': 'tilt-command',
|
'tilt_command_topic': 'tilt-command',
|
||||||
'tilt_status_topic': 'tilt-status'
|
'tilt_status_topic': 'tilt-status'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state_attributes_dict = self.hass.states.get(
|
state_attributes_dict = self.hass.states.get(
|
||||||
'cover.test').attributes
|
'cover.test').attributes
|
||||||
self.assertTrue('current_tilt_position' in state_attributes_dict)
|
assert 'current_tilt_position' in state_attributes_dict
|
||||||
|
|
||||||
current_cover_position = self.hass.states.get(
|
current_cover_position = self.hass.states.get(
|
||||||
'cover.test').attributes['current_tilt_position']
|
'cover.test').attributes['current_tilt_position']
|
||||||
self.assertEqual(STATE_UNKNOWN, current_cover_position)
|
assert STATE_UNKNOWN == current_cover_position
|
||||||
|
|
||||||
def test_tilt_via_invocation_defaults(self):
|
def test_tilt_via_invocation_defaults(self):
|
||||||
"""Test tilt defaults on close/open."""
|
"""Test tilt defaults on close/open."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -421,7 +421,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'tilt_command_topic': 'tilt-command-topic',
|
'tilt_command_topic': 'tilt-command-topic',
|
||||||
'tilt_status_topic': 'tilt-status-topic'
|
'tilt_status_topic': 'tilt-status-topic'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
self.hass.services.call(
|
self.hass.services.call(
|
||||||
cover.DOMAIN, SERVICE_OPEN_COVER_TILT,
|
cover.DOMAIN, SERVICE_OPEN_COVER_TILT,
|
||||||
|
@ -442,7 +442,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
|
|
||||||
def test_tilt_given_value(self):
|
def test_tilt_given_value(self):
|
||||||
"""Test tilting to a given value."""
|
"""Test tilting to a given value."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -457,7 +457,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'tilt_opened_value': 400,
|
'tilt_opened_value': 400,
|
||||||
'tilt_closed_value': 125
|
'tilt_closed_value': 125
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
self.hass.services.call(
|
self.hass.services.call(
|
||||||
cover.DOMAIN, SERVICE_OPEN_COVER_TILT,
|
cover.DOMAIN, SERVICE_OPEN_COVER_TILT,
|
||||||
|
@ -478,7 +478,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
|
|
||||||
def test_tilt_via_topic(self):
|
def test_tilt_via_topic(self):
|
||||||
"""Test tilt by updating status via MQTT."""
|
"""Test tilt by updating status via MQTT."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -493,25 +493,25 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'tilt_opened_value': 400,
|
'tilt_opened_value': 400,
|
||||||
'tilt_closed_value': 125
|
'tilt_closed_value': 125
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'tilt-status-topic', '0')
|
fire_mqtt_message(self.hass, 'tilt-status-topic', '0')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
current_cover_tilt_position = self.hass.states.get(
|
current_cover_tilt_position = self.hass.states.get(
|
||||||
'cover.test').attributes['current_tilt_position']
|
'cover.test').attributes['current_tilt_position']
|
||||||
self.assertEqual(0, current_cover_tilt_position)
|
assert 0 == current_cover_tilt_position
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'tilt-status-topic', '50')
|
fire_mqtt_message(self.hass, 'tilt-status-topic', '50')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
current_cover_tilt_position = self.hass.states.get(
|
current_cover_tilt_position = self.hass.states.get(
|
||||||
'cover.test').attributes['current_tilt_position']
|
'cover.test').attributes['current_tilt_position']
|
||||||
self.assertEqual(50, current_cover_tilt_position)
|
assert 50 == current_cover_tilt_position
|
||||||
|
|
||||||
def test_tilt_via_topic_altered_range(self):
|
def test_tilt_via_topic_altered_range(self):
|
||||||
"""Test tilt status via MQTT with altered tilt range."""
|
"""Test tilt status via MQTT with altered tilt range."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -528,32 +528,32 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'tilt_min': 0,
|
'tilt_min': 0,
|
||||||
'tilt_max': 50
|
'tilt_max': 50
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'tilt-status-topic', '0')
|
fire_mqtt_message(self.hass, 'tilt-status-topic', '0')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
current_cover_tilt_position = self.hass.states.get(
|
current_cover_tilt_position = self.hass.states.get(
|
||||||
'cover.test').attributes['current_tilt_position']
|
'cover.test').attributes['current_tilt_position']
|
||||||
self.assertEqual(0, current_cover_tilt_position)
|
assert 0 == current_cover_tilt_position
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'tilt-status-topic', '50')
|
fire_mqtt_message(self.hass, 'tilt-status-topic', '50')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
current_cover_tilt_position = self.hass.states.get(
|
current_cover_tilt_position = self.hass.states.get(
|
||||||
'cover.test').attributes['current_tilt_position']
|
'cover.test').attributes['current_tilt_position']
|
||||||
self.assertEqual(100, current_cover_tilt_position)
|
assert 100 == current_cover_tilt_position
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'tilt-status-topic', '25')
|
fire_mqtt_message(self.hass, 'tilt-status-topic', '25')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
current_cover_tilt_position = self.hass.states.get(
|
current_cover_tilt_position = self.hass.states.get(
|
||||||
'cover.test').attributes['current_tilt_position']
|
'cover.test').attributes['current_tilt_position']
|
||||||
self.assertEqual(50, current_cover_tilt_position)
|
assert 50 == current_cover_tilt_position
|
||||||
|
|
||||||
def test_tilt_position(self):
|
def test_tilt_position(self):
|
||||||
"""Test tilt via method invocation."""
|
"""Test tilt via method invocation."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -568,7 +568,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'tilt_opened_value': 400,
|
'tilt_opened_value': 400,
|
||||||
'tilt_closed_value': 125
|
'tilt_closed_value': 125
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
self.hass.services.call(
|
self.hass.services.call(
|
||||||
cover.DOMAIN, SERVICE_SET_COVER_TILT_POSITION,
|
cover.DOMAIN, SERVICE_SET_COVER_TILT_POSITION,
|
||||||
|
@ -581,7 +581,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
|
|
||||||
def test_tilt_position_altered_range(self):
|
def test_tilt_position_altered_range(self):
|
||||||
"""Test tilt via method invocation with altered range."""
|
"""Test tilt via method invocation with altered range."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -598,7 +598,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'tilt_min': 0,
|
'tilt_min': 0,
|
||||||
'tilt_max': 50
|
'tilt_max': 50
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
self.hass.services.call(
|
self.hass.services.call(
|
||||||
cover.DOMAIN, SERVICE_SET_COVER_TILT_POSITION,
|
cover.DOMAIN, SERVICE_SET_COVER_TILT_POSITION,
|
||||||
|
@ -618,7 +618,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
False, None, 100, 0, 0, 100, False, False, None, None, None,
|
False, None, 100, 0, 0, 100, False, False, None, None, None,
|
||||||
None, None)
|
None, None)
|
||||||
|
|
||||||
self.assertEqual(44, mqtt_cover.find_percentage_in_range(44))
|
assert 44 == mqtt_cover.find_percentage_in_range(44)
|
||||||
|
|
||||||
def test_find_percentage_in_range_altered(self):
|
def test_find_percentage_in_range_altered(self):
|
||||||
"""Test find percentage in range with altered range."""
|
"""Test find percentage in range with altered range."""
|
||||||
|
@ -629,7 +629,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
False, None, 180, 80, 80, 180, False, False, None, None, None,
|
False, None, 180, 80, 80, 180, False, False, None, None, None,
|
||||||
None, None)
|
None, None)
|
||||||
|
|
||||||
self.assertEqual(40, mqtt_cover.find_percentage_in_range(120))
|
assert 40 == mqtt_cover.find_percentage_in_range(120)
|
||||||
|
|
||||||
def test_find_percentage_in_range_defaults_inverted(self):
|
def test_find_percentage_in_range_defaults_inverted(self):
|
||||||
"""Test find percentage in range with default range but inverted."""
|
"""Test find percentage in range with default range but inverted."""
|
||||||
|
@ -640,7 +640,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
False, None, 100, 0, 0, 100, False, True, None, None, None,
|
False, None, 100, 0, 0, 100, False, True, None, None, None,
|
||||||
None, None)
|
None, None)
|
||||||
|
|
||||||
self.assertEqual(56, mqtt_cover.find_percentage_in_range(44))
|
assert 56 == mqtt_cover.find_percentage_in_range(44)
|
||||||
|
|
||||||
def test_find_percentage_in_range_altered_inverted(self):
|
def test_find_percentage_in_range_altered_inverted(self):
|
||||||
"""Test find percentage in range with altered range and inverted."""
|
"""Test find percentage in range with altered range and inverted."""
|
||||||
|
@ -651,7 +651,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
False, None, 180, 80, 80, 180, False, True, None, None, None,
|
False, None, 180, 80, 80, 180, False, True, None, None, None,
|
||||||
None, None)
|
None, None)
|
||||||
|
|
||||||
self.assertEqual(60, mqtt_cover.find_percentage_in_range(120))
|
assert 60 == mqtt_cover.find_percentage_in_range(120)
|
||||||
|
|
||||||
def test_find_in_range_defaults(self):
|
def test_find_in_range_defaults(self):
|
||||||
"""Test find in range with default range."""
|
"""Test find in range with default range."""
|
||||||
|
@ -662,7 +662,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
False, None, 100, 0, 0, 100, False, False, None, None, None,
|
False, None, 100, 0, 0, 100, False, False, None, None, None,
|
||||||
None, None)
|
None, None)
|
||||||
|
|
||||||
self.assertEqual(44, mqtt_cover.find_in_range_from_percent(44))
|
assert 44 == mqtt_cover.find_in_range_from_percent(44)
|
||||||
|
|
||||||
def test_find_in_range_altered(self):
|
def test_find_in_range_altered(self):
|
||||||
"""Test find in range with altered range."""
|
"""Test find in range with altered range."""
|
||||||
|
@ -673,7 +673,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
False, None, 180, 80, 80, 180, False, False, None, None, None,
|
False, None, 180, 80, 80, 180, False, False, None, None, None,
|
||||||
None, None)
|
None, None)
|
||||||
|
|
||||||
self.assertEqual(120, mqtt_cover.find_in_range_from_percent(40))
|
assert 120 == mqtt_cover.find_in_range_from_percent(40)
|
||||||
|
|
||||||
def test_find_in_range_defaults_inverted(self):
|
def test_find_in_range_defaults_inverted(self):
|
||||||
"""Test find in range with default range but inverted."""
|
"""Test find in range with default range but inverted."""
|
||||||
|
@ -684,7 +684,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
False, None, 100, 0, 0, 100, False, True, None, None, None,
|
False, None, 100, 0, 0, 100, False, True, None, None, None,
|
||||||
None, None)
|
None, None)
|
||||||
|
|
||||||
self.assertEqual(44, mqtt_cover.find_in_range_from_percent(56))
|
assert 44 == mqtt_cover.find_in_range_from_percent(56)
|
||||||
|
|
||||||
def test_find_in_range_altered_inverted(self):
|
def test_find_in_range_altered_inverted(self):
|
||||||
"""Test find in range with altered range and inverted."""
|
"""Test find in range with altered range and inverted."""
|
||||||
|
@ -695,25 +695,25 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
False, None, 180, 80, 80, 180, False, True, None, None, None,
|
False, None, 180, 80, 80, 180, False, True, None, None, None,
|
||||||
None, None)
|
None, None)
|
||||||
|
|
||||||
self.assertEqual(120, mqtt_cover.find_in_range_from_percent(60))
|
assert 120 == mqtt_cover.find_in_range_from_percent(60)
|
||||||
|
|
||||||
def test_availability_without_topic(self):
|
def test_availability_without_topic(self):
|
||||||
"""Test availability without defined availability topic."""
|
"""Test availability without defined availability topic."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'state_topic': 'state-topic',
|
'state_topic': 'state-topic',
|
||||||
'command_topic': 'command-topic'
|
'command_topic': 'command-topic'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
def test_availability_by_defaults(self):
|
def test_availability_by_defaults(self):
|
||||||
"""Test availability by defaults with defined topic."""
|
"""Test availability by defaults with defined topic."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -721,26 +721,26 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'command_topic': 'command-topic',
|
'command_topic': 'command-topic',
|
||||||
'availability_topic': 'availability-topic'
|
'availability_topic': 'availability-topic'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
def test_availability_by_custom_payload(self):
|
def test_availability_by_custom_payload(self):
|
||||||
"""Test availability by custom payload with defined topic."""
|
"""Test availability by custom payload with defined topic."""
|
||||||
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
assert setup_component(self.hass, cover.DOMAIN, {
|
||||||
cover.DOMAIN: {
|
cover.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -750,22 +750,22 @@ class TestCoverMQTT(unittest.TestCase):
|
||||||
'payload_available': 'good',
|
'payload_available': 'good',
|
||||||
'payload_not_available': 'nogood'
|
'payload_not_available': 'nogood'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('cover.test')
|
state = self.hass.states.get('cover.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_cover(hass, mqtt_mock, caplog):
|
async def test_discovery_removal_cover(hass, mqtt_mock, caplog):
|
||||||
|
|
|
@ -28,18 +28,18 @@ class TestCoverRfxtrx(unittest.TestCase):
|
||||||
|
|
||||||
def test_valid_config(self):
|
def test_valid_config(self):
|
||||||
"""Test configuration."""
|
"""Test configuration."""
|
||||||
self.assertTrue(setup_component(self.hass, 'cover', {
|
assert setup_component(self.hass, 'cover', {
|
||||||
'cover': {'platform': 'rfxtrx',
|
'cover': {'platform': 'rfxtrx',
|
||||||
'automatic_add': True,
|
'automatic_add': True,
|
||||||
'devices':
|
'devices':
|
||||||
{'0b1100cd0213c7f210010f51': {
|
{'0b1100cd0213c7f210010f51': {
|
||||||
'name': 'Test',
|
'name': 'Test',
|
||||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||||
}}}))
|
}}})
|
||||||
|
|
||||||
def test_invalid_config_capital_letters(self):
|
def test_invalid_config_capital_letters(self):
|
||||||
"""Test configuration."""
|
"""Test configuration."""
|
||||||
self.assertFalse(setup_component(self.hass, 'cover', {
|
assert not setup_component(self.hass, 'cover', {
|
||||||
'cover': {'platform': 'rfxtrx',
|
'cover': {'platform': 'rfxtrx',
|
||||||
'automatic_add': True,
|
'automatic_add': True,
|
||||||
'devices':
|
'devices':
|
||||||
|
@ -47,11 +47,11 @@ class TestCoverRfxtrx(unittest.TestCase):
|
||||||
'name': 'Test',
|
'name': 'Test',
|
||||||
'packetid': '0b1100cd0213c7f210010f51',
|
'packetid': '0b1100cd0213c7f210010f51',
|
||||||
'signal_repetitions': 3}
|
'signal_repetitions': 3}
|
||||||
}}}))
|
}}})
|
||||||
|
|
||||||
def test_invalid_config_extra_key(self):
|
def test_invalid_config_extra_key(self):
|
||||||
"""Test configuration."""
|
"""Test configuration."""
|
||||||
self.assertFalse(setup_component(self.hass, 'cover', {
|
assert not setup_component(self.hass, 'cover', {
|
||||||
'cover': {'platform': 'rfxtrx',
|
'cover': {'platform': 'rfxtrx',
|
||||||
'automatic_add': True,
|
'automatic_add': True,
|
||||||
'invalid_key': 'afda',
|
'invalid_key': 'afda',
|
||||||
|
@ -60,11 +60,11 @@ class TestCoverRfxtrx(unittest.TestCase):
|
||||||
'name': 'Test',
|
'name': 'Test',
|
||||||
'packetid': '0b1100cd0213c7f210010f51',
|
'packetid': '0b1100cd0213c7f210010f51',
|
||||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||||
}}}))
|
}}})
|
||||||
|
|
||||||
def test_invalid_config_capital_packetid(self):
|
def test_invalid_config_capital_packetid(self):
|
||||||
"""Test configuration."""
|
"""Test configuration."""
|
||||||
self.assertFalse(setup_component(self.hass, 'cover', {
|
assert not setup_component(self.hass, 'cover', {
|
||||||
'cover': {'platform': 'rfxtrx',
|
'cover': {'platform': 'rfxtrx',
|
||||||
'automatic_add': True,
|
'automatic_add': True,
|
||||||
'devices':
|
'devices':
|
||||||
|
@ -72,52 +72,52 @@ class TestCoverRfxtrx(unittest.TestCase):
|
||||||
'name': 'Test',
|
'name': 'Test',
|
||||||
'packetid': 'AA1100cd0213c7f210010f51',
|
'packetid': 'AA1100cd0213c7f210010f51',
|
||||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||||
}}}))
|
}}})
|
||||||
|
|
||||||
def test_invalid_config_missing_packetid(self):
|
def test_invalid_config_missing_packetid(self):
|
||||||
"""Test configuration."""
|
"""Test configuration."""
|
||||||
self.assertFalse(setup_component(self.hass, 'cover', {
|
assert not setup_component(self.hass, 'cover', {
|
||||||
'cover': {'platform': 'rfxtrx',
|
'cover': {'platform': 'rfxtrx',
|
||||||
'automatic_add': True,
|
'automatic_add': True,
|
||||||
'devices':
|
'devices':
|
||||||
{'213c7f216': {
|
{'213c7f216': {
|
||||||
'name': 'Test',
|
'name': 'Test',
|
||||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||||
}}}))
|
}}})
|
||||||
|
|
||||||
def test_default_config(self):
|
def test_default_config(self):
|
||||||
"""Test with 0 cover."""
|
"""Test with 0 cover."""
|
||||||
self.assertTrue(setup_component(self.hass, 'cover', {
|
assert setup_component(self.hass, 'cover', {
|
||||||
'cover': {'platform': 'rfxtrx',
|
'cover': {'platform': 'rfxtrx',
|
||||||
'devices': {}}}))
|
'devices': {}}})
|
||||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
def test_one_cover(self):
|
def test_one_cover(self):
|
||||||
"""Test with 1 cover."""
|
"""Test with 1 cover."""
|
||||||
self.assertTrue(setup_component(self.hass, 'cover', {
|
assert setup_component(self.hass, 'cover', {
|
||||||
'cover': {'platform': 'rfxtrx',
|
'cover': {'platform': 'rfxtrx',
|
||||||
'devices':
|
'devices':
|
||||||
{'0b1400cd0213c7f210010f51': {
|
{'0b1400cd0213c7f210010f51': {
|
||||||
'name': 'Test'
|
'name': 'Test'
|
||||||
}}}}))
|
}}}})
|
||||||
|
|
||||||
import RFXtrx as rfxtrxmod
|
import RFXtrx as rfxtrxmod
|
||||||
rfxtrx_core.RFXOBJECT =\
|
rfxtrx_core.RFXOBJECT =\
|
||||||
rfxtrxmod.Core("", transport_protocol=rfxtrxmod.DummyTransport)
|
rfxtrxmod.Core("", transport_protocol=rfxtrxmod.DummyTransport)
|
||||||
|
|
||||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
assert 1 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
for id in rfxtrx_core.RFX_DEVICES:
|
for id in rfxtrx_core.RFX_DEVICES:
|
||||||
entity = rfxtrx_core.RFX_DEVICES[id]
|
entity = rfxtrx_core.RFX_DEVICES[id]
|
||||||
self.assertEqual(entity.signal_repetitions, 1)
|
assert entity.signal_repetitions == 1
|
||||||
self.assertFalse(entity.should_fire_event)
|
assert not entity.should_fire_event
|
||||||
self.assertFalse(entity.should_poll)
|
assert not entity.should_poll
|
||||||
entity.open_cover()
|
entity.open_cover()
|
||||||
entity.close_cover()
|
entity.close_cover()
|
||||||
entity.stop_cover()
|
entity.stop_cover()
|
||||||
|
|
||||||
def test_several_covers(self):
|
def test_several_covers(self):
|
||||||
"""Test with 3 covers."""
|
"""Test with 3 covers."""
|
||||||
self.assertTrue(setup_component(self.hass, 'cover', {
|
assert setup_component(self.hass, 'cover', {
|
||||||
'cover': {'platform': 'rfxtrx',
|
'cover': {'platform': 'rfxtrx',
|
||||||
'signal_repetitions': 3,
|
'signal_repetitions': 3,
|
||||||
'devices':
|
'devices':
|
||||||
|
@ -127,13 +127,13 @@ class TestCoverRfxtrx(unittest.TestCase):
|
||||||
'name': 'Bath'},
|
'name': 'Bath'},
|
||||||
'0b1100101118cdea02010f70': {
|
'0b1100101118cdea02010f70': {
|
||||||
'name': 'Living'}
|
'name': 'Living'}
|
||||||
}}}))
|
}}})
|
||||||
|
|
||||||
self.assertEqual(3, len(rfxtrx_core.RFX_DEVICES))
|
assert 3 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
device_num = 0
|
device_num = 0
|
||||||
for id in rfxtrx_core.RFX_DEVICES:
|
for id in rfxtrx_core.RFX_DEVICES:
|
||||||
entity = rfxtrx_core.RFX_DEVICES[id]
|
entity = rfxtrx_core.RFX_DEVICES[id]
|
||||||
self.assertEqual(entity.signal_repetitions, 3)
|
assert entity.signal_repetitions == 3
|
||||||
if entity.name == 'Living':
|
if entity.name == 'Living':
|
||||||
device_num = device_num + 1
|
device_num = device_num + 1
|
||||||
elif entity.name == 'Bath':
|
elif entity.name == 'Bath':
|
||||||
|
@ -141,14 +141,14 @@ class TestCoverRfxtrx(unittest.TestCase):
|
||||||
elif entity.name == 'Test':
|
elif entity.name == 'Test':
|
||||||
device_num = device_num + 1
|
device_num = device_num + 1
|
||||||
|
|
||||||
self.assertEqual(3, device_num)
|
assert 3 == device_num
|
||||||
|
|
||||||
def test_discover_covers(self):
|
def test_discover_covers(self):
|
||||||
"""Test with discovery of covers."""
|
"""Test with discovery of covers."""
|
||||||
self.assertTrue(setup_component(self.hass, 'cover', {
|
assert setup_component(self.hass, 'cover', {
|
||||||
'cover': {'platform': 'rfxtrx',
|
'cover': {'platform': 'rfxtrx',
|
||||||
'automatic_add': True,
|
'automatic_add': True,
|
||||||
'devices': {}}}))
|
'devices': {}}})
|
||||||
|
|
||||||
event = rfxtrx_core.get_rfx_object('0a140002f38cae010f0070')
|
event = rfxtrx_core.get_rfx_object('0a140002f38cae010f0070')
|
||||||
event.data = bytearray([0x0A, 0x14, 0x00, 0x02, 0xF3, 0x8C,
|
event.data = bytearray([0x0A, 0x14, 0x00, 0x02, 0xF3, 0x8C,
|
||||||
|
@ -156,7 +156,7 @@ class TestCoverRfxtrx(unittest.TestCase):
|
||||||
|
|
||||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||||
evt_sub(event)
|
evt_sub(event)
|
||||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
assert 1 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
event = rfxtrx_core.get_rfx_object('0a1400adf394ab020e0060')
|
event = rfxtrx_core.get_rfx_object('0a1400adf394ab020e0060')
|
||||||
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
||||||
|
@ -164,14 +164,14 @@ class TestCoverRfxtrx(unittest.TestCase):
|
||||||
|
|
||||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||||
evt_sub(event)
|
evt_sub(event)
|
||||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
assert 2 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
# Trying to add a sensor
|
# Trying to add a sensor
|
||||||
event = rfxtrx_core.get_rfx_object('0a52085e070100b31b0279')
|
event = rfxtrx_core.get_rfx_object('0a52085e070100b31b0279')
|
||||||
event.data = bytearray(b'\nR\x08^\x07\x01\x00\xb3\x1b\x02y')
|
event.data = bytearray(b'\nR\x08^\x07\x01\x00\xb3\x1b\x02y')
|
||||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||||
evt_sub(event)
|
evt_sub(event)
|
||||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
assert 2 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
# Trying to add a light
|
# Trying to add a light
|
||||||
event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70')
|
event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70')
|
||||||
|
@ -179,14 +179,14 @@ class TestCoverRfxtrx(unittest.TestCase):
|
||||||
0xcd, 0xea, 0x01, 0x02, 0x0f, 0x70])
|
0xcd, 0xea, 0x01, 0x02, 0x0f, 0x70])
|
||||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||||
evt_sub(event)
|
evt_sub(event)
|
||||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
assert 2 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
def test_discover_cover_noautoadd(self):
|
def test_discover_cover_noautoadd(self):
|
||||||
"""Test with discovery of cover when auto add is False."""
|
"""Test with discovery of cover when auto add is False."""
|
||||||
self.assertTrue(setup_component(self.hass, 'cover', {
|
assert setup_component(self.hass, 'cover', {
|
||||||
'cover': {'platform': 'rfxtrx',
|
'cover': {'platform': 'rfxtrx',
|
||||||
'automatic_add': False,
|
'automatic_add': False,
|
||||||
'devices': {}}}))
|
'devices': {}}})
|
||||||
|
|
||||||
event = rfxtrx_core.get_rfx_object('0a1400adf394ab010d0060')
|
event = rfxtrx_core.get_rfx_object('0a1400adf394ab010d0060')
|
||||||
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
||||||
|
@ -194,21 +194,21 @@ class TestCoverRfxtrx(unittest.TestCase):
|
||||||
|
|
||||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||||
evt_sub(event)
|
evt_sub(event)
|
||||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
event = rfxtrx_core.get_rfx_object('0a1400adf394ab020e0060')
|
event = rfxtrx_core.get_rfx_object('0a1400adf394ab020e0060')
|
||||||
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
||||||
0xAB, 0x02, 0x0E, 0x00, 0x60])
|
0xAB, 0x02, 0x0E, 0x00, 0x60])
|
||||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||||
evt_sub(event)
|
evt_sub(event)
|
||||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
# Trying to add a sensor
|
# Trying to add a sensor
|
||||||
event = rfxtrx_core.get_rfx_object('0a52085e070100b31b0279')
|
event = rfxtrx_core.get_rfx_object('0a52085e070100b31b0279')
|
||||||
event.data = bytearray(b'\nR\x08^\x07\x01\x00\xb3\x1b\x02y')
|
event.data = bytearray(b'\nR\x08^\x07\x01\x00\xb3\x1b\x02y')
|
||||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||||
evt_sub(event)
|
evt_sub(event)
|
||||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
# Trying to add a light
|
# Trying to add a light
|
||||||
event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70')
|
event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70')
|
||||||
|
@ -216,4 +216,4 @@ class TestCoverRfxtrx(unittest.TestCase):
|
||||||
0x18, 0xcd, 0xea, 0x01, 0x02, 0x0f, 0x70])
|
0x18, 0xcd, 0xea, 0x01, 0x02, 0x0f, 0x70])
|
||||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||||
evt_sub(event)
|
evt_sub(event)
|
||||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
|
@ -103,5 +103,5 @@ class TestComponentsDeviceTrackerASUSWRT(unittest.TestCase):
|
||||||
conf_dict[DOMAIN][CONF_MODE] = 'router'
|
conf_dict[DOMAIN][CONF_MODE] = 'router'
|
||||||
conf_dict[DOMAIN][CONF_PROTOCOL] = 'ssh'
|
conf_dict[DOMAIN][CONF_PROTOCOL] = 'ssh'
|
||||||
conf_dict[DOMAIN][CONF_PORT] = 22
|
conf_dict[DOMAIN][CONF_PORT] = 22
|
||||||
self.assertEqual(asuswrt_mock.call_count, 1)
|
assert asuswrt_mock.call_count == 1
|
||||||
self.assertEqual(asuswrt_mock.call_args, mock.call(conf_dict[DOMAIN]))
|
assert asuswrt_mock.call_args == mock.call(conf_dict[DOMAIN])
|
||||||
|
|
|
@ -69,9 +69,8 @@ class TestDdwrt(unittest.TestCase):
|
||||||
CONF_PASSWORD: '0'
|
CONF_PASSWORD: '0'
|
||||||
}})
|
}})
|
||||||
|
|
||||||
self.assertTrue(
|
assert 'Failed to authenticate' in \
|
||||||
'Failed to authenticate' in
|
str(mock_error.call_args_list[-1])
|
||||||
str(mock_error.call_args_list[-1]))
|
|
||||||
|
|
||||||
@mock.patch('homeassistant.components.device_tracker.ddwrt._LOGGER.error')
|
@mock.patch('homeassistant.components.device_tracker.ddwrt._LOGGER.error')
|
||||||
def test_invalid_response(self, mock_error):
|
def test_invalid_response(self, mock_error):
|
||||||
|
@ -89,9 +88,8 @@ class TestDdwrt(unittest.TestCase):
|
||||||
CONF_PASSWORD: '0'
|
CONF_PASSWORD: '0'
|
||||||
}})
|
}})
|
||||||
|
|
||||||
self.assertTrue(
|
assert 'Invalid response from DD-WRT' in \
|
||||||
'Invalid response from DD-WRT' in
|
str(mock_error.call_args_list[-1])
|
||||||
str(mock_error.call_args_list[-1]))
|
|
||||||
|
|
||||||
@mock.patch('homeassistant.components.device_tracker._LOGGER.error')
|
@mock.patch('homeassistant.components.device_tracker._LOGGER.error')
|
||||||
@mock.patch('homeassistant.components.device_tracker.'
|
@mock.patch('homeassistant.components.device_tracker.'
|
||||||
|
@ -106,9 +104,8 @@ class TestDdwrt(unittest.TestCase):
|
||||||
CONF_USERNAME: 'fake_user',
|
CONF_USERNAME: 'fake_user',
|
||||||
CONF_PASSWORD: '0'
|
CONF_PASSWORD: '0'
|
||||||
}})
|
}})
|
||||||
self.assertTrue(
|
assert 'Error setting up platform' in \
|
||||||
'Error setting up platform' in
|
str(error_mock.call_args_list[-1])
|
||||||
str(error_mock.call_args_list[-1]))
|
|
||||||
|
|
||||||
@mock.patch('homeassistant.components.device_tracker.ddwrt.requests.get',
|
@mock.patch('homeassistant.components.device_tracker.ddwrt.requests.get',
|
||||||
side_effect=requests.exceptions.Timeout)
|
side_effect=requests.exceptions.Timeout)
|
||||||
|
@ -124,9 +121,8 @@ class TestDdwrt(unittest.TestCase):
|
||||||
CONF_PASSWORD: '0'
|
CONF_PASSWORD: '0'
|
||||||
}})
|
}})
|
||||||
|
|
||||||
self.assertTrue(
|
assert 'Connection to the router timed out' in \
|
||||||
'Connection to the router timed out' in
|
str(mock_error.call_args_list[-1])
|
||||||
str(mock_error.call_args_list[-1]))
|
|
||||||
|
|
||||||
def test_scan_devices(self):
|
def test_scan_devices(self):
|
||||||
"""Test creating device info (MAC, name) from response.
|
"""Test creating device info (MAC, name) from response.
|
||||||
|
@ -158,8 +154,8 @@ class TestDdwrt(unittest.TestCase):
|
||||||
path = self.hass.config.path(device_tracker.YAML_DEVICES)
|
path = self.hass.config.path(device_tracker.YAML_DEVICES)
|
||||||
devices = config.load_yaml_config_file(path)
|
devices = config.load_yaml_config_file(path)
|
||||||
for device in devices:
|
for device in devices:
|
||||||
self.assertIn(devices[device]['mac'], status_lan)
|
assert devices[device]['mac'] in status_lan
|
||||||
self.assertIn(slugify(devices[device]['name']), status_lan)
|
assert slugify(devices[device]['name']) in status_lan
|
||||||
|
|
||||||
def test_device_name_no_data(self):
|
def test_device_name_no_data(self):
|
||||||
"""Test creating device info (MAC only) when no response."""
|
"""Test creating device info (MAC only) when no response."""
|
||||||
|
@ -185,7 +181,7 @@ class TestDdwrt(unittest.TestCase):
|
||||||
status_lan = load_fixture('Ddwrt_Status_Lan.txt')
|
status_lan = load_fixture('Ddwrt_Status_Lan.txt')
|
||||||
for device in devices:
|
for device in devices:
|
||||||
_LOGGER.error(devices[device])
|
_LOGGER.error(devices[device])
|
||||||
self.assertIn(devices[device]['mac'], status_lan)
|
assert devices[device]['mac'] in status_lan
|
||||||
|
|
||||||
def test_device_name_no_dhcp(self):
|
def test_device_name_no_dhcp(self):
|
||||||
"""Test creating device info (MAC) when missing dhcp response."""
|
"""Test creating device info (MAC) when missing dhcp response."""
|
||||||
|
@ -213,7 +209,7 @@ class TestDdwrt(unittest.TestCase):
|
||||||
status_lan = load_fixture('Ddwrt_Status_Lan.txt')
|
status_lan = load_fixture('Ddwrt_Status_Lan.txt')
|
||||||
for device in devices:
|
for device in devices:
|
||||||
_LOGGER.error(devices[device])
|
_LOGGER.error(devices[device])
|
||||||
self.assertIn(devices[device]['mac'], status_lan)
|
assert devices[device]['mac'] in status_lan
|
||||||
|
|
||||||
def test_update_no_data(self):
|
def test_update_no_data(self):
|
||||||
"""Test error handling of no response when active devices checked."""
|
"""Test error handling of no response when active devices checked."""
|
||||||
|
|
|
@ -25,6 +25,7 @@ from homeassistant.helpers.json import JSONEncoder
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
get_test_home_assistant, fire_time_changed,
|
get_test_home_assistant, fire_time_changed,
|
||||||
patch_yaml_files, assert_setup_component, mock_restore_cache)
|
patch_yaml_files, assert_setup_component, mock_restore_cache)
|
||||||
|
import pytest
|
||||||
|
|
||||||
TEST_PLATFORM = {device_tracker.DOMAIN: {CONF_PLATFORM: 'test'}}
|
TEST_PLATFORM = {device_tracker.DOMAIN: {CONF_PLATFORM: 'test'}}
|
||||||
|
|
||||||
|
@ -57,11 +58,11 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.states.set(entity_id, STATE_HOME)
|
self.hass.states.set(entity_id, STATE_HOME)
|
||||||
|
|
||||||
self.assertTrue(device_tracker.is_on(self.hass, entity_id))
|
assert device_tracker.is_on(self.hass, entity_id)
|
||||||
|
|
||||||
self.hass.states.set(entity_id, STATE_NOT_HOME)
|
self.hass.states.set(entity_id, STATE_NOT_HOME)
|
||||||
|
|
||||||
self.assertFalse(device_tracker.is_on(self.hass, entity_id))
|
assert not device_tracker.is_on(self.hass, entity_id)
|
||||||
|
|
||||||
# pylint: disable=no-self-use
|
# pylint: disable=no-self-use
|
||||||
def test_reading_broken_yaml_config(self):
|
def test_reading_broken_yaml_config(self):
|
||||||
|
@ -103,13 +104,13 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
TEST_PLATFORM)
|
TEST_PLATFORM)
|
||||||
config = device_tracker.load_config(self.yaml_devices, self.hass,
|
config = device_tracker.load_config(self.yaml_devices, self.hass,
|
||||||
device.consider_home)[0]
|
device.consider_home)[0]
|
||||||
self.assertEqual(device.dev_id, config.dev_id)
|
assert device.dev_id == config.dev_id
|
||||||
self.assertEqual(device.track, config.track)
|
assert device.track == config.track
|
||||||
self.assertEqual(device.mac, config.mac)
|
assert device.mac == config.mac
|
||||||
self.assertEqual(device.config_picture, config.config_picture)
|
assert device.config_picture == config.config_picture
|
||||||
self.assertEqual(device.away_hide, config.away_hide)
|
assert device.away_hide == config.away_hide
|
||||||
self.assertEqual(device.consider_home, config.consider_home)
|
assert device.consider_home == config.consider_home
|
||||||
self.assertEqual(device.icon, config.icon)
|
assert device.icon == config.icon
|
||||||
|
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
@patch('homeassistant.components.device_tracker._LOGGER.warning')
|
@patch('homeassistant.components.device_tracker._LOGGER.warning')
|
||||||
|
@ -157,7 +158,7 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
'AB:CD:EF:GH:IJ', 'Test name', gravatar='test@example.com')
|
'AB:CD:EF:GH:IJ', 'Test name', gravatar='test@example.com')
|
||||||
gravatar_url = ("https://www.gravatar.com/avatar/"
|
gravatar_url = ("https://www.gravatar.com/avatar/"
|
||||||
"55502f40dc8b7c769880b10874abc9d0.jpg?s=80&d=wavatar")
|
"55502f40dc8b7c769880b10874abc9d0.jpg?s=80&d=wavatar")
|
||||||
self.assertEqual(device.config_picture, gravatar_url)
|
assert device.config_picture == gravatar_url
|
||||||
|
|
||||||
def test_gravatar_and_picture(self):
|
def test_gravatar_and_picture(self):
|
||||||
"""Test that Gravatar overrides picture."""
|
"""Test that Gravatar overrides picture."""
|
||||||
|
@ -168,7 +169,7 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
gravatar='test@example.com')
|
gravatar='test@example.com')
|
||||||
gravatar_url = ("https://www.gravatar.com/avatar/"
|
gravatar_url = ("https://www.gravatar.com/avatar/"
|
||||||
"55502f40dc8b7c769880b10874abc9d0.jpg?s=80&d=wavatar")
|
"55502f40dc8b7c769880b10874abc9d0.jpg?s=80&d=wavatar")
|
||||||
self.assertEqual(device.config_picture, gravatar_url)
|
assert device.config_picture == gravatar_url
|
||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
'homeassistant.components.device_tracker.DeviceTracker.see')
|
'homeassistant.components.device_tracker.DeviceTracker.see')
|
||||||
|
@ -206,8 +207,8 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
}})
|
}})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(STATE_HOME,
|
assert STATE_HOME == \
|
||||||
self.hass.states.get('device_tracker.dev1').state)
|
self.hass.states.get('device_tracker.dev1').state
|
||||||
|
|
||||||
scanner.leave_home('DEV1')
|
scanner.leave_home('DEV1')
|
||||||
|
|
||||||
|
@ -216,8 +217,8 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
fire_time_changed(self.hass, scan_time)
|
fire_time_changed(self.hass, scan_time)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(STATE_NOT_HOME,
|
assert STATE_NOT_HOME == \
|
||||||
self.hass.states.get('device_tracker.dev1').state)
|
self.hass.states.get('device_tracker.dev1').state
|
||||||
|
|
||||||
def test_entity_attributes(self):
|
def test_entity_attributes(self):
|
||||||
"""Test the entity attributes."""
|
"""Test the entity attributes."""
|
||||||
|
@ -238,9 +239,9 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
|
|
||||||
attrs = self.hass.states.get(entity_id).attributes
|
attrs = self.hass.states.get(entity_id).attributes
|
||||||
|
|
||||||
self.assertEqual(friendly_name, attrs.get(ATTR_FRIENDLY_NAME))
|
assert friendly_name == attrs.get(ATTR_FRIENDLY_NAME)
|
||||||
self.assertEqual(icon, attrs.get(ATTR_ICON))
|
assert icon == attrs.get(ATTR_ICON)
|
||||||
self.assertEqual(picture, attrs.get(ATTR_ENTITY_PICTURE))
|
assert picture == attrs.get(ATTR_ENTITY_PICTURE)
|
||||||
|
|
||||||
def test_device_hidden(self):
|
def test_device_hidden(self):
|
||||||
"""Test hidden devices."""
|
"""Test hidden devices."""
|
||||||
|
@ -258,8 +259,8 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
assert setup_component(self.hass, device_tracker.DOMAIN,
|
assert setup_component(self.hass, device_tracker.DOMAIN,
|
||||||
TEST_PLATFORM)
|
TEST_PLATFORM)
|
||||||
|
|
||||||
self.assertTrue(self.hass.states.get(entity_id)
|
assert self.hass.states.get(entity_id) \
|
||||||
.attributes.get(ATTR_HIDDEN))
|
.attributes.get(ATTR_HIDDEN)
|
||||||
|
|
||||||
def test_group_all_devices(self):
|
def test_group_all_devices(self):
|
||||||
"""Test grouping of devices."""
|
"""Test grouping of devices."""
|
||||||
|
@ -279,10 +280,9 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get(device_tracker.ENTITY_ID_ALL_DEVICES)
|
state = self.hass.states.get(device_tracker.ENTITY_ID_ALL_DEVICES)
|
||||||
self.assertIsNotNone(state)
|
assert state is not None
|
||||||
self.assertEqual(STATE_NOT_HOME, state.state)
|
assert STATE_NOT_HOME == state.state
|
||||||
self.assertSequenceEqual((entity_id,),
|
assert (entity_id,) == state.attributes.get(ATTR_ENTITY_ID)
|
||||||
state.attributes.get(ATTR_ENTITY_ID))
|
|
||||||
|
|
||||||
@patch('homeassistant.components.device_tracker.DeviceTracker.async_see')
|
@patch('homeassistant.components.device_tracker.DeviceTracker.async_see')
|
||||||
def test_see_service(self, mock_see):
|
def test_see_service(self, mock_see):
|
||||||
|
@ -302,8 +302,8 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
device_tracker.see(self.hass, **params)
|
device_tracker.see(self.hass, **params)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
assert mock_see.call_count == 1
|
assert mock_see.call_count == 1
|
||||||
self.assertEqual(mock_see.call_count, 1)
|
assert mock_see.call_count == 1
|
||||||
self.assertEqual(mock_see.call_args, call(**params))
|
assert mock_see.call_args == call(**params)
|
||||||
|
|
||||||
mock_see.reset_mock()
|
mock_see.reset_mock()
|
||||||
params['dev_id'] += chr(233) # e' acute accent from icloud
|
params['dev_id'] += chr(233) # e' acute accent from icloud
|
||||||
|
@ -311,8 +311,8 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
device_tracker.see(self.hass, **params)
|
device_tracker.see(self.hass, **params)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
assert mock_see.call_count == 1
|
assert mock_see.call_count == 1
|
||||||
self.assertEqual(mock_see.call_count, 1)
|
assert mock_see.call_count == 1
|
||||||
self.assertEqual(mock_see.call_args, call(**params))
|
assert mock_see.call_args == call(**params)
|
||||||
|
|
||||||
def test_new_device_event_fired(self):
|
def test_new_device_event_fired(self):
|
||||||
"""Test that the device tracker will fire an event."""
|
"""Test that the device tracker will fire an event."""
|
||||||
|
@ -375,8 +375,8 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
|
|
||||||
def test_see_state(self):
|
def test_see_state(self):
|
||||||
"""Test device tracker see records state correctly."""
|
"""Test device tracker see records state correctly."""
|
||||||
self.assertTrue(setup_component(self.hass, device_tracker.DOMAIN,
|
assert setup_component(self.hass, device_tracker.DOMAIN,
|
||||||
TEST_PLATFORM))
|
TEST_PLATFORM)
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
'mac': 'AA:BB:CC:DD:EE:FF',
|
'mac': 'AA:BB:CC:DD:EE:FF',
|
||||||
|
@ -401,17 +401,17 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('device_tracker.examplecom')
|
state = self.hass.states.get('device_tracker.examplecom')
|
||||||
attrs = state.attributes
|
attrs = state.attributes
|
||||||
self.assertEqual(state.state, 'Work')
|
assert state.state == 'Work'
|
||||||
self.assertEqual(state.object_id, 'examplecom')
|
assert state.object_id == 'examplecom'
|
||||||
self.assertEqual(state.name, 'example.com')
|
assert state.name == 'example.com'
|
||||||
self.assertEqual(attrs['friendly_name'], 'example.com')
|
assert attrs['friendly_name'] == 'example.com'
|
||||||
self.assertEqual(attrs['battery'], 100)
|
assert attrs['battery'] == 100
|
||||||
self.assertEqual(attrs['latitude'], 0.3)
|
assert attrs['latitude'] == 0.3
|
||||||
self.assertEqual(attrs['longitude'], 0.8)
|
assert attrs['longitude'] == 0.8
|
||||||
self.assertEqual(attrs['test'], 'test')
|
assert attrs['test'] == 'test'
|
||||||
self.assertEqual(attrs['gps_accuracy'], 1)
|
assert attrs['gps_accuracy'] == 1
|
||||||
self.assertEqual(attrs['source_type'], 'gps')
|
assert attrs['source_type'] == 'gps'
|
||||||
self.assertEqual(attrs['number'], 1)
|
assert attrs['number'] == 1
|
||||||
|
|
||||||
def test_see_passive_zone_state(self):
|
def test_see_passive_zone_state(self):
|
||||||
"""Test that the device tracker sets gps for passive trackers."""
|
"""Test that the device tracker sets gps for passive trackers."""
|
||||||
|
@ -447,15 +447,15 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('device_tracker.dev1')
|
state = self.hass.states.get('device_tracker.dev1')
|
||||||
attrs = state.attributes
|
attrs = state.attributes
|
||||||
self.assertEqual(STATE_HOME, state.state)
|
assert STATE_HOME == state.state
|
||||||
self.assertEqual(state.object_id, 'dev1')
|
assert state.object_id == 'dev1'
|
||||||
self.assertEqual(state.name, 'dev1')
|
assert state.name == 'dev1'
|
||||||
self.assertEqual(attrs.get('friendly_name'), 'dev1')
|
assert attrs.get('friendly_name') == 'dev1'
|
||||||
self.assertEqual(attrs.get('latitude'), 1)
|
assert attrs.get('latitude') == 1
|
||||||
self.assertEqual(attrs.get('longitude'), 2)
|
assert attrs.get('longitude') == 2
|
||||||
self.assertEqual(attrs.get('gps_accuracy'), 0)
|
assert attrs.get('gps_accuracy') == 0
|
||||||
self.assertEqual(attrs.get('source_type'),
|
assert attrs.get('source_type') == \
|
||||||
device_tracker.SOURCE_TYPE_ROUTER)
|
device_tracker.SOURCE_TYPE_ROUTER
|
||||||
|
|
||||||
scanner.leave_home('dev1')
|
scanner.leave_home('dev1')
|
||||||
|
|
||||||
|
@ -466,15 +466,15 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
|
|
||||||
state = self.hass.states.get('device_tracker.dev1')
|
state = self.hass.states.get('device_tracker.dev1')
|
||||||
attrs = state.attributes
|
attrs = state.attributes
|
||||||
self.assertEqual(STATE_NOT_HOME, state.state)
|
assert STATE_NOT_HOME == state.state
|
||||||
self.assertEqual(state.object_id, 'dev1')
|
assert state.object_id == 'dev1'
|
||||||
self.assertEqual(state.name, 'dev1')
|
assert state.name == 'dev1'
|
||||||
self.assertEqual(attrs.get('friendly_name'), 'dev1')
|
assert attrs.get('friendly_name') == 'dev1'
|
||||||
self.assertEqual(attrs.get('latitude'), None)
|
assert attrs.get('latitude')is None
|
||||||
self.assertEqual(attrs.get('longitude'), None)
|
assert attrs.get('longitude')is None
|
||||||
self.assertEqual(attrs.get('gps_accuracy'), None)
|
assert attrs.get('gps_accuracy')is None
|
||||||
self.assertEqual(attrs.get('source_type'),
|
assert attrs.get('source_type') == \
|
||||||
device_tracker.SOURCE_TYPE_ROUTER)
|
device_tracker.SOURCE_TYPE_ROUTER
|
||||||
|
|
||||||
@patch('homeassistant.components.device_tracker._LOGGER.warning')
|
@patch('homeassistant.components.device_tracker._LOGGER.warning')
|
||||||
def test_see_failures(self, mock_warning):
|
def test_see_failures(self, mock_warning):
|
||||||
|
@ -486,7 +486,7 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||||
tracker.see(mac=567, host_name="Number MAC")
|
tracker.see(mac=567, host_name="Number MAC")
|
||||||
|
|
||||||
# No device id or MAC(not added)
|
# No device id or MAC(not added)
|
||||||
with self.assertRaises(HomeAssistantError):
|
with pytest.raises(HomeAssistantError):
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
tracker.async_see(), self.hass.loop).result()
|
tracker.async_see(), self.hass.loop).result()
|
||||||
assert mock_warning.call_count == 0
|
assert mock_warning.call_count == 0
|
||||||
|
|
|
@ -36,7 +36,7 @@ class TestComponentsDeviceTrackerMQTT(unittest.TestCase):
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def mock_setup_scanner(hass, config, see, discovery_info=None):
|
def mock_setup_scanner(hass, config, see, discovery_info=None):
|
||||||
"""Check that Qos was added by validation."""
|
"""Check that Qos was added by validation."""
|
||||||
self.assertTrue('qos' in config)
|
assert 'qos' in config
|
||||||
|
|
||||||
with patch('homeassistant.components.device_tracker.mqtt.'
|
with patch('homeassistant.components.device_tracker.mqtt.'
|
||||||
'async_setup_scanner', autospec=True,
|
'async_setup_scanner', autospec=True,
|
||||||
|
@ -68,7 +68,7 @@ class TestComponentsDeviceTrackerMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
fire_mqtt_message(self.hass, topic, location)
|
fire_mqtt_message(self.hass, topic, location)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(location, self.hass.states.get(entity_id).state)
|
assert location == self.hass.states.get(entity_id).state
|
||||||
|
|
||||||
def test_single_level_wildcard_topic(self):
|
def test_single_level_wildcard_topic(self):
|
||||||
"""Test single level wildcard topic."""
|
"""Test single level wildcard topic."""
|
||||||
|
@ -87,7 +87,7 @@ class TestComponentsDeviceTrackerMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
fire_mqtt_message(self.hass, topic, location)
|
fire_mqtt_message(self.hass, topic, location)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(location, self.hass.states.get(entity_id).state)
|
assert location == self.hass.states.get(entity_id).state
|
||||||
|
|
||||||
def test_multi_level_wildcard_topic(self):
|
def test_multi_level_wildcard_topic(self):
|
||||||
"""Test multi level wildcard topic."""
|
"""Test multi level wildcard topic."""
|
||||||
|
@ -106,7 +106,7 @@ class TestComponentsDeviceTrackerMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
fire_mqtt_message(self.hass, topic, location)
|
fire_mqtt_message(self.hass, topic, location)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(location, self.hass.states.get(entity_id).state)
|
assert location == self.hass.states.get(entity_id).state
|
||||||
|
|
||||||
def test_single_level_wildcard_topic_not_matching(self):
|
def test_single_level_wildcard_topic_not_matching(self):
|
||||||
"""Test not matching single level wildcard topic."""
|
"""Test not matching single level wildcard topic."""
|
||||||
|
@ -125,7 +125,7 @@ class TestComponentsDeviceTrackerMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
fire_mqtt_message(self.hass, topic, location)
|
fire_mqtt_message(self.hass, topic, location)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertIsNone(self.hass.states.get(entity_id))
|
assert self.hass.states.get(entity_id) is None
|
||||||
|
|
||||||
def test_multi_level_wildcard_topic_not_matching(self):
|
def test_multi_level_wildcard_topic_not_matching(self):
|
||||||
"""Test not matching multi level wildcard topic."""
|
"""Test not matching multi level wildcard topic."""
|
||||||
|
@ -144,4 +144,4 @@ class TestComponentsDeviceTrackerMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
fire_mqtt_message(self.hass, topic, location)
|
fire_mqtt_message(self.hass, topic, location)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertIsNone(self.hass.states.get(entity_id))
|
assert self.hass.states.get(entity_id) is None
|
||||||
|
|
|
@ -46,7 +46,7 @@ class TestComponentsDeviceTrackerJSONMQTT(unittest.TestCase):
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def mock_setup_scanner(hass, config, see, discovery_info=None):
|
def mock_setup_scanner(hass, config, see, discovery_info=None):
|
||||||
"""Check that Qos was added by validation."""
|
"""Check that Qos was added by validation."""
|
||||||
self.assertTrue('qos' in config)
|
assert 'qos' in config
|
||||||
|
|
||||||
with patch('homeassistant.components.device_tracker.mqtt_json.'
|
with patch('homeassistant.components.device_tracker.mqtt_json.'
|
||||||
'async_setup_scanner', autospec=True,
|
'async_setup_scanner', autospec=True,
|
||||||
|
@ -77,8 +77,8 @@ class TestComponentsDeviceTrackerJSONMQTT(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, topic, location)
|
fire_mqtt_message(self.hass, topic, location)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get('device_tracker.zanzito')
|
state = self.hass.states.get('device_tracker.zanzito')
|
||||||
self.assertEqual(state.attributes.get('latitude'), 2.0)
|
assert state.attributes.get('latitude') == 2.0
|
||||||
self.assertEqual(state.attributes.get('longitude'), 1.0)
|
assert state.attributes.get('longitude') == 1.0
|
||||||
|
|
||||||
def test_non_json_message(self):
|
def test_non_json_message(self):
|
||||||
"""Test receiving a non JSON message."""
|
"""Test receiving a non JSON message."""
|
||||||
|
@ -96,10 +96,9 @@ class TestComponentsDeviceTrackerJSONMQTT(unittest.TestCase):
|
||||||
with self.assertLogs(level='ERROR') as test_handle:
|
with self.assertLogs(level='ERROR') as test_handle:
|
||||||
fire_mqtt_message(self.hass, topic, location)
|
fire_mqtt_message(self.hass, topic, location)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertIn(
|
assert "ERROR:homeassistant.components.device_tracker.mqtt_json:" \
|
||||||
"ERROR:homeassistant.components.device_tracker.mqtt_json:"
|
"Error parsing JSON payload: home" in \
|
||||||
"Error parsing JSON payload: home",
|
test_handle.output[0]
|
||||||
test_handle.output[0])
|
|
||||||
|
|
||||||
def test_incomplete_message(self):
|
def test_incomplete_message(self):
|
||||||
"""Test receiving an incomplete message."""
|
"""Test receiving an incomplete message."""
|
||||||
|
@ -117,11 +116,10 @@ class TestComponentsDeviceTrackerJSONMQTT(unittest.TestCase):
|
||||||
with self.assertLogs(level='ERROR') as test_handle:
|
with self.assertLogs(level='ERROR') as test_handle:
|
||||||
fire_mqtt_message(self.hass, topic, location)
|
fire_mqtt_message(self.hass, topic, location)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertIn(
|
assert "ERROR:homeassistant.components.device_tracker.mqtt_json:" \
|
||||||
"ERROR:homeassistant.components.device_tracker.mqtt_json:"
|
"Skipping update for following data because of missing " \
|
||||||
"Skipping update for following data because of missing "
|
"or malformatted data: {\"longitude\": 2.0}" in \
|
||||||
"or malformatted data: {\"longitude\": 2.0}",
|
test_handle.output[0]
|
||||||
test_handle.output[0])
|
|
||||||
|
|
||||||
def test_single_level_wildcard_topic(self):
|
def test_single_level_wildcard_topic(self):
|
||||||
"""Test single level wildcard topic."""
|
"""Test single level wildcard topic."""
|
||||||
|
@ -139,8 +137,8 @@ class TestComponentsDeviceTrackerJSONMQTT(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, topic, location)
|
fire_mqtt_message(self.hass, topic, location)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get('device_tracker.zanzito')
|
state = self.hass.states.get('device_tracker.zanzito')
|
||||||
self.assertEqual(state.attributes.get('latitude'), 2.0)
|
assert state.attributes.get('latitude') == 2.0
|
||||||
self.assertEqual(state.attributes.get('longitude'), 1.0)
|
assert state.attributes.get('longitude') == 1.0
|
||||||
|
|
||||||
def test_multi_level_wildcard_topic(self):
|
def test_multi_level_wildcard_topic(self):
|
||||||
"""Test multi level wildcard topic."""
|
"""Test multi level wildcard topic."""
|
||||||
|
@ -158,8 +156,8 @@ class TestComponentsDeviceTrackerJSONMQTT(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, topic, location)
|
fire_mqtt_message(self.hass, topic, location)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get('device_tracker.zanzito')
|
state = self.hass.states.get('device_tracker.zanzito')
|
||||||
self.assertEqual(state.attributes.get('latitude'), 2.0)
|
assert state.attributes.get('latitude') == 2.0
|
||||||
self.assertEqual(state.attributes.get('longitude'), 1.0)
|
assert state.attributes.get('longitude') == 1.0
|
||||||
|
|
||||||
def test_single_level_wildcard_topic_not_matching(self):
|
def test_single_level_wildcard_topic_not_matching(self):
|
||||||
"""Test not matching single level wildcard topic."""
|
"""Test not matching single level wildcard topic."""
|
||||||
|
@ -177,7 +175,7 @@ class TestComponentsDeviceTrackerJSONMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
fire_mqtt_message(self.hass, topic, location)
|
fire_mqtt_message(self.hass, topic, location)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertIsNone(self.hass.states.get(entity_id))
|
assert self.hass.states.get(entity_id) is None
|
||||||
|
|
||||||
def test_multi_level_wildcard_topic_not_matching(self):
|
def test_multi_level_wildcard_topic_not_matching(self):
|
||||||
"""Test not matching multi level wildcard topic."""
|
"""Test not matching multi level wildcard topic."""
|
||||||
|
@ -195,4 +193,4 @@ class TestComponentsDeviceTrackerJSONMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
fire_mqtt_message(self.hass, topic, location)
|
fire_mqtt_message(self.hass, topic, location)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertIsNone(self.hass.states.get(entity_id))
|
assert self.hass.states.get(entity_id) is None
|
||||||
|
|
|
@ -299,27 +299,27 @@ class BaseMQTT(unittest.TestCase):
|
||||||
def assert_location_state(self, location):
|
def assert_location_state(self, location):
|
||||||
"""Test the assertion of a location state."""
|
"""Test the assertion of a location state."""
|
||||||
state = self.hass.states.get(DEVICE_TRACKER_STATE)
|
state = self.hass.states.get(DEVICE_TRACKER_STATE)
|
||||||
self.assertEqual(state.state, location)
|
assert state.state == location
|
||||||
|
|
||||||
def assert_location_latitude(self, latitude):
|
def assert_location_latitude(self, latitude):
|
||||||
"""Test the assertion of a location latitude."""
|
"""Test the assertion of a location latitude."""
|
||||||
state = self.hass.states.get(DEVICE_TRACKER_STATE)
|
state = self.hass.states.get(DEVICE_TRACKER_STATE)
|
||||||
self.assertEqual(state.attributes.get('latitude'), latitude)
|
assert state.attributes.get('latitude') == latitude
|
||||||
|
|
||||||
def assert_location_longitude(self, longitude):
|
def assert_location_longitude(self, longitude):
|
||||||
"""Test the assertion of a location longitude."""
|
"""Test the assertion of a location longitude."""
|
||||||
state = self.hass.states.get(DEVICE_TRACKER_STATE)
|
state = self.hass.states.get(DEVICE_TRACKER_STATE)
|
||||||
self.assertEqual(state.attributes.get('longitude'), longitude)
|
assert state.attributes.get('longitude') == longitude
|
||||||
|
|
||||||
def assert_location_accuracy(self, accuracy):
|
def assert_location_accuracy(self, accuracy):
|
||||||
"""Test the assertion of a location accuracy."""
|
"""Test the assertion of a location accuracy."""
|
||||||
state = self.hass.states.get(DEVICE_TRACKER_STATE)
|
state = self.hass.states.get(DEVICE_TRACKER_STATE)
|
||||||
self.assertEqual(state.attributes.get('gps_accuracy'), accuracy)
|
assert state.attributes.get('gps_accuracy') == accuracy
|
||||||
|
|
||||||
def assert_location_source_type(self, source_type):
|
def assert_location_source_type(self, source_type):
|
||||||
"""Test the assertion of source_type."""
|
"""Test the assertion of source_type."""
|
||||||
state = self.hass.states.get(DEVICE_TRACKER_STATE)
|
state = self.hass.states.get(DEVICE_TRACKER_STATE)
|
||||||
self.assertEqual(state.attributes.get('source_type'), source_type)
|
assert state.attributes.get('source_type') == source_type
|
||||||
|
|
||||||
|
|
||||||
class TestDeviceTrackerOwnTracks(BaseMQTT):
|
class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
|
@ -382,19 +382,19 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
"""Test the assertion of a mobile beacon tracker state."""
|
"""Test the assertion of a mobile beacon tracker state."""
|
||||||
dev_id = MOBILE_BEACON_FMT.format(beacon)
|
dev_id = MOBILE_BEACON_FMT.format(beacon)
|
||||||
state = self.hass.states.get(dev_id)
|
state = self.hass.states.get(dev_id)
|
||||||
self.assertEqual(state.state, location)
|
assert state.state == location
|
||||||
|
|
||||||
def assert_mobile_tracker_latitude(self, latitude, beacon=IBEACON_DEVICE):
|
def assert_mobile_tracker_latitude(self, latitude, beacon=IBEACON_DEVICE):
|
||||||
"""Test the assertion of a mobile beacon tracker latitude."""
|
"""Test the assertion of a mobile beacon tracker latitude."""
|
||||||
dev_id = MOBILE_BEACON_FMT.format(beacon)
|
dev_id = MOBILE_BEACON_FMT.format(beacon)
|
||||||
state = self.hass.states.get(dev_id)
|
state = self.hass.states.get(dev_id)
|
||||||
self.assertEqual(state.attributes.get('latitude'), latitude)
|
assert state.attributes.get('latitude') == latitude
|
||||||
|
|
||||||
def assert_mobile_tracker_accuracy(self, accuracy, beacon=IBEACON_DEVICE):
|
def assert_mobile_tracker_accuracy(self, accuracy, beacon=IBEACON_DEVICE):
|
||||||
"""Test the assertion of a mobile beacon tracker accuracy."""
|
"""Test the assertion of a mobile beacon tracker accuracy."""
|
||||||
dev_id = MOBILE_BEACON_FMT.format(beacon)
|
dev_id = MOBILE_BEACON_FMT.format(beacon)
|
||||||
state = self.hass.states.get(dev_id)
|
state = self.hass.states.get(dev_id)
|
||||||
self.assertEqual(state.attributes.get('gps_accuracy'), accuracy)
|
assert state.attributes.get('gps_accuracy') == accuracy
|
||||||
|
|
||||||
def test_location_invalid_devid(self): # pylint: disable=invalid-name
|
def test_location_invalid_devid(self): # pylint: disable=invalid-name
|
||||||
"""Test the update of a location."""
|
"""Test the update of a location."""
|
||||||
|
@ -460,7 +460,7 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
self.assert_location_state('outer')
|
self.assert_location_state('outer')
|
||||||
|
|
||||||
# Left clean zone state
|
# Left clean zone state
|
||||||
self.assertFalse(self.context.regions_entered[USER])
|
assert not self.context.regions_entered[USER]
|
||||||
|
|
||||||
self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE)
|
self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE)
|
||||||
|
|
||||||
|
@ -480,7 +480,7 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
self.send_message(EVENT_TOPIC, message)
|
self.send_message(EVENT_TOPIC, message)
|
||||||
|
|
||||||
# Left clean zone state
|
# Left clean zone state
|
||||||
self.assertFalse(self.context.regions_entered[USER])
|
assert not self.context.regions_entered[USER]
|
||||||
|
|
||||||
def test_event_gps_entry_inaccurate(self):
|
def test_event_gps_entry_inaccurate(self):
|
||||||
"""Test the event for inaccurate entry."""
|
"""Test the event for inaccurate entry."""
|
||||||
|
@ -511,7 +511,7 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
self.assert_location_state('inner')
|
self.assert_location_state('inner')
|
||||||
|
|
||||||
# But does exit region correctly
|
# But does exit region correctly
|
||||||
self.assertFalse(self.context.regions_entered[USER])
|
assert not self.context.regions_entered[USER]
|
||||||
|
|
||||||
def test_event_gps_entry_exit_zero_accuracy(self):
|
def test_event_gps_entry_exit_zero_accuracy(self):
|
||||||
"""Test entry/exit events with accuracy zero."""
|
"""Test entry/exit events with accuracy zero."""
|
||||||
|
@ -530,7 +530,7 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
self.assert_location_state('inner')
|
self.assert_location_state('inner')
|
||||||
|
|
||||||
# But does exit region correctly
|
# But does exit region correctly
|
||||||
self.assertFalse(self.context.regions_entered[USER])
|
assert not self.context.regions_entered[USER]
|
||||||
|
|
||||||
def test_event_gps_exit_outside_zone_sets_away(self):
|
def test_event_gps_exit_outside_zone_sets_away(self):
|
||||||
"""Test the event for exit zone."""
|
"""Test the event for exit zone."""
|
||||||
|
@ -730,7 +730,7 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
self.assert_location_state('inner')
|
self.assert_location_state('inner')
|
||||||
|
|
||||||
# Left clean zone state
|
# Left clean zone state
|
||||||
self.assertFalse(self.context.regions_entered[USER])
|
assert not self.context.regions_entered[USER]
|
||||||
|
|
||||||
# Now sending a location update moves me again.
|
# Now sending a location update moves me again.
|
||||||
self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE)
|
self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE)
|
||||||
|
@ -749,7 +749,7 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
self.send_message(EVENT_TOPIC, message)
|
self.send_message(EVENT_TOPIC, message)
|
||||||
|
|
||||||
# Left clean zone state
|
# Left clean zone state
|
||||||
self.assertFalse(self.context.regions_entered[USER])
|
assert not self.context.regions_entered[USER]
|
||||||
|
|
||||||
def test_event_region_entry_exit_right_order(self):
|
def test_event_region_entry_exit_right_order(self):
|
||||||
"""Test the event for ordering."""
|
"""Test the event for ordering."""
|
||||||
|
@ -959,8 +959,8 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.send_message(EVENT_TOPIC, MOBILE_BEACON_LEAVE_EVENT_MESSAGE)
|
self.send_message(EVENT_TOPIC, MOBILE_BEACON_LEAVE_EVENT_MESSAGE)
|
||||||
self.assertEqual(len(self.context.mobile_beacons_active['greg_phone']),
|
assert len(self.context.mobile_beacons_active['greg_phone']) == \
|
||||||
0)
|
0
|
||||||
|
|
||||||
def test_mobile_multiple_enter_exit(self):
|
def test_mobile_multiple_enter_exit(self):
|
||||||
"""Test the multiple entering."""
|
"""Test the multiple entering."""
|
||||||
|
@ -968,8 +968,8 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
self.send_message(EVENT_TOPIC, MOBILE_BEACON_ENTER_EVENT_MESSAGE)
|
self.send_message(EVENT_TOPIC, MOBILE_BEACON_ENTER_EVENT_MESSAGE)
|
||||||
self.send_message(EVENT_TOPIC, MOBILE_BEACON_LEAVE_EVENT_MESSAGE)
|
self.send_message(EVENT_TOPIC, MOBILE_BEACON_LEAVE_EVENT_MESSAGE)
|
||||||
|
|
||||||
self.assertEqual(len(self.context.mobile_beacons_active['greg_phone']),
|
assert len(self.context.mobile_beacons_active['greg_phone']) == \
|
||||||
0)
|
0
|
||||||
|
|
||||||
def test_complex_movement(self):
|
def test_complex_movement(self):
|
||||||
"""Test a complex sequence representative of real-world use."""
|
"""Test a complex sequence representative of real-world use."""
|
||||||
|
@ -1168,9 +1168,9 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
self.send_message(WAYPOINTS_TOPIC, waypoints_message)
|
self.send_message(WAYPOINTS_TOPIC, waypoints_message)
|
||||||
# Check if it made it into states
|
# Check if it made it into states
|
||||||
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[0])
|
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[0])
|
||||||
self.assertTrue(wayp is not None)
|
assert wayp is not None
|
||||||
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[1])
|
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[1])
|
||||||
self.assertTrue(wayp is not None)
|
assert wayp is not None
|
||||||
|
|
||||||
def test_waypoint_import_blacklist(self):
|
def test_waypoint_import_blacklist(self):
|
||||||
"""Test import of list of waypoints for blacklisted user."""
|
"""Test import of list of waypoints for blacklisted user."""
|
||||||
|
@ -1178,9 +1178,9 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
self.send_message(WAYPOINTS_TOPIC_BLOCKED, waypoints_message)
|
self.send_message(WAYPOINTS_TOPIC_BLOCKED, waypoints_message)
|
||||||
# Check if it made it into states
|
# Check if it made it into states
|
||||||
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[2])
|
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[2])
|
||||||
self.assertTrue(wayp is None)
|
assert wayp is None
|
||||||
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[3])
|
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[3])
|
||||||
self.assertTrue(wayp is None)
|
assert wayp is None
|
||||||
|
|
||||||
def test_waypoint_import_no_whitelist(self):
|
def test_waypoint_import_no_whitelist(self):
|
||||||
"""Test import of list of waypoints with no whitelist set."""
|
"""Test import of list of waypoints with no whitelist set."""
|
||||||
|
@ -1201,9 +1201,9 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
self.send_message(WAYPOINTS_TOPIC_BLOCKED, waypoints_message)
|
self.send_message(WAYPOINTS_TOPIC_BLOCKED, waypoints_message)
|
||||||
# Check if it made it into states
|
# Check if it made it into states
|
||||||
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[2])
|
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[2])
|
||||||
self.assertTrue(wayp is not None)
|
assert wayp is not None
|
||||||
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[3])
|
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[3])
|
||||||
self.assertTrue(wayp is not None)
|
assert wayp is not None
|
||||||
|
|
||||||
def test_waypoint_import_bad_json(self):
|
def test_waypoint_import_bad_json(self):
|
||||||
"""Test importing a bad JSON payload."""
|
"""Test importing a bad JSON payload."""
|
||||||
|
@ -1211,9 +1211,9 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
self.send_message(WAYPOINTS_TOPIC, waypoints_message, True)
|
self.send_message(WAYPOINTS_TOPIC, waypoints_message, True)
|
||||||
# Check if it made it into states
|
# Check if it made it into states
|
||||||
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[2])
|
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[2])
|
||||||
self.assertTrue(wayp is None)
|
assert wayp is None
|
||||||
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[3])
|
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[3])
|
||||||
self.assertTrue(wayp is None)
|
assert wayp is None
|
||||||
|
|
||||||
def test_waypoint_import_existing(self):
|
def test_waypoint_import_existing(self):
|
||||||
"""Test importing a zone that exists."""
|
"""Test importing a zone that exists."""
|
||||||
|
@ -1225,14 +1225,14 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
waypoints_message = WAYPOINTS_UPDATED_MESSAGE.copy()
|
waypoints_message = WAYPOINTS_UPDATED_MESSAGE.copy()
|
||||||
self.send_message(WAYPOINTS_TOPIC, waypoints_message)
|
self.send_message(WAYPOINTS_TOPIC, waypoints_message)
|
||||||
new_wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[0])
|
new_wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[0])
|
||||||
self.assertTrue(wayp == new_wayp)
|
assert wayp == new_wayp
|
||||||
|
|
||||||
def test_single_waypoint_import(self):
|
def test_single_waypoint_import(self):
|
||||||
"""Test single waypoint message."""
|
"""Test single waypoint message."""
|
||||||
waypoint_message = WAYPOINT_MESSAGE.copy()
|
waypoint_message = WAYPOINT_MESSAGE.copy()
|
||||||
self.send_message(WAYPOINT_TOPIC, waypoint_message)
|
self.send_message(WAYPOINT_TOPIC, waypoint_message)
|
||||||
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[0])
|
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[0])
|
||||||
self.assertTrue(wayp is not None)
|
assert wayp is not None
|
||||||
|
|
||||||
def test_not_implemented_message(self):
|
def test_not_implemented_message(self):
|
||||||
"""Handle not implemented message type."""
|
"""Handle not implemented message type."""
|
||||||
|
@ -1240,7 +1240,7 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
'owntracks.async_handle_not_impl_msg',
|
'owntracks.async_handle_not_impl_msg',
|
||||||
return_value=mock_coro(False))
|
return_value=mock_coro(False))
|
||||||
patch_handler.start()
|
patch_handler.start()
|
||||||
self.assertFalse(self.send_message(LWT_TOPIC, LWT_MESSAGE))
|
assert not self.send_message(LWT_TOPIC, LWT_MESSAGE)
|
||||||
patch_handler.stop()
|
patch_handler.stop()
|
||||||
|
|
||||||
def test_unsupported_message(self):
|
def test_unsupported_message(self):
|
||||||
|
@ -1249,7 +1249,7 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||||
'owntracks.async_handle_unsupported_msg',
|
'owntracks.async_handle_unsupported_msg',
|
||||||
return_value=mock_coro(False))
|
return_value=mock_coro(False))
|
||||||
patch_handler.start()
|
patch_handler.start()
|
||||||
self.assertFalse(self.send_message(BAD_TOPIC, BAD_MESSAGE))
|
assert not self.send_message(BAD_TOPIC, BAD_MESSAGE)
|
||||||
patch_handler.stop()
|
patch_handler.stop()
|
||||||
|
|
||||||
|
|
||||||
|
@ -1465,7 +1465,7 @@ class TestDeviceTrackerOwnTrackConfigs(BaseMQTT):
|
||||||
'zone.inner', 'zoning', INNER_ZONE)
|
'zone.inner', 'zoning', INNER_ZONE)
|
||||||
|
|
||||||
message = build_message({'desc': 'foo'}, REGION_GPS_ENTER_MESSAGE)
|
message = build_message({'desc': 'foo'}, REGION_GPS_ENTER_MESSAGE)
|
||||||
self.assertEqual(message['desc'], 'foo')
|
assert message['desc'] == 'foo'
|
||||||
|
|
||||||
self.send_message(EVENT_TOPIC, message)
|
self.send_message(EVENT_TOPIC, message)
|
||||||
self.assert_location_state('inner')
|
self.assert_location_state('inner')
|
||||||
|
|
|
@ -40,8 +40,7 @@ class TestTplink4DeviceScanner(unittest.TestCase):
|
||||||
# Mock the token retrieval process
|
# Mock the token retrieval process
|
||||||
FAKE_TOKEN = 'fake_token'
|
FAKE_TOKEN = 'fake_token'
|
||||||
fake_auth_token_response = 'window.parent.location.href = ' \
|
fake_auth_token_response = 'window.parent.location.href = ' \
|
||||||
'"https://a/{}/userRpm/Index.htm";'.format(
|
'"https://a/{}/userRpm/Index.htm";'.format(FAKE_TOKEN)
|
||||||
FAKE_TOKEN)
|
|
||||||
|
|
||||||
m.get('http://{}/userRpm/LoginRpm.htm?Save=Save'.format(
|
m.get('http://{}/userRpm/LoginRpm.htm?Save=Save'.format(
|
||||||
conf_dict[CONF_HOST]), text=fake_auth_token_response)
|
conf_dict[CONF_HOST]), text=fake_auth_token_response)
|
||||||
|
@ -65,4 +64,4 @@ class TestTplink4DeviceScanner(unittest.TestCase):
|
||||||
expected_mac_results = [mac.replace('-', ':') for mac in
|
expected_mac_results = [mac.replace('-', ':') for mac in
|
||||||
[FAKE_MAC_1, FAKE_MAC_2, FAKE_MAC_3]]
|
[FAKE_MAC_1, FAKE_MAC_2, FAKE_MAC_3]]
|
||||||
|
|
||||||
self.assertEqual(tplink.last_results, expected_mac_results)
|
assert tplink.last_results == expected_mac_results
|
||||||
|
|
|
@ -66,7 +66,7 @@ class TestComponentsDeviceTrackerUnifiDirect(unittest.TestCase):
|
||||||
assert setup_component(self.hass, DOMAIN, conf_dict)
|
assert setup_component(self.hass, DOMAIN, conf_dict)
|
||||||
|
|
||||||
conf_dict[DOMAIN][CONF_PORT] = 22
|
conf_dict[DOMAIN][CONF_PORT] = 22
|
||||||
self.assertEqual(unifi_mock.call_args, mock.call(conf_dict[DOMAIN]))
|
assert unifi_mock.call_args == mock.call(conf_dict[DOMAIN])
|
||||||
|
|
||||||
@patch('pexpect.pxssh.pxssh')
|
@patch('pexpect.pxssh.pxssh')
|
||||||
def test_get_device_name(self, mock_ssh):
|
def test_get_device_name(self, mock_ssh):
|
||||||
|
@ -85,11 +85,11 @@ class TestComponentsDeviceTrackerUnifiDirect(unittest.TestCase):
|
||||||
mock_ssh.return_value.before = load_fixture('unifi_direct.txt')
|
mock_ssh.return_value.before = load_fixture('unifi_direct.txt')
|
||||||
scanner = get_scanner(self.hass, conf_dict)
|
scanner = get_scanner(self.hass, conf_dict)
|
||||||
devices = scanner.scan_devices()
|
devices = scanner.scan_devices()
|
||||||
self.assertEqual(23, len(devices))
|
assert 23 == len(devices)
|
||||||
self.assertEqual("iPhone",
|
assert "iPhone" == \
|
||||||
scanner.get_device_name("98:00:c6:56:34:12"))
|
scanner.get_device_name("98:00:c6:56:34:12")
|
||||||
self.assertEqual("iPhone",
|
assert "iPhone" == \
|
||||||
scanner.get_device_name("98:00:C6:56:34:12"))
|
scanner.get_device_name("98:00:C6:56:34:12")
|
||||||
|
|
||||||
@patch('pexpect.pxssh.pxssh.logout')
|
@patch('pexpect.pxssh.pxssh.logout')
|
||||||
@patch('pexpect.pxssh.pxssh.login')
|
@patch('pexpect.pxssh.pxssh.login')
|
||||||
|
@ -111,7 +111,7 @@ class TestComponentsDeviceTrackerUnifiDirect(unittest.TestCase):
|
||||||
|
|
||||||
mock_login.side_effect = exceptions.EOF("Test")
|
mock_login.side_effect = exceptions.EOF("Test")
|
||||||
scanner = get_scanner(self.hass, conf_dict)
|
scanner = get_scanner(self.hass, conf_dict)
|
||||||
self.assertFalse(scanner)
|
assert not scanner
|
||||||
|
|
||||||
@patch('pexpect.pxssh.pxssh.logout')
|
@patch('pexpect.pxssh.pxssh.logout')
|
||||||
@patch('pexpect.pxssh.pxssh.login', autospec=True)
|
@patch('pexpect.pxssh.pxssh.login', autospec=True)
|
||||||
|
@ -136,16 +136,16 @@ class TestComponentsDeviceTrackerUnifiDirect(unittest.TestCase):
|
||||||
# mock_sendline.side_effect = AssertionError("Test")
|
# mock_sendline.side_effect = AssertionError("Test")
|
||||||
mock_prompt.side_effect = AssertionError("Test")
|
mock_prompt.side_effect = AssertionError("Test")
|
||||||
devices = scanner._get_update() # pylint: disable=protected-access
|
devices = scanner._get_update() # pylint: disable=protected-access
|
||||||
self.assertTrue(devices is None)
|
assert devices is None
|
||||||
|
|
||||||
def test_good_response_parses(self):
|
def test_good_response_parses(self):
|
||||||
"""Test that the response form the AP parses to JSON correctly."""
|
"""Test that the response form the AP parses to JSON correctly."""
|
||||||
response = _response_to_json(load_fixture('unifi_direct.txt'))
|
response = _response_to_json(load_fixture('unifi_direct.txt'))
|
||||||
self.assertTrue(response != {})
|
assert response != {}
|
||||||
|
|
||||||
def test_bad_response_returns_none(self):
|
def test_bad_response_returns_none(self):
|
||||||
"""Test that a bad response form the AP parses to JSON correctly."""
|
"""Test that a bad response form the AP parses to JSON correctly."""
|
||||||
self.assertTrue(_response_to_json("{(}") == {})
|
assert _response_to_json("{(}") == {}
|
||||||
|
|
||||||
|
|
||||||
def test_config_error():
|
def test_config_error():
|
||||||
|
|
|
@ -176,13 +176,13 @@ class TestXiaomiDeviceScanner(unittest.TestCase):
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
xiaomi.get_scanner(self.hass, config)
|
xiaomi.get_scanner(self.hass, config)
|
||||||
self.assertEqual(xiaomi_mock.call_count, 1)
|
assert xiaomi_mock.call_count == 1
|
||||||
self.assertEqual(xiaomi_mock.call_args, mock.call(config[DOMAIN]))
|
assert xiaomi_mock.call_args == mock.call(config[DOMAIN])
|
||||||
call_arg = xiaomi_mock.call_args[0][0]
|
call_arg = xiaomi_mock.call_args[0][0]
|
||||||
self.assertEqual(call_arg['username'], 'admin')
|
assert call_arg['username'] == 'admin'
|
||||||
self.assertEqual(call_arg['password'], 'passwordTest')
|
assert call_arg['password'] == 'passwordTest'
|
||||||
self.assertEqual(call_arg['host'], '192.168.0.1')
|
assert call_arg['host'] == '192.168.0.1'
|
||||||
self.assertEqual(call_arg['platform'], 'device_tracker')
|
assert call_arg['platform'] == 'device_tracker'
|
||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
'homeassistant.components.device_tracker.xiaomi.XiaomiDeviceScanner',
|
'homeassistant.components.device_tracker.xiaomi.XiaomiDeviceScanner',
|
||||||
|
@ -198,13 +198,13 @@ class TestXiaomiDeviceScanner(unittest.TestCase):
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
xiaomi.get_scanner(self.hass, config)
|
xiaomi.get_scanner(self.hass, config)
|
||||||
self.assertEqual(xiaomi_mock.call_count, 1)
|
assert xiaomi_mock.call_count == 1
|
||||||
self.assertEqual(xiaomi_mock.call_args, mock.call(config[DOMAIN]))
|
assert xiaomi_mock.call_args == mock.call(config[DOMAIN])
|
||||||
call_arg = xiaomi_mock.call_args[0][0]
|
call_arg = xiaomi_mock.call_args[0][0]
|
||||||
self.assertEqual(call_arg['username'], 'alternativeAdminName')
|
assert call_arg['username'] == 'alternativeAdminName'
|
||||||
self.assertEqual(call_arg['password'], 'passwordTest')
|
assert call_arg['password'] == 'passwordTest'
|
||||||
self.assertEqual(call_arg['host'], '192.168.0.1')
|
assert call_arg['host'] == '192.168.0.1'
|
||||||
self.assertEqual(call_arg['platform'], 'device_tracker')
|
assert call_arg['platform'] == 'device_tracker'
|
||||||
|
|
||||||
@patch('requests.get', side_effect=mocked_requests)
|
@patch('requests.get', side_effect=mocked_requests)
|
||||||
@patch('requests.post', side_effect=mocked_requests)
|
@patch('requests.post', side_effect=mocked_requests)
|
||||||
|
@ -218,7 +218,7 @@ class TestXiaomiDeviceScanner(unittest.TestCase):
|
||||||
CONF_PASSWORD: 'passwordTest'
|
CONF_PASSWORD: 'passwordTest'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
self.assertIsNone(get_scanner(self.hass, config))
|
assert get_scanner(self.hass, config) is None
|
||||||
|
|
||||||
@patch('requests.get', side_effect=mocked_requests)
|
@patch('requests.get', side_effect=mocked_requests)
|
||||||
@patch('requests.post', side_effect=mocked_requests)
|
@patch('requests.post', side_effect=mocked_requests)
|
||||||
|
@ -233,12 +233,12 @@ class TestXiaomiDeviceScanner(unittest.TestCase):
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
scanner = get_scanner(self.hass, config)
|
scanner = get_scanner(self.hass, config)
|
||||||
self.assertIsNotNone(scanner)
|
assert scanner is not None
|
||||||
self.assertEqual(2, len(scanner.scan_devices()))
|
assert 2 == len(scanner.scan_devices())
|
||||||
self.assertEqual("Device1",
|
assert "Device1" == \
|
||||||
scanner.get_device_name("23:83:BF:F6:38:A0"))
|
scanner.get_device_name("23:83:BF:F6:38:A0")
|
||||||
self.assertEqual("Device2",
|
assert "Device2" == \
|
||||||
scanner.get_device_name("1D:98:EC:5E:D5:A6"))
|
scanner.get_device_name("1D:98:EC:5E:D5:A6")
|
||||||
|
|
||||||
@patch('requests.get', side_effect=mocked_requests)
|
@patch('requests.get', side_effect=mocked_requests)
|
||||||
@patch('requests.post', side_effect=mocked_requests)
|
@patch('requests.post', side_effect=mocked_requests)
|
||||||
|
@ -256,9 +256,9 @@ class TestXiaomiDeviceScanner(unittest.TestCase):
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
scanner = get_scanner(self.hass, config)
|
scanner = get_scanner(self.hass, config)
|
||||||
self.assertIsNotNone(scanner)
|
assert scanner is not None
|
||||||
self.assertEqual(2, len(scanner.scan_devices()))
|
assert 2 == len(scanner.scan_devices())
|
||||||
self.assertEqual("Device1",
|
assert "Device1" == \
|
||||||
scanner.get_device_name("23:83:BF:F6:38:A0"))
|
scanner.get_device_name("23:83:BF:F6:38:A0")
|
||||||
self.assertEqual("Device2",
|
assert "Device2" == \
|
||||||
scanner.get_device_name("1D:98:EC:5E:D5:A6"))
|
scanner.get_device_name("1D:98:EC:5E:D5:A6")
|
||||||
|
|
|
@ -83,8 +83,8 @@ class TestEmulatedHue(unittest.TestCase):
|
||||||
result = requests.get(
|
result = requests.get(
|
||||||
BRIDGE_URL_BASE.format('/description.xml'), timeout=5)
|
BRIDGE_URL_BASE.format('/description.xml'), timeout=5)
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 200)
|
assert result.status_code == 200
|
||||||
self.assertTrue('text/xml' in result.headers['content-type'])
|
assert 'text/xml' in result.headers['content-type']
|
||||||
|
|
||||||
# Make sure the XML is parsable
|
# Make sure the XML is parsable
|
||||||
try:
|
try:
|
||||||
|
@ -100,14 +100,14 @@ class TestEmulatedHue(unittest.TestCase):
|
||||||
BRIDGE_URL_BASE.format('/api'), data=json.dumps(request_json),
|
BRIDGE_URL_BASE.format('/api'), data=json.dumps(request_json),
|
||||||
timeout=5)
|
timeout=5)
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 200)
|
assert result.status_code == 200
|
||||||
self.assertTrue('application/json' in result.headers['content-type'])
|
assert 'application/json' in result.headers['content-type']
|
||||||
|
|
||||||
resp_json = result.json()
|
resp_json = result.json()
|
||||||
success_json = resp_json[0]
|
success_json = resp_json[0]
|
||||||
|
|
||||||
self.assertTrue('success' in success_json)
|
assert 'success' in success_json
|
||||||
self.assertTrue('username' in success_json['success'])
|
assert 'username' in success_json['success']
|
||||||
|
|
||||||
def test_valid_username_request(self):
|
def test_valid_username_request(self):
|
||||||
"""Test request with a valid username."""
|
"""Test request with a valid username."""
|
||||||
|
@ -117,4 +117,4 @@ class TestEmulatedHue(unittest.TestCase):
|
||||||
BRIDGE_URL_BASE.format('/api'), data=json.dumps(request_json),
|
BRIDGE_URL_BASE.format('/api'), data=json.dumps(request_json),
|
||||||
timeout=5)
|
timeout=5)
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 400)
|
assert result.status_code == 400
|
||||||
|
|
|
@ -22,9 +22,9 @@ class TestDemoFan(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Initialize unit test data."""
|
"""Initialize unit test data."""
|
||||||
self.hass = get_test_home_assistant()
|
self.hass = get_test_home_assistant()
|
||||||
self.assertTrue(setup_component(self.hass, fan.DOMAIN, {'fan': {
|
assert setup_component(self.hass, fan.DOMAIN, {'fan': {
|
||||||
'platform': 'demo',
|
'platform': 'demo',
|
||||||
}}))
|
}})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
@ -33,76 +33,76 @@ class TestDemoFan(unittest.TestCase):
|
||||||
|
|
||||||
def test_turn_on(self):
|
def test_turn_on(self):
|
||||||
"""Test turning on the device."""
|
"""Test turning on the device."""
|
||||||
self.assertEqual(STATE_OFF, self.get_entity().state)
|
assert STATE_OFF == self.get_entity().state
|
||||||
|
|
||||||
common.turn_on(self.hass, FAN_ENTITY_ID)
|
common.turn_on(self.hass, FAN_ENTITY_ID)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertNotEqual(STATE_OFF, self.get_entity().state)
|
assert STATE_OFF != self.get_entity().state
|
||||||
|
|
||||||
common.turn_on(self.hass, FAN_ENTITY_ID, fan.SPEED_HIGH)
|
common.turn_on(self.hass, FAN_ENTITY_ID, fan.SPEED_HIGH)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(STATE_ON, self.get_entity().state)
|
assert STATE_ON == self.get_entity().state
|
||||||
self.assertEqual(fan.SPEED_HIGH,
|
assert fan.SPEED_HIGH == \
|
||||||
self.get_entity().attributes[fan.ATTR_SPEED])
|
self.get_entity().attributes[fan.ATTR_SPEED]
|
||||||
|
|
||||||
def test_turn_off(self):
|
def test_turn_off(self):
|
||||||
"""Test turning off the device."""
|
"""Test turning off the device."""
|
||||||
self.assertEqual(STATE_OFF, self.get_entity().state)
|
assert STATE_OFF == self.get_entity().state
|
||||||
|
|
||||||
common.turn_on(self.hass, FAN_ENTITY_ID)
|
common.turn_on(self.hass, FAN_ENTITY_ID)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertNotEqual(STATE_OFF, self.get_entity().state)
|
assert STATE_OFF != self.get_entity().state
|
||||||
|
|
||||||
common.turn_off(self.hass, FAN_ENTITY_ID)
|
common.turn_off(self.hass, FAN_ENTITY_ID)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(STATE_OFF, self.get_entity().state)
|
assert STATE_OFF == self.get_entity().state
|
||||||
|
|
||||||
def test_turn_off_without_entity_id(self):
|
def test_turn_off_without_entity_id(self):
|
||||||
"""Test turning off all fans."""
|
"""Test turning off all fans."""
|
||||||
self.assertEqual(STATE_OFF, self.get_entity().state)
|
assert STATE_OFF == self.get_entity().state
|
||||||
|
|
||||||
common.turn_on(self.hass, FAN_ENTITY_ID)
|
common.turn_on(self.hass, FAN_ENTITY_ID)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertNotEqual(STATE_OFF, self.get_entity().state)
|
assert STATE_OFF != self.get_entity().state
|
||||||
|
|
||||||
common.turn_off(self.hass)
|
common.turn_off(self.hass)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(STATE_OFF, self.get_entity().state)
|
assert STATE_OFF == self.get_entity().state
|
||||||
|
|
||||||
def test_set_direction(self):
|
def test_set_direction(self):
|
||||||
"""Test setting the direction of the device."""
|
"""Test setting the direction of the device."""
|
||||||
self.assertEqual(STATE_OFF, self.get_entity().state)
|
assert STATE_OFF == self.get_entity().state
|
||||||
|
|
||||||
common.set_direction(self.hass, FAN_ENTITY_ID, fan.DIRECTION_REVERSE)
|
common.set_direction(self.hass, FAN_ENTITY_ID, fan.DIRECTION_REVERSE)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(fan.DIRECTION_REVERSE,
|
assert fan.DIRECTION_REVERSE == \
|
||||||
self.get_entity().attributes.get('direction'))
|
self.get_entity().attributes.get('direction')
|
||||||
|
|
||||||
def test_set_speed(self):
|
def test_set_speed(self):
|
||||||
"""Test setting the speed of the device."""
|
"""Test setting the speed of the device."""
|
||||||
self.assertEqual(STATE_OFF, self.get_entity().state)
|
assert STATE_OFF == self.get_entity().state
|
||||||
|
|
||||||
common.set_speed(self.hass, FAN_ENTITY_ID, fan.SPEED_LOW)
|
common.set_speed(self.hass, FAN_ENTITY_ID, fan.SPEED_LOW)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(fan.SPEED_LOW,
|
assert fan.SPEED_LOW == \
|
||||||
self.get_entity().attributes.get('speed'))
|
self.get_entity().attributes.get('speed')
|
||||||
|
|
||||||
def test_oscillate(self):
|
def test_oscillate(self):
|
||||||
"""Test oscillating the fan."""
|
"""Test oscillating the fan."""
|
||||||
self.assertFalse(self.get_entity().attributes.get('oscillating'))
|
assert not self.get_entity().attributes.get('oscillating')
|
||||||
|
|
||||||
common.oscillate(self.hass, FAN_ENTITY_ID, True)
|
common.oscillate(self.hass, FAN_ENTITY_ID, True)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(self.get_entity().attributes.get('oscillating'))
|
assert self.get_entity().attributes.get('oscillating')
|
||||||
|
|
||||||
common.oscillate(self.hass, FAN_ENTITY_ID, False)
|
common.oscillate(self.hass, FAN_ENTITY_ID, False)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertFalse(self.get_entity().attributes.get('oscillating'))
|
assert not self.get_entity().attributes.get('oscillating')
|
||||||
|
|
||||||
def test_is_on(self):
|
def test_is_on(self):
|
||||||
"""Test is on service call."""
|
"""Test is on service call."""
|
||||||
self.assertFalse(fan.is_on(self.hass, FAN_ENTITY_ID))
|
assert not fan.is_on(self.hass, FAN_ENTITY_ID)
|
||||||
|
|
||||||
common.turn_on(self.hass, FAN_ENTITY_ID)
|
common.turn_on(self.hass, FAN_ENTITY_ID)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(fan.is_on(self.hass, FAN_ENTITY_ID))
|
assert fan.is_on(self.hass, FAN_ENTITY_ID)
|
||||||
|
|
|
@ -130,14 +130,14 @@ class DysonTest(unittest.TestCase):
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(len(self.hass.data[dyson.DYSON_DEVICES]), 1)
|
assert len(self.hass.data[dyson.DYSON_DEVICES]) == 1
|
||||||
assert mocked_devices.return_value[0].add_message_listener.called
|
assert mocked_devices.return_value[0].add_message_listener.called
|
||||||
|
|
||||||
def test_dyson_set_speed(self):
|
def test_dyson_set_speed(self):
|
||||||
"""Test set fan speed."""
|
"""Test set fan speed."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertFalse(component.should_poll)
|
assert not component.should_poll
|
||||||
component.set_speed("1")
|
component.set_speed("1")
|
||||||
set_config = device.set_configuration
|
set_config = device.set_configuration
|
||||||
set_config.assert_called_with(fan_mode=FanMode.FAN,
|
set_config.assert_called_with(fan_mode=FanMode.FAN,
|
||||||
|
@ -151,7 +151,7 @@ class DysonTest(unittest.TestCase):
|
||||||
"""Test turn on fan."""
|
"""Test turn on fan."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertFalse(component.should_poll)
|
assert not component.should_poll
|
||||||
component.turn_on()
|
component.turn_on()
|
||||||
set_config = device.set_configuration
|
set_config = device.set_configuration
|
||||||
set_config.assert_called_with(fan_mode=FanMode.FAN)
|
set_config.assert_called_with(fan_mode=FanMode.FAN)
|
||||||
|
@ -160,7 +160,7 @@ class DysonTest(unittest.TestCase):
|
||||||
"""Test turn on fan with night mode."""
|
"""Test turn on fan with night mode."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertFalse(component.should_poll)
|
assert not component.should_poll
|
||||||
component.night_mode(True)
|
component.night_mode(True)
|
||||||
set_config = device.set_configuration
|
set_config = device.set_configuration
|
||||||
set_config.assert_called_with(night_mode=NightMode.NIGHT_MODE_ON)
|
set_config.assert_called_with(night_mode=NightMode.NIGHT_MODE_ON)
|
||||||
|
@ -173,17 +173,17 @@ class DysonTest(unittest.TestCase):
|
||||||
"""Test night mode."""
|
"""Test night mode."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertFalse(component.is_night_mode)
|
assert not component.is_night_mode
|
||||||
|
|
||||||
device = _get_device_off()
|
device = _get_device_off()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertTrue(component.is_night_mode)
|
assert component.is_night_mode
|
||||||
|
|
||||||
def test_dyson_turn_auto_mode(self):
|
def test_dyson_turn_auto_mode(self):
|
||||||
"""Test turn on/off fan with auto mode."""
|
"""Test turn on/off fan with auto mode."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertFalse(component.should_poll)
|
assert not component.should_poll
|
||||||
component.auto_mode(True)
|
component.auto_mode(True)
|
||||||
set_config = device.set_configuration
|
set_config = device.set_configuration
|
||||||
set_config.assert_called_with(fan_mode=FanMode.AUTO)
|
set_config.assert_called_with(fan_mode=FanMode.AUTO)
|
||||||
|
@ -196,17 +196,17 @@ class DysonTest(unittest.TestCase):
|
||||||
"""Test auto mode."""
|
"""Test auto mode."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertFalse(component.is_auto_mode)
|
assert not component.is_auto_mode
|
||||||
|
|
||||||
device = _get_device_auto()
|
device = _get_device_auto()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertTrue(component.is_auto_mode)
|
assert component.is_auto_mode
|
||||||
|
|
||||||
def test_dyson_turn_on_speed(self):
|
def test_dyson_turn_on_speed(self):
|
||||||
"""Test turn on fan with specified speed."""
|
"""Test turn on fan with specified speed."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertFalse(component.should_poll)
|
assert not component.should_poll
|
||||||
component.turn_on("1")
|
component.turn_on("1")
|
||||||
set_config = device.set_configuration
|
set_config = device.set_configuration
|
||||||
set_config.assert_called_with(fan_mode=FanMode.FAN,
|
set_config.assert_called_with(fan_mode=FanMode.FAN,
|
||||||
|
@ -220,7 +220,7 @@ class DysonTest(unittest.TestCase):
|
||||||
"""Test turn off fan."""
|
"""Test turn off fan."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertFalse(component.should_poll)
|
assert not component.should_poll
|
||||||
component.turn_off()
|
component.turn_off()
|
||||||
set_config = device.set_configuration
|
set_config = device.set_configuration
|
||||||
set_config.assert_called_with(fan_mode=FanMode.OFF)
|
set_config.assert_called_with(fan_mode=FanMode.OFF)
|
||||||
|
@ -245,65 +245,65 @@ class DysonTest(unittest.TestCase):
|
||||||
"""Test get oscillation value on."""
|
"""Test get oscillation value on."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertTrue(component.oscillating)
|
assert component.oscillating
|
||||||
|
|
||||||
def test_dyson_oscillate_value_off(self):
|
def test_dyson_oscillate_value_off(self):
|
||||||
"""Test get oscillation value off."""
|
"""Test get oscillation value off."""
|
||||||
device = _get_device_off()
|
device = _get_device_off()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertFalse(component.oscillating)
|
assert not component.oscillating
|
||||||
|
|
||||||
def test_dyson_on(self):
|
def test_dyson_on(self):
|
||||||
"""Test device is on."""
|
"""Test device is on."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertTrue(component.is_on)
|
assert component.is_on
|
||||||
|
|
||||||
def test_dyson_off(self):
|
def test_dyson_off(self):
|
||||||
"""Test device is off."""
|
"""Test device is off."""
|
||||||
device = _get_device_off()
|
device = _get_device_off()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertFalse(component.is_on)
|
assert not component.is_on
|
||||||
|
|
||||||
device = _get_device_with_no_state()
|
device = _get_device_with_no_state()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertFalse(component.is_on)
|
assert not component.is_on
|
||||||
|
|
||||||
def test_dyson_get_speed(self):
|
def test_dyson_get_speed(self):
|
||||||
"""Test get device speed."""
|
"""Test get device speed."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertEqual(component.speed, 1)
|
assert component.speed == 1
|
||||||
|
|
||||||
device = _get_device_off()
|
device = _get_device_off()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertEqual(component.speed, 4)
|
assert component.speed == 4
|
||||||
|
|
||||||
device = _get_device_with_no_state()
|
device = _get_device_with_no_state()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertIsNone(component.speed)
|
assert component.speed is None
|
||||||
|
|
||||||
device = _get_device_auto()
|
device = _get_device_auto()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertEqual(component.speed, "AUTO")
|
assert component.speed == "AUTO"
|
||||||
|
|
||||||
def test_dyson_get_direction(self):
|
def test_dyson_get_direction(self):
|
||||||
"""Test get device direction."""
|
"""Test get device direction."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertIsNone(component.current_direction)
|
assert component.current_direction is None
|
||||||
|
|
||||||
def test_dyson_get_speed_list(self):
|
def test_dyson_get_speed_list(self):
|
||||||
"""Test get speeds list."""
|
"""Test get speeds list."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertEqual(len(component.speed_list), 11)
|
assert len(component.speed_list) == 11
|
||||||
|
|
||||||
def test_dyson_supported_features(self):
|
def test_dyson_supported_features(self):
|
||||||
"""Test supported features."""
|
"""Test supported features."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
|
||||||
self.assertEqual(component.supported_features, 3)
|
assert component.supported_features == 3
|
||||||
|
|
||||||
def test_on_message(self):
|
def test_on_message(self):
|
||||||
"""Test when message is received."""
|
"""Test when message is received."""
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from homeassistant.components.fan import FanEntity
|
from homeassistant.components.fan import FanEntity
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
class BaseFan(FanEntity):
|
class BaseFan(FanEntity):
|
||||||
|
@ -26,15 +27,15 @@ class TestFanEntity(unittest.TestCase):
|
||||||
|
|
||||||
def test_fanentity(self):
|
def test_fanentity(self):
|
||||||
"""Test fan entity methods."""
|
"""Test fan entity methods."""
|
||||||
self.assertEqual('on', self.fan.state)
|
assert 'on' == self.fan.state
|
||||||
self.assertEqual(0, len(self.fan.speed_list))
|
assert 0 == len(self.fan.speed_list)
|
||||||
self.assertEqual(0, self.fan.supported_features)
|
assert 0 == self.fan.supported_features
|
||||||
self.assertEqual({'speed_list': []}, self.fan.state_attributes)
|
assert {'speed_list': []} == self.fan.state_attributes
|
||||||
# Test set_speed not required
|
# Test set_speed not required
|
||||||
self.fan.oscillate(True)
|
self.fan.oscillate(True)
|
||||||
with self.assertRaises(NotImplementedError):
|
with pytest.raises(NotImplementedError):
|
||||||
self.fan.set_speed('slow')
|
self.fan.set_speed('slow')
|
||||||
with self.assertRaises(NotImplementedError):
|
with pytest.raises(NotImplementedError):
|
||||||
self.fan.turn_on()
|
self.fan.turn_on()
|
||||||
with self.assertRaises(NotImplementedError):
|
with pytest.raises(NotImplementedError):
|
||||||
self.fan.turn_off()
|
self.fan.turn_off()
|
||||||
|
|
|
@ -37,32 +37,32 @@ class TestMqttFan(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('fan.test')
|
state = self.hass.states.get('fan.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability_topic', 'online')
|
fire_mqtt_message(self.hass, 'availability_topic', 'online')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('fan.test')
|
state = self.hass.states.get('fan.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability_topic', 'offline')
|
fire_mqtt_message(self.hass, 'availability_topic', 'offline')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('fan.test')
|
state = self.hass.states.get('fan.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', '1')
|
fire_mqtt_message(self.hass, 'state-topic', '1')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('fan.test')
|
state = self.hass.states.get('fan.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability_topic', 'online')
|
fire_mqtt_message(self.hass, 'availability_topic', 'online')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('fan.test')
|
state = self.hass.states.get('fan.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
def test_custom_availability_payload(self):
|
def test_custom_availability_payload(self):
|
||||||
"""Test the availability payload."""
|
"""Test the availability payload."""
|
||||||
|
@ -79,32 +79,32 @@ class TestMqttFan(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('fan.test')
|
state = self.hass.states.get('fan.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability_topic', 'good')
|
fire_mqtt_message(self.hass, 'availability_topic', 'good')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('fan.test')
|
state = self.hass.states.get('fan.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability_topic', 'nogood')
|
fire_mqtt_message(self.hass, 'availability_topic', 'nogood')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('fan.test')
|
state = self.hass.states.get('fan.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', '1')
|
fire_mqtt_message(self.hass, 'state-topic', '1')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('fan.test')
|
state = self.hass.states.get('fan.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability_topic', 'good')
|
fire_mqtt_message(self.hass, 'availability_topic', 'good')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('fan.test')
|
state = self.hass.states.get('fan.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_fan(hass, mqtt_mock, caplog):
|
async def test_discovery_removal_fan(hass, mqtt_mock, caplog):
|
||||||
|
|
|
@ -37,8 +37,7 @@ class TestDemoPlatform(unittest.TestCase):
|
||||||
# Patching 'utcnow' to gain more control over the timed update.
|
# Patching 'utcnow' to gain more control over the timed update.
|
||||||
with patch('homeassistant.util.dt.utcnow', return_value=utcnow):
|
with patch('homeassistant.util.dt.utcnow', return_value=utcnow):
|
||||||
with assert_setup_component(1, geo_location.DOMAIN):
|
with assert_setup_component(1, geo_location.DOMAIN):
|
||||||
self.assertTrue(setup_component(self.hass, geo_location.DOMAIN,
|
assert setup_component(self.hass, geo_location.DOMAIN, CONFIG)
|
||||||
CONFIG))
|
|
||||||
|
|
||||||
# In this test, only entities of the geo location domain have been
|
# In this test, only entities of the geo location domain have been
|
||||||
# generated.
|
# generated.
|
||||||
|
@ -47,10 +46,14 @@ class TestDemoPlatform(unittest.TestCase):
|
||||||
|
|
||||||
# Check a single device's attributes.
|
# Check a single device's attributes.
|
||||||
state_first_entry = all_states[0]
|
state_first_entry = all_states[0]
|
||||||
self.assertAlmostEqual(state_first_entry.attributes['latitude'],
|
assert abs(
|
||||||
self.hass.config.latitude, delta=1.0)
|
state_first_entry.attributes['latitude'] -
|
||||||
self.assertAlmostEqual(state_first_entry.attributes['longitude'],
|
self.hass.config.latitude
|
||||||
self.hass.config.longitude, delta=1.0)
|
) < 1.0
|
||||||
|
assert abs(
|
||||||
|
state_first_entry.attributes['longitude'] -
|
||||||
|
self.hass.config.longitude
|
||||||
|
) < 1.0
|
||||||
assert state_first_entry.attributes['unit_of_measurement'] == \
|
assert state_first_entry.attributes['unit_of_measurement'] == \
|
||||||
DEFAULT_UNIT_OF_MEASUREMENT
|
DEFAULT_UNIT_OF_MEASUREMENT
|
||||||
# Update (replaces 1 device).
|
# Update (replaces 1 device).
|
||||||
|
@ -60,4 +63,4 @@ class TestDemoPlatform(unittest.TestCase):
|
||||||
# the same, but the lists are different.
|
# the same, but the lists are different.
|
||||||
all_states_updated = self.hass.states.all()
|
all_states_updated = self.hass.states.all()
|
||||||
assert len(all_states_updated) == NUMBER_OF_DEMO_DEVICES
|
assert len(all_states_updated) == NUMBER_OF_DEMO_DEVICES
|
||||||
self.assertNotEqual(all_states, all_states_updated)
|
assert all_states != all_states_updated
|
||||||
|
|
|
@ -70,8 +70,7 @@ class TestGeoJsonPlatform(unittest.TestCase):
|
||||||
# Patching 'utcnow' to gain more control over the timed update.
|
# Patching 'utcnow' to gain more control over the timed update.
|
||||||
with patch('homeassistant.util.dt.utcnow', return_value=utcnow):
|
with patch('homeassistant.util.dt.utcnow', return_value=utcnow):
|
||||||
with assert_setup_component(1, geo_location.DOMAIN):
|
with assert_setup_component(1, geo_location.DOMAIN):
|
||||||
self.assertTrue(setup_component(self.hass, geo_location.DOMAIN,
|
assert setup_component(self.hass, geo_location.DOMAIN, CONFIG)
|
||||||
CONFIG))
|
|
||||||
# Artificially trigger update.
|
# Artificially trigger update.
|
||||||
self.hass.bus.fire(EVENT_HOMEASSISTANT_START)
|
self.hass.bus.fire(EVENT_HOMEASSISTANT_START)
|
||||||
# Collect events.
|
# Collect events.
|
||||||
|
@ -81,34 +80,34 @@ class TestGeoJsonPlatform(unittest.TestCase):
|
||||||
assert len(all_states) == 3
|
assert len(all_states) == 3
|
||||||
|
|
||||||
state = self.hass.states.get("geo_location.title_1")
|
state = self.hass.states.get("geo_location.title_1")
|
||||||
self.assertIsNotNone(state)
|
assert state is not None
|
||||||
assert state.name == "Title 1"
|
assert state.name == "Title 1"
|
||||||
assert state.attributes == {
|
assert state.attributes == {
|
||||||
ATTR_EXTERNAL_ID: "1234", ATTR_LATITUDE: -31.0,
|
ATTR_EXTERNAL_ID: "1234", ATTR_LATITUDE: -31.0,
|
||||||
ATTR_LONGITUDE: 150.0, ATTR_FRIENDLY_NAME: "Title 1",
|
ATTR_LONGITUDE: 150.0, ATTR_FRIENDLY_NAME: "Title 1",
|
||||||
ATTR_UNIT_OF_MEASUREMENT: "km",
|
ATTR_UNIT_OF_MEASUREMENT: "km",
|
||||||
ATTR_SOURCE: 'geo_json_events'}
|
ATTR_SOURCE: 'geo_json_events'}
|
||||||
self.assertAlmostEqual(float(state.state), 15.5)
|
assert round(abs(float(state.state)-15.5), 7) == 0
|
||||||
|
|
||||||
state = self.hass.states.get("geo_location.title_2")
|
state = self.hass.states.get("geo_location.title_2")
|
||||||
self.assertIsNotNone(state)
|
assert state is not None
|
||||||
assert state.name == "Title 2"
|
assert state.name == "Title 2"
|
||||||
assert state.attributes == {
|
assert state.attributes == {
|
||||||
ATTR_EXTERNAL_ID: "2345", ATTR_LATITUDE: -31.1,
|
ATTR_EXTERNAL_ID: "2345", ATTR_LATITUDE: -31.1,
|
||||||
ATTR_LONGITUDE: 150.1, ATTR_FRIENDLY_NAME: "Title 2",
|
ATTR_LONGITUDE: 150.1, ATTR_FRIENDLY_NAME: "Title 2",
|
||||||
ATTR_UNIT_OF_MEASUREMENT: "km",
|
ATTR_UNIT_OF_MEASUREMENT: "km",
|
||||||
ATTR_SOURCE: 'geo_json_events'}
|
ATTR_SOURCE: 'geo_json_events'}
|
||||||
self.assertAlmostEqual(float(state.state), 20.5)
|
assert round(abs(float(state.state)-20.5), 7) == 0
|
||||||
|
|
||||||
state = self.hass.states.get("geo_location.title_3")
|
state = self.hass.states.get("geo_location.title_3")
|
||||||
self.assertIsNotNone(state)
|
assert state is not None
|
||||||
assert state.name == "Title 3"
|
assert state.name == "Title 3"
|
||||||
assert state.attributes == {
|
assert state.attributes == {
|
||||||
ATTR_EXTERNAL_ID: "3456", ATTR_LATITUDE: -31.2,
|
ATTR_EXTERNAL_ID: "3456", ATTR_LATITUDE: -31.2,
|
||||||
ATTR_LONGITUDE: 150.2, ATTR_FRIENDLY_NAME: "Title 3",
|
ATTR_LONGITUDE: 150.2, ATTR_FRIENDLY_NAME: "Title 3",
|
||||||
ATTR_UNIT_OF_MEASUREMENT: "km",
|
ATTR_UNIT_OF_MEASUREMENT: "km",
|
||||||
ATTR_SOURCE: 'geo_json_events'}
|
ATTR_SOURCE: 'geo_json_events'}
|
||||||
self.assertAlmostEqual(float(state.state), 25.5)
|
assert round(abs(float(state.state)-25.5), 7) == 0
|
||||||
|
|
||||||
# Simulate an update - one existing, one new entry,
|
# Simulate an update - one existing, one new entry,
|
||||||
# one outdated entry
|
# one outdated entry
|
||||||
|
@ -162,8 +161,7 @@ class TestGeoJsonPlatform(unittest.TestCase):
|
||||||
# Patching 'utcnow' to gain more control over the timed update.
|
# Patching 'utcnow' to gain more control over the timed update.
|
||||||
with patch('homeassistant.util.dt.utcnow', return_value=utcnow):
|
with patch('homeassistant.util.dt.utcnow', return_value=utcnow):
|
||||||
with assert_setup_component(1, geo_location.DOMAIN):
|
with assert_setup_component(1, geo_location.DOMAIN):
|
||||||
self.assertTrue(setup_component(self.hass, geo_location.DOMAIN,
|
assert setup_component(self.hass, geo_location.DOMAIN, CONFIG)
|
||||||
CONFIG))
|
|
||||||
|
|
||||||
# This gives us the ability to assert the '_delete_callback'
|
# This gives us the ability to assert the '_delete_callback'
|
||||||
# has been called while still executing it.
|
# has been called while still executing it.
|
||||||
|
|
|
@ -93,8 +93,7 @@ class TestGeoJsonPlatform(unittest.TestCase):
|
||||||
# Patching 'utcnow' to gain more control over the timed update.
|
# Patching 'utcnow' to gain more control over the timed update.
|
||||||
with patch('homeassistant.util.dt.utcnow', return_value=utcnow):
|
with patch('homeassistant.util.dt.utcnow', return_value=utcnow):
|
||||||
with assert_setup_component(1, geo_location.DOMAIN):
|
with assert_setup_component(1, geo_location.DOMAIN):
|
||||||
self.assertTrue(setup_component(self.hass, geo_location.DOMAIN,
|
assert setup_component(self.hass, geo_location.DOMAIN, CONFIG)
|
||||||
CONFIG))
|
|
||||||
# Artificially trigger update.
|
# Artificially trigger update.
|
||||||
self.hass.bus.fire(EVENT_HOMEASSISTANT_START)
|
self.hass.bus.fire(EVENT_HOMEASSISTANT_START)
|
||||||
# Collect events.
|
# Collect events.
|
||||||
|
@ -104,7 +103,7 @@ class TestGeoJsonPlatform(unittest.TestCase):
|
||||||
assert len(all_states) == 3
|
assert len(all_states) == 3
|
||||||
|
|
||||||
state = self.hass.states.get("geo_location.title_1")
|
state = self.hass.states.get("geo_location.title_1")
|
||||||
self.assertIsNotNone(state)
|
assert state is not None
|
||||||
assert state.name == "Title 1"
|
assert state.name == "Title 1"
|
||||||
assert state.attributes == {
|
assert state.attributes == {
|
||||||
ATTR_EXTERNAL_ID: "1234", ATTR_LATITUDE: -31.0,
|
ATTR_EXTERNAL_ID: "1234", ATTR_LATITUDE: -31.0,
|
||||||
|
@ -120,10 +119,10 @@ class TestGeoJsonPlatform(unittest.TestCase):
|
||||||
ATTR_SIZE: 'Size 1', ATTR_RESPONSIBLE_AGENCY: 'Agency 1',
|
ATTR_SIZE: 'Size 1', ATTR_RESPONSIBLE_AGENCY: 'Agency 1',
|
||||||
ATTR_UNIT_OF_MEASUREMENT: "km",
|
ATTR_UNIT_OF_MEASUREMENT: "km",
|
||||||
ATTR_SOURCE: 'nsw_rural_fire_service_feed'}
|
ATTR_SOURCE: 'nsw_rural_fire_service_feed'}
|
||||||
self.assertAlmostEqual(float(state.state), 15.5)
|
assert round(abs(float(state.state)-15.5), 7) == 0
|
||||||
|
|
||||||
state = self.hass.states.get("geo_location.title_2")
|
state = self.hass.states.get("geo_location.title_2")
|
||||||
self.assertIsNotNone(state)
|
assert state is not None
|
||||||
assert state.name == "Title 2"
|
assert state.name == "Title 2"
|
||||||
assert state.attributes == {
|
assert state.attributes == {
|
||||||
ATTR_EXTERNAL_ID: "2345", ATTR_LATITUDE: -31.1,
|
ATTR_EXTERNAL_ID: "2345", ATTR_LATITUDE: -31.1,
|
||||||
|
@ -131,10 +130,10 @@ class TestGeoJsonPlatform(unittest.TestCase):
|
||||||
ATTR_FIRE: False,
|
ATTR_FIRE: False,
|
||||||
ATTR_UNIT_OF_MEASUREMENT: "km",
|
ATTR_UNIT_OF_MEASUREMENT: "km",
|
||||||
ATTR_SOURCE: 'nsw_rural_fire_service_feed'}
|
ATTR_SOURCE: 'nsw_rural_fire_service_feed'}
|
||||||
self.assertAlmostEqual(float(state.state), 20.5)
|
assert round(abs(float(state.state)-20.5), 7) == 0
|
||||||
|
|
||||||
state = self.hass.states.get("geo_location.title_3")
|
state = self.hass.states.get("geo_location.title_3")
|
||||||
self.assertIsNotNone(state)
|
assert state is not None
|
||||||
assert state.name == "Title 3"
|
assert state.name == "Title 3"
|
||||||
assert state.attributes == {
|
assert state.attributes == {
|
||||||
ATTR_EXTERNAL_ID: "3456", ATTR_LATITUDE: -31.2,
|
ATTR_EXTERNAL_ID: "3456", ATTR_LATITUDE: -31.2,
|
||||||
|
@ -142,7 +141,7 @@ class TestGeoJsonPlatform(unittest.TestCase):
|
||||||
ATTR_FIRE: True,
|
ATTR_FIRE: True,
|
||||||
ATTR_UNIT_OF_MEASUREMENT: "km",
|
ATTR_UNIT_OF_MEASUREMENT: "km",
|
||||||
ATTR_SOURCE: 'nsw_rural_fire_service_feed'}
|
ATTR_SOURCE: 'nsw_rural_fire_service_feed'}
|
||||||
self.assertAlmostEqual(float(state.state), 25.5)
|
assert round(abs(float(state.state)-25.5), 7) == 0
|
||||||
|
|
||||||
# Simulate an update - one existing, one new entry,
|
# Simulate an update - one existing, one new entry,
|
||||||
# one outdated entry
|
# one outdated entry
|
||||||
|
|
|
@ -36,10 +36,9 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
self.hass, 'person_and_light',
|
self.hass, 'person_and_light',
|
||||||
['light.Bowl', 'device_tracker.Paulus'])
|
['light.Bowl', 'device_tracker.Paulus'])
|
||||||
|
|
||||||
self.assertEqual(
|
assert STATE_ON == \
|
||||||
STATE_ON,
|
|
||||||
self.hass.states.get(
|
self.hass.states.get(
|
||||||
group.ENTITY_ID_FORMAT.format('person_and_light')).state)
|
group.ENTITY_ID_FORMAT.format('person_and_light')).state
|
||||||
|
|
||||||
def test_setup_group_with_a_non_existing_state(self):
|
def test_setup_group_with_a_non_existing_state(self):
|
||||||
"""Try to set up a group with a non existing state."""
|
"""Try to set up a group with a non existing state."""
|
||||||
|
@ -49,7 +48,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
self.hass, 'light_and_nothing',
|
self.hass, 'light_and_nothing',
|
||||||
['light.Bowl', 'non.existing'])
|
['light.Bowl', 'non.existing'])
|
||||||
|
|
||||||
self.assertEqual(STATE_ON, grp.state)
|
assert STATE_ON == grp.state
|
||||||
|
|
||||||
def test_setup_group_with_non_groupable_states(self):
|
def test_setup_group_with_non_groupable_states(self):
|
||||||
"""Test setup with groups which are not groupable."""
|
"""Test setup with groups which are not groupable."""
|
||||||
|
@ -60,13 +59,13 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
self.hass, 'chromecasts',
|
self.hass, 'chromecasts',
|
||||||
['cast.living_room', 'cast.bedroom'])
|
['cast.living_room', 'cast.bedroom'])
|
||||||
|
|
||||||
self.assertEqual(STATE_UNKNOWN, grp.state)
|
assert STATE_UNKNOWN == grp.state
|
||||||
|
|
||||||
def test_setup_empty_group(self):
|
def test_setup_empty_group(self):
|
||||||
"""Try to set up an empty group."""
|
"""Try to set up an empty group."""
|
||||||
grp = group.Group.create_group(self.hass, 'nothing', [])
|
grp = group.Group.create_group(self.hass, 'nothing', [])
|
||||||
|
|
||||||
self.assertEqual(STATE_UNKNOWN, grp.state)
|
assert STATE_UNKNOWN == grp.state
|
||||||
|
|
||||||
def test_monitor_group(self):
|
def test_monitor_group(self):
|
||||||
"""Test if the group keeps track of states."""
|
"""Test if the group keeps track of states."""
|
||||||
|
@ -76,11 +75,11 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
||||||
|
|
||||||
# Test if group setup in our init mode is ok
|
# Test if group setup in our init mode is ok
|
||||||
self.assertIn(test_group.entity_id, self.hass.states.entity_ids())
|
assert test_group.entity_id in self.hass.states.entity_ids()
|
||||||
|
|
||||||
group_state = self.hass.states.get(test_group.entity_id)
|
group_state = self.hass.states.get(test_group.entity_id)
|
||||||
self.assertEqual(STATE_ON, group_state.state)
|
assert STATE_ON == group_state.state
|
||||||
self.assertTrue(group_state.attributes.get(group.ATTR_AUTO))
|
assert group_state.attributes.get(group.ATTR_AUTO)
|
||||||
|
|
||||||
def test_group_turns_off_if_all_off(self):
|
def test_group_turns_off_if_all_off(self):
|
||||||
"""Test if turn off if the last device that was on turns off."""
|
"""Test if turn off if the last device that was on turns off."""
|
||||||
|
@ -92,7 +91,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
group_state = self.hass.states.get(test_group.entity_id)
|
group_state = self.hass.states.get(test_group.entity_id)
|
||||||
self.assertEqual(STATE_OFF, group_state.state)
|
assert STATE_OFF == group_state.state
|
||||||
|
|
||||||
def test_group_turns_on_if_all_are_off_and_one_turns_on(self):
|
def test_group_turns_on_if_all_are_off_and_one_turns_on(self):
|
||||||
"""Test if turn on if all devices were turned off and one turns on."""
|
"""Test if turn on if all devices were turned off and one turns on."""
|
||||||
|
@ -106,7 +105,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
group_state = self.hass.states.get(test_group.entity_id)
|
group_state = self.hass.states.get(test_group.entity_id)
|
||||||
self.assertEqual(STATE_ON, group_state.state)
|
assert STATE_ON == group_state.state
|
||||||
|
|
||||||
def test_allgroup_stays_off_if_all_are_off_and_one_turns_on(self):
|
def test_allgroup_stays_off_if_all_are_off_and_one_turns_on(self):
|
||||||
"""Group with all: true, stay off if one device turns on."""
|
"""Group with all: true, stay off if one device turns on."""
|
||||||
|
@ -121,7 +120,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
group_state = self.hass.states.get(test_group.entity_id)
|
group_state = self.hass.states.get(test_group.entity_id)
|
||||||
self.assertEqual(STATE_OFF, group_state.state)
|
assert STATE_OFF == group_state.state
|
||||||
|
|
||||||
def test_allgroup_turn_on_if_last_turns_on(self):
|
def test_allgroup_turn_on_if_last_turns_on(self):
|
||||||
"""Group with all: true, turn on if all devices are on."""
|
"""Group with all: true, turn on if all devices are on."""
|
||||||
|
@ -136,7 +135,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
group_state = self.hass.states.get(test_group.entity_id)
|
group_state = self.hass.states.get(test_group.entity_id)
|
||||||
self.assertEqual(STATE_ON, group_state.state)
|
assert STATE_ON == group_state.state
|
||||||
|
|
||||||
def test_is_on(self):
|
def test_is_on(self):
|
||||||
"""Test is_on method."""
|
"""Test is_on method."""
|
||||||
|
@ -145,13 +144,13 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
test_group = group.Group.create_group(
|
test_group = group.Group.create_group(
|
||||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
||||||
|
|
||||||
self.assertTrue(group.is_on(self.hass, test_group.entity_id))
|
assert group.is_on(self.hass, test_group.entity_id)
|
||||||
self.hass.states.set('light.Bowl', STATE_OFF)
|
self.hass.states.set('light.Bowl', STATE_OFF)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertFalse(group.is_on(self.hass, test_group.entity_id))
|
assert not group.is_on(self.hass, test_group.entity_id)
|
||||||
|
|
||||||
# Try on non existing state
|
# Try on non existing state
|
||||||
self.assertFalse(group.is_on(self.hass, 'non.existing'))
|
assert not group.is_on(self.hass, 'non.existing')
|
||||||
|
|
||||||
def test_expand_entity_ids(self):
|
def test_expand_entity_ids(self):
|
||||||
"""Test expand_entity_ids method."""
|
"""Test expand_entity_ids method."""
|
||||||
|
@ -160,9 +159,9 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
test_group = group.Group.create_group(
|
test_group = group.Group.create_group(
|
||||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
||||||
|
|
||||||
self.assertEqual(sorted(['light.ceiling', 'light.bowl']),
|
assert sorted(['light.ceiling', 'light.bowl']) == \
|
||||||
sorted(group.expand_entity_ids(
|
sorted(group.expand_entity_ids(
|
||||||
self.hass, [test_group.entity_id])))
|
self.hass, [test_group.entity_id]))
|
||||||
|
|
||||||
def test_expand_entity_ids_does_not_return_duplicates(self):
|
def test_expand_entity_ids_does_not_return_duplicates(self):
|
||||||
"""Test that expand_entity_ids does not return duplicates."""
|
"""Test that expand_entity_ids does not return duplicates."""
|
||||||
|
@ -171,15 +170,13 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
test_group = group.Group.create_group(
|
test_group = group.Group.create_group(
|
||||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
||||||
|
|
||||||
self.assertEqual(
|
assert ['light.bowl', 'light.ceiling'] == \
|
||||||
['light.bowl', 'light.ceiling'],
|
|
||||||
sorted(group.expand_entity_ids(
|
sorted(group.expand_entity_ids(
|
||||||
self.hass, [test_group.entity_id, 'light.Ceiling'])))
|
self.hass, [test_group.entity_id, 'light.Ceiling']))
|
||||||
|
|
||||||
self.assertEqual(
|
assert ['light.bowl', 'light.ceiling'] == \
|
||||||
['light.bowl', 'light.ceiling'],
|
|
||||||
sorted(group.expand_entity_ids(
|
sorted(group.expand_entity_ids(
|
||||||
self.hass, ['light.bowl', test_group.entity_id])))
|
self.hass, ['light.bowl', test_group.entity_id]))
|
||||||
|
|
||||||
def test_expand_entity_ids_recursive(self):
|
def test_expand_entity_ids_recursive(self):
|
||||||
"""Test expand_entity_ids method with a group that contains itself."""
|
"""Test expand_entity_ids method with a group that contains itself."""
|
||||||
|
@ -191,13 +188,13 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
['light.Bowl', 'light.Ceiling', 'group.init_group'],
|
['light.Bowl', 'light.Ceiling', 'group.init_group'],
|
||||||
False)
|
False)
|
||||||
|
|
||||||
self.assertEqual(sorted(['light.ceiling', 'light.bowl']),
|
assert sorted(['light.ceiling', 'light.bowl']) == \
|
||||||
sorted(group.expand_entity_ids(
|
sorted(group.expand_entity_ids(
|
||||||
self.hass, [test_group.entity_id])))
|
self.hass, [test_group.entity_id]))
|
||||||
|
|
||||||
def test_expand_entity_ids_ignores_non_strings(self):
|
def test_expand_entity_ids_ignores_non_strings(self):
|
||||||
"""Test that non string elements in lists are ignored."""
|
"""Test that non string elements in lists are ignored."""
|
||||||
self.assertEqual([], group.expand_entity_ids(self.hass, [5, True]))
|
assert [] == group.expand_entity_ids(self.hass, [5, True])
|
||||||
|
|
||||||
def test_get_entity_ids(self):
|
def test_get_entity_ids(self):
|
||||||
"""Test get_entity_ids method."""
|
"""Test get_entity_ids method."""
|
||||||
|
@ -206,9 +203,8 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
test_group = group.Group.create_group(
|
test_group = group.Group.create_group(
|
||||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
||||||
|
|
||||||
self.assertEqual(
|
assert ['light.bowl', 'light.ceiling'] == \
|
||||||
['light.bowl', 'light.ceiling'],
|
sorted(group.get_entity_ids(self.hass, test_group.entity_id))
|
||||||
sorted(group.get_entity_ids(self.hass, test_group.entity_id)))
|
|
||||||
|
|
||||||
def test_get_entity_ids_with_domain_filter(self):
|
def test_get_entity_ids_with_domain_filter(self):
|
||||||
"""Test if get_entity_ids works with a domain_filter."""
|
"""Test if get_entity_ids works with a domain_filter."""
|
||||||
|
@ -217,18 +213,17 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
mixed_group = group.Group.create_group(
|
mixed_group = group.Group.create_group(
|
||||||
self.hass, 'mixed_group', ['light.Bowl', 'switch.AC'], False)
|
self.hass, 'mixed_group', ['light.Bowl', 'switch.AC'], False)
|
||||||
|
|
||||||
self.assertEqual(
|
assert ['switch.ac'] == \
|
||||||
['switch.ac'],
|
|
||||||
group.get_entity_ids(
|
group.get_entity_ids(
|
||||||
self.hass, mixed_group.entity_id, domain_filter="switch"))
|
self.hass, mixed_group.entity_id, domain_filter="switch")
|
||||||
|
|
||||||
def test_get_entity_ids_with_non_existing_group_name(self):
|
def test_get_entity_ids_with_non_existing_group_name(self):
|
||||||
"""Test get_entity_ids with a non existing group."""
|
"""Test get_entity_ids with a non existing group."""
|
||||||
self.assertEqual([], group.get_entity_ids(self.hass, 'non_existing'))
|
assert [] == group.get_entity_ids(self.hass, 'non_existing')
|
||||||
|
|
||||||
def test_get_entity_ids_with_non_group_state(self):
|
def test_get_entity_ids_with_non_group_state(self):
|
||||||
"""Test get_entity_ids with a non group state."""
|
"""Test get_entity_ids with a non group state."""
|
||||||
self.assertEqual([], group.get_entity_ids(self.hass, 'switch.AC'))
|
assert [] == group.get_entity_ids(self.hass, 'switch.AC')
|
||||||
|
|
||||||
def test_group_being_init_before_first_tracked_state_is_set_to_on(self):
|
def test_group_being_init_before_first_tracked_state_is_set_to_on(self):
|
||||||
"""Test if the groups turn on.
|
"""Test if the groups turn on.
|
||||||
|
@ -244,7 +239,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
group_state = self.hass.states.get(test_group.entity_id)
|
group_state = self.hass.states.get(test_group.entity_id)
|
||||||
self.assertEqual(STATE_ON, group_state.state)
|
assert STATE_ON == group_state.state
|
||||||
|
|
||||||
def test_group_being_init_before_first_tracked_state_is_set_to_off(self):
|
def test_group_being_init_before_first_tracked_state_is_set_to_off(self):
|
||||||
"""Test if the group turns off.
|
"""Test if the group turns off.
|
||||||
|
@ -260,7 +255,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
group_state = self.hass.states.get(test_group.entity_id)
|
group_state = self.hass.states.get(test_group.entity_id)
|
||||||
self.assertEqual(STATE_OFF, group_state.state)
|
assert STATE_OFF == group_state.state
|
||||||
|
|
||||||
def test_setup(self):
|
def test_setup(self):
|
||||||
"""Test setup method."""
|
"""Test setup method."""
|
||||||
|
@ -283,36 +278,36 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
|
|
||||||
group_state = self.hass.states.get(
|
group_state = self.hass.states.get(
|
||||||
group.ENTITY_ID_FORMAT.format('second_group'))
|
group.ENTITY_ID_FORMAT.format('second_group'))
|
||||||
self.assertEqual(STATE_ON, group_state.state)
|
assert STATE_ON == group_state.state
|
||||||
self.assertEqual(set((test_group.entity_id, 'light.bowl')),
|
assert set((test_group.entity_id, 'light.bowl')) == \
|
||||||
set(group_state.attributes['entity_id']))
|
set(group_state.attributes['entity_id'])
|
||||||
self.assertIsNone(group_state.attributes.get(group.ATTR_AUTO))
|
assert group_state.attributes.get(group.ATTR_AUTO) is None
|
||||||
self.assertEqual('mdi:work',
|
assert 'mdi:work' == \
|
||||||
group_state.attributes.get(ATTR_ICON))
|
group_state.attributes.get(ATTR_ICON)
|
||||||
self.assertTrue(group_state.attributes.get(group.ATTR_VIEW))
|
assert group_state.attributes.get(group.ATTR_VIEW)
|
||||||
self.assertEqual('hidden',
|
assert 'hidden' == \
|
||||||
group_state.attributes.get(group.ATTR_CONTROL))
|
group_state.attributes.get(group.ATTR_CONTROL)
|
||||||
self.assertTrue(group_state.attributes.get(ATTR_HIDDEN))
|
assert group_state.attributes.get(ATTR_HIDDEN)
|
||||||
self.assertEqual(1, group_state.attributes.get(group.ATTR_ORDER))
|
assert 1 == group_state.attributes.get(group.ATTR_ORDER)
|
||||||
|
|
||||||
group_state = self.hass.states.get(
|
group_state = self.hass.states.get(
|
||||||
group.ENTITY_ID_FORMAT.format('test_group'))
|
group.ENTITY_ID_FORMAT.format('test_group'))
|
||||||
self.assertEqual(STATE_UNKNOWN, group_state.state)
|
assert STATE_UNKNOWN == group_state.state
|
||||||
self.assertEqual(set(('sensor.happy', 'hello.world')),
|
assert set(('sensor.happy', 'hello.world')) == \
|
||||||
set(group_state.attributes['entity_id']))
|
set(group_state.attributes['entity_id'])
|
||||||
self.assertIsNone(group_state.attributes.get(group.ATTR_AUTO))
|
assert group_state.attributes.get(group.ATTR_AUTO) is None
|
||||||
self.assertIsNone(group_state.attributes.get(ATTR_ICON))
|
assert group_state.attributes.get(ATTR_ICON) is None
|
||||||
self.assertIsNone(group_state.attributes.get(group.ATTR_VIEW))
|
assert group_state.attributes.get(group.ATTR_VIEW) is None
|
||||||
self.assertIsNone(group_state.attributes.get(group.ATTR_CONTROL))
|
assert group_state.attributes.get(group.ATTR_CONTROL) is None
|
||||||
self.assertIsNone(group_state.attributes.get(ATTR_HIDDEN))
|
assert group_state.attributes.get(ATTR_HIDDEN) is None
|
||||||
self.assertEqual(2, group_state.attributes.get(group.ATTR_ORDER))
|
assert 2 == group_state.attributes.get(group.ATTR_ORDER)
|
||||||
|
|
||||||
def test_groups_get_unique_names(self):
|
def test_groups_get_unique_names(self):
|
||||||
"""Two groups with same name should both have a unique entity id."""
|
"""Two groups with same name should both have a unique entity id."""
|
||||||
grp1 = group.Group.create_group(self.hass, 'Je suis Charlie')
|
grp1 = group.Group.create_group(self.hass, 'Je suis Charlie')
|
||||||
grp2 = group.Group.create_group(self.hass, 'Je suis Charlie')
|
grp2 = group.Group.create_group(self.hass, 'Je suis Charlie')
|
||||||
|
|
||||||
self.assertNotEqual(grp1.entity_id, grp2.entity_id)
|
assert grp1.entity_id != grp2.entity_id
|
||||||
|
|
||||||
def test_expand_entity_ids_expands_nested_groups(self):
|
def test_expand_entity_ids_expands_nested_groups(self):
|
||||||
"""Test if entity ids epands to nested groups."""
|
"""Test if entity ids epands to nested groups."""
|
||||||
|
@ -323,10 +318,10 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
group.Group.create_group(
|
group.Group.create_group(
|
||||||
self.hass, 'group_of_groups', ['group.light', 'group.switch'])
|
self.hass, 'group_of_groups', ['group.light', 'group.switch'])
|
||||||
|
|
||||||
self.assertEqual(
|
assert ['light.test_1', 'light.test_2',
|
||||||
['light.test_1', 'light.test_2', 'switch.test_1', 'switch.test_2'],
|
'switch.test_1', 'switch.test_2'] == \
|
||||||
sorted(group.expand_entity_ids(self.hass,
|
sorted(group.expand_entity_ids(self.hass,
|
||||||
['group.group_of_groups'])))
|
['group.group_of_groups']))
|
||||||
|
|
||||||
def test_set_assumed_state_based_on_tracked(self):
|
def test_set_assumed_state_based_on_tracked(self):
|
||||||
"""Test assumed state."""
|
"""Test assumed state."""
|
||||||
|
@ -337,7 +332,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
['light.Bowl', 'light.Ceiling', 'sensor.no_exist'])
|
['light.Bowl', 'light.Ceiling', 'sensor.no_exist'])
|
||||||
|
|
||||||
state = self.hass.states.get(test_group.entity_id)
|
state = self.hass.states.get(test_group.entity_id)
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
self.hass.states.set('light.Bowl', STATE_ON, {
|
self.hass.states.set('light.Bowl', STATE_ON, {
|
||||||
ATTR_ASSUMED_STATE: True
|
ATTR_ASSUMED_STATE: True
|
||||||
|
@ -345,13 +340,13 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get(test_group.entity_id)
|
state = self.hass.states.get(test_group.entity_id)
|
||||||
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
self.hass.states.set('light.Bowl', STATE_ON)
|
self.hass.states.set('light.Bowl', STATE_ON)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get(test_group.entity_id)
|
state = self.hass.states.get(test_group.entity_id)
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
def test_group_updated_after_device_tracker_zone_change(self):
|
def test_group_updated_after_device_tracker_zone_change(self):
|
||||||
"""Test group state when device tracker in group changes zone."""
|
"""Test group state when device tracker in group changes zone."""
|
||||||
|
@ -363,9 +358,9 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
['device_tracker.Adam', 'device_tracker.Eve'])
|
['device_tracker.Adam', 'device_tracker.Eve'])
|
||||||
self.hass.states.set('device_tracker.Adam', 'cool_state_not_home')
|
self.hass.states.set('device_tracker.Adam', 'cool_state_not_home')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(STATE_NOT_HOME,
|
assert STATE_NOT_HOME == \
|
||||||
self.hass.states.get(
|
self.hass.states.get(
|
||||||
group.ENTITY_ID_FORMAT.format('peeps')).state)
|
group.ENTITY_ID_FORMAT.format('peeps')).state
|
||||||
|
|
||||||
def test_reloading_groups(self):
|
def test_reloading_groups(self):
|
||||||
"""Test reloading the group config."""
|
"""Test reloading the group config."""
|
||||||
|
@ -419,13 +414,13 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
common.set_visibility(self.hass, group_entity_id, False)
|
common.set_visibility(self.hass, group_entity_id, False)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
group_state = self.hass.states.get(group_entity_id)
|
group_state = self.hass.states.get(group_entity_id)
|
||||||
self.assertTrue(group_state.attributes.get(ATTR_HIDDEN))
|
assert group_state.attributes.get(ATTR_HIDDEN)
|
||||||
|
|
||||||
# Show it again
|
# Show it again
|
||||||
common.set_visibility(self.hass, group_entity_id, True)
|
common.set_visibility(self.hass, group_entity_id, True)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
group_state = self.hass.states.get(group_entity_id)
|
group_state = self.hass.states.get(group_entity_id)
|
||||||
self.assertIsNone(group_state.attributes.get(ATTR_HIDDEN))
|
assert group_state.attributes.get(ATTR_HIDDEN) is None
|
||||||
|
|
||||||
def test_modify_group(self):
|
def test_modify_group(self):
|
||||||
"""Test modifying a group."""
|
"""Test modifying a group."""
|
||||||
|
|
|
@ -40,16 +40,16 @@ class TestLight(unittest.TestCase):
|
||||||
"""Test if methods call the services as expected."""
|
"""Test if methods call the services as expected."""
|
||||||
# Test is_on
|
# Test is_on
|
||||||
self.hass.states.set('light.test', STATE_ON)
|
self.hass.states.set('light.test', STATE_ON)
|
||||||
self.assertTrue(light.is_on(self.hass, 'light.test'))
|
assert light.is_on(self.hass, 'light.test')
|
||||||
|
|
||||||
self.hass.states.set('light.test', STATE_OFF)
|
self.hass.states.set('light.test', STATE_OFF)
|
||||||
self.assertFalse(light.is_on(self.hass, 'light.test'))
|
assert not light.is_on(self.hass, 'light.test')
|
||||||
|
|
||||||
self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_ON)
|
self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_ON)
|
||||||
self.assertTrue(light.is_on(self.hass))
|
assert light.is_on(self.hass)
|
||||||
|
|
||||||
self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_OFF)
|
self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_OFF)
|
||||||
self.assertFalse(light.is_on(self.hass))
|
assert not light.is_on(self.hass)
|
||||||
|
|
||||||
# Test turn_on
|
# Test turn_on
|
||||||
turn_on_calls = mock_service(
|
turn_on_calls = mock_service(
|
||||||
|
@ -68,22 +68,19 @@ class TestLight(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(turn_on_calls))
|
assert 1 == len(turn_on_calls)
|
||||||
call = turn_on_calls[-1]
|
call = turn_on_calls[-1]
|
||||||
|
|
||||||
self.assertEqual(light.DOMAIN, call.domain)
|
assert light.DOMAIN == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
assert SERVICE_TURN_ON == call.service
|
||||||
self.assertEqual('entity_id_val', call.data.get(ATTR_ENTITY_ID))
|
assert 'entity_id_val' == call.data.get(ATTR_ENTITY_ID)
|
||||||
self.assertEqual(
|
assert 'transition_val' == call.data.get(light.ATTR_TRANSITION)
|
||||||
'transition_val', call.data.get(light.ATTR_TRANSITION))
|
assert 'brightness_val' == call.data.get(light.ATTR_BRIGHTNESS)
|
||||||
self.assertEqual(
|
assert 'rgb_color_val' == call.data.get(light.ATTR_RGB_COLOR)
|
||||||
'brightness_val', call.data.get(light.ATTR_BRIGHTNESS))
|
assert 'xy_color_val' == call.data.get(light.ATTR_XY_COLOR)
|
||||||
self.assertEqual('rgb_color_val', call.data.get(light.ATTR_RGB_COLOR))
|
assert 'profile_val' == call.data.get(light.ATTR_PROFILE)
|
||||||
self.assertEqual('xy_color_val', call.data.get(light.ATTR_XY_COLOR))
|
assert 'color_name_val' == call.data.get(light.ATTR_COLOR_NAME)
|
||||||
self.assertEqual('profile_val', call.data.get(light.ATTR_PROFILE))
|
assert 'white_val' == call.data.get(light.ATTR_WHITE_VALUE)
|
||||||
self.assertEqual(
|
|
||||||
'color_name_val', call.data.get(light.ATTR_COLOR_NAME))
|
|
||||||
self.assertEqual('white_val', call.data.get(light.ATTR_WHITE_VALUE))
|
|
||||||
|
|
||||||
# Test turn_off
|
# Test turn_off
|
||||||
turn_off_calls = mock_service(
|
turn_off_calls = mock_service(
|
||||||
|
@ -94,13 +91,13 @@ class TestLight(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(turn_off_calls))
|
assert 1 == len(turn_off_calls)
|
||||||
call = turn_off_calls[-1]
|
call = turn_off_calls[-1]
|
||||||
|
|
||||||
self.assertEqual(light.DOMAIN, call.domain)
|
assert light.DOMAIN == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
assert SERVICE_TURN_OFF == call.service
|
||||||
self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID])
|
assert 'entity_id_val' == call.data[ATTR_ENTITY_ID]
|
||||||
self.assertEqual('transition_val', call.data[light.ATTR_TRANSITION])
|
assert 'transition_val' == call.data[light.ATTR_TRANSITION]
|
||||||
|
|
||||||
# Test toggle
|
# Test toggle
|
||||||
toggle_calls = mock_service(
|
toggle_calls = mock_service(
|
||||||
|
@ -111,29 +108,28 @@ class TestLight(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(toggle_calls))
|
assert 1 == len(toggle_calls)
|
||||||
call = toggle_calls[-1]
|
call = toggle_calls[-1]
|
||||||
|
|
||||||
self.assertEqual(light.DOMAIN, call.domain)
|
assert light.DOMAIN == call.domain
|
||||||
self.assertEqual(SERVICE_TOGGLE, call.service)
|
assert SERVICE_TOGGLE == call.service
|
||||||
self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID])
|
assert 'entity_id_val' == call.data[ATTR_ENTITY_ID]
|
||||||
self.assertEqual('transition_val', call.data[light.ATTR_TRANSITION])
|
assert 'transition_val' == call.data[light.ATTR_TRANSITION]
|
||||||
|
|
||||||
def test_services(self):
|
def test_services(self):
|
||||||
"""Test the provided services."""
|
"""Test the provided services."""
|
||||||
platform = loader.get_component(self.hass, 'light.test')
|
platform = loader.get_component(self.hass, 'light.test')
|
||||||
|
|
||||||
platform.init()
|
platform.init()
|
||||||
self.assertTrue(
|
assert setup_component(self.hass, light.DOMAIN,
|
||||||
setup_component(self.hass, light.DOMAIN,
|
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
|
||||||
|
|
||||||
dev1, dev2, dev3 = platform.DEVICES
|
dev1, dev2, dev3 = platform.DEVICES
|
||||||
|
|
||||||
# Test init
|
# Test init
|
||||||
self.assertTrue(light.is_on(self.hass, dev1.entity_id))
|
assert light.is_on(self.hass, dev1.entity_id)
|
||||||
self.assertFalse(light.is_on(self.hass, dev2.entity_id))
|
assert not light.is_on(self.hass, dev2.entity_id)
|
||||||
self.assertFalse(light.is_on(self.hass, dev3.entity_id))
|
assert not light.is_on(self.hass, dev3.entity_id)
|
||||||
|
|
||||||
# Test basic turn_on, turn_off, toggle services
|
# Test basic turn_on, turn_off, toggle services
|
||||||
common.turn_off(self.hass, entity_id=dev1.entity_id)
|
common.turn_off(self.hass, entity_id=dev1.entity_id)
|
||||||
|
@ -141,44 +137,44 @@ class TestLight(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertFalse(light.is_on(self.hass, dev1.entity_id))
|
assert not light.is_on(self.hass, dev1.entity_id)
|
||||||
self.assertTrue(light.is_on(self.hass, dev2.entity_id))
|
assert light.is_on(self.hass, dev2.entity_id)
|
||||||
|
|
||||||
# turn on all lights
|
# turn on all lights
|
||||||
common.turn_on(self.hass)
|
common.turn_on(self.hass)
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertTrue(light.is_on(self.hass, dev1.entity_id))
|
assert light.is_on(self.hass, dev1.entity_id)
|
||||||
self.assertTrue(light.is_on(self.hass, dev2.entity_id))
|
assert light.is_on(self.hass, dev2.entity_id)
|
||||||
self.assertTrue(light.is_on(self.hass, dev3.entity_id))
|
assert light.is_on(self.hass, dev3.entity_id)
|
||||||
|
|
||||||
# turn off all lights
|
# turn off all lights
|
||||||
common.turn_off(self.hass)
|
common.turn_off(self.hass)
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertFalse(light.is_on(self.hass, dev1.entity_id))
|
assert not light.is_on(self.hass, dev1.entity_id)
|
||||||
self.assertFalse(light.is_on(self.hass, dev2.entity_id))
|
assert not light.is_on(self.hass, dev2.entity_id)
|
||||||
self.assertFalse(light.is_on(self.hass, dev3.entity_id))
|
assert not light.is_on(self.hass, dev3.entity_id)
|
||||||
|
|
||||||
# toggle all lights
|
# toggle all lights
|
||||||
common.toggle(self.hass)
|
common.toggle(self.hass)
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertTrue(light.is_on(self.hass, dev1.entity_id))
|
assert light.is_on(self.hass, dev1.entity_id)
|
||||||
self.assertTrue(light.is_on(self.hass, dev2.entity_id))
|
assert light.is_on(self.hass, dev2.entity_id)
|
||||||
self.assertTrue(light.is_on(self.hass, dev3.entity_id))
|
assert light.is_on(self.hass, dev3.entity_id)
|
||||||
|
|
||||||
# toggle all lights
|
# toggle all lights
|
||||||
common.toggle(self.hass)
|
common.toggle(self.hass)
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertFalse(light.is_on(self.hass, dev1.entity_id))
|
assert not light.is_on(self.hass, dev1.entity_id)
|
||||||
self.assertFalse(light.is_on(self.hass, dev2.entity_id))
|
assert not light.is_on(self.hass, dev2.entity_id)
|
||||||
self.assertFalse(light.is_on(self.hass, dev3.entity_id))
|
assert not light.is_on(self.hass, dev3.entity_id)
|
||||||
|
|
||||||
# Ensure all attributes process correctly
|
# Ensure all attributes process correctly
|
||||||
common.turn_on(self.hass, dev1.entity_id,
|
common.turn_on(self.hass, dev1.entity_id,
|
||||||
|
@ -191,22 +187,22 @@ class TestLight(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
_, data = dev1.last_call('turn_on')
|
_, data = dev1.last_call('turn_on')
|
||||||
self.assertEqual({
|
assert {
|
||||||
light.ATTR_TRANSITION: 10,
|
light.ATTR_TRANSITION: 10,
|
||||||
light.ATTR_BRIGHTNESS: 20,
|
light.ATTR_BRIGHTNESS: 20,
|
||||||
light.ATTR_HS_COLOR: (240, 100),
|
light.ATTR_HS_COLOR: (240, 100),
|
||||||
}, data)
|
} == data
|
||||||
|
|
||||||
_, data = dev2.last_call('turn_on')
|
_, data = dev2.last_call('turn_on')
|
||||||
self.assertEqual({
|
assert {
|
||||||
light.ATTR_HS_COLOR: (0, 0),
|
light.ATTR_HS_COLOR: (0, 0),
|
||||||
light.ATTR_WHITE_VALUE: 255,
|
light.ATTR_WHITE_VALUE: 255,
|
||||||
}, data)
|
} == data
|
||||||
|
|
||||||
_, data = dev3.last_call('turn_on')
|
_, data = dev3.last_call('turn_on')
|
||||||
self.assertEqual({
|
assert {
|
||||||
light.ATTR_HS_COLOR: (71.059, 100),
|
light.ATTR_HS_COLOR: (71.059, 100),
|
||||||
}, data)
|
} == data
|
||||||
|
|
||||||
# One of the light profiles
|
# One of the light profiles
|
||||||
prof_name, prof_h, prof_s, prof_bri = 'relax', 35.932, 69.412, 144
|
prof_name, prof_h, prof_s, prof_bri = 'relax', 35.932, 69.412, 144
|
||||||
|
@ -221,16 +217,16 @@ class TestLight(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
_, data = dev1.last_call('turn_on')
|
_, data = dev1.last_call('turn_on')
|
||||||
self.assertEqual({
|
assert {
|
||||||
light.ATTR_BRIGHTNESS: prof_bri,
|
light.ATTR_BRIGHTNESS: prof_bri,
|
||||||
light.ATTR_HS_COLOR: (prof_h, prof_s),
|
light.ATTR_HS_COLOR: (prof_h, prof_s),
|
||||||
}, data)
|
} == data
|
||||||
|
|
||||||
_, data = dev2.last_call('turn_on')
|
_, data = dev2.last_call('turn_on')
|
||||||
self.assertEqual({
|
assert {
|
||||||
light.ATTR_BRIGHTNESS: 100,
|
light.ATTR_BRIGHTNESS: 100,
|
||||||
light.ATTR_HS_COLOR: (prof_h, prof_s),
|
light.ATTR_HS_COLOR: (prof_h, prof_s),
|
||||||
}, data)
|
} == data
|
||||||
|
|
||||||
# Test bad data
|
# Test bad data
|
||||||
common.turn_on(self.hass)
|
common.turn_on(self.hass)
|
||||||
|
@ -241,13 +237,13 @@ class TestLight(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
_, data = dev1.last_call('turn_on')
|
_, data = dev1.last_call('turn_on')
|
||||||
self.assertEqual({}, data)
|
assert {} == data
|
||||||
|
|
||||||
_, data = dev2.last_call('turn_on')
|
_, data = dev2.last_call('turn_on')
|
||||||
self.assertEqual({}, data)
|
assert {} == data
|
||||||
|
|
||||||
_, data = dev3.last_call('turn_on')
|
_, data = dev3.last_call('turn_on')
|
||||||
self.assertEqual({}, data)
|
assert {} == data
|
||||||
|
|
||||||
# faulty attributes will not trigger a service call
|
# faulty attributes will not trigger a service call
|
||||||
common.turn_on(
|
common.turn_on(
|
||||||
|
@ -263,10 +259,10 @@ class TestLight(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
_, data = dev1.last_call('turn_on')
|
_, data = dev1.last_call('turn_on')
|
||||||
self.assertEqual({}, data)
|
assert {} == data
|
||||||
|
|
||||||
_, data = dev2.last_call('turn_on')
|
_, data = dev2.last_call('turn_on')
|
||||||
self.assertEqual({}, data)
|
assert {} == data
|
||||||
|
|
||||||
def test_broken_light_profiles(self):
|
def test_broken_light_profiles(self):
|
||||||
"""Test light profiles."""
|
"""Test light profiles."""
|
||||||
|
@ -280,8 +276,8 @@ class TestLight(unittest.TestCase):
|
||||||
user_file.write('id,x,y,brightness\n')
|
user_file.write('id,x,y,brightness\n')
|
||||||
user_file.write('I,WILL,NOT,WORK\n')
|
user_file.write('I,WILL,NOT,WORK\n')
|
||||||
|
|
||||||
self.assertFalse(setup_component(
|
assert not setup_component(
|
||||||
self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||||
|
|
||||||
def test_light_profiles(self):
|
def test_light_profiles(self):
|
||||||
"""Test light profiles."""
|
"""Test light profiles."""
|
||||||
|
@ -294,9 +290,9 @@ class TestLight(unittest.TestCase):
|
||||||
user_file.write('id,x,y,brightness\n')
|
user_file.write('id,x,y,brightness\n')
|
||||||
user_file.write('test,.4,.6,100\n')
|
user_file.write('test,.4,.6,100\n')
|
||||||
|
|
||||||
self.assertTrue(setup_component(
|
assert setup_component(
|
||||||
self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: 'test'}}
|
self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: 'test'}}
|
||||||
))
|
)
|
||||||
|
|
||||||
dev1, _, _ = platform.DEVICES
|
dev1, _, _ = platform.DEVICES
|
||||||
|
|
||||||
|
@ -306,10 +302,10 @@ class TestLight(unittest.TestCase):
|
||||||
|
|
||||||
_, data = dev1.last_call('turn_on')
|
_, data = dev1.last_call('turn_on')
|
||||||
|
|
||||||
self.assertEqual({
|
assert {
|
||||||
light.ATTR_HS_COLOR: (71.059, 100),
|
light.ATTR_HS_COLOR: (71.059, 100),
|
||||||
light.ATTR_BRIGHTNESS: 100
|
light.ATTR_BRIGHTNESS: 100
|
||||||
}, data)
|
} == data
|
||||||
|
|
||||||
def test_default_profiles_group(self):
|
def test_default_profiles_group(self):
|
||||||
"""Test default turn-on light profile for all lights."""
|
"""Test default turn-on light profile for all lights."""
|
||||||
|
@ -335,19 +331,19 @@ class TestLight(unittest.TestCase):
|
||||||
with mock.patch('os.path.isfile', side_effect=_mock_isfile):
|
with mock.patch('os.path.isfile', side_effect=_mock_isfile):
|
||||||
with mock.patch('builtins.open', side_effect=_mock_open):
|
with mock.patch('builtins.open', side_effect=_mock_open):
|
||||||
with mock_storage():
|
with mock_storage():
|
||||||
self.assertTrue(setup_component(
|
assert setup_component(
|
||||||
self.hass, light.DOMAIN,
|
self.hass, light.DOMAIN,
|
||||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}
|
{light.DOMAIN: {CONF_PLATFORM: 'test'}}
|
||||||
))
|
)
|
||||||
|
|
||||||
dev, _, _ = platform.DEVICES
|
dev, _, _ = platform.DEVICES
|
||||||
common.turn_on(self.hass, dev.entity_id)
|
common.turn_on(self.hass, dev.entity_id)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
_, data = dev.last_call('turn_on')
|
_, data = dev.last_call('turn_on')
|
||||||
self.assertEqual({
|
assert {
|
||||||
light.ATTR_HS_COLOR: (71.059, 100),
|
light.ATTR_HS_COLOR: (71.059, 100),
|
||||||
light.ATTR_BRIGHTNESS: 99
|
light.ATTR_BRIGHTNESS: 99
|
||||||
}, data)
|
} == data
|
||||||
|
|
||||||
def test_default_profiles_light(self):
|
def test_default_profiles_light(self):
|
||||||
"""Test default turn-on light profile for a specific light."""
|
"""Test default turn-on light profile for a specific light."""
|
||||||
|
@ -374,20 +370,20 @@ class TestLight(unittest.TestCase):
|
||||||
with mock.patch('os.path.isfile', side_effect=_mock_isfile):
|
with mock.patch('os.path.isfile', side_effect=_mock_isfile):
|
||||||
with mock.patch('builtins.open', side_effect=_mock_open):
|
with mock.patch('builtins.open', side_effect=_mock_open):
|
||||||
with mock_storage():
|
with mock_storage():
|
||||||
self.assertTrue(setup_component(
|
assert setup_component(
|
||||||
self.hass, light.DOMAIN,
|
self.hass, light.DOMAIN,
|
||||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}
|
{light.DOMAIN: {CONF_PLATFORM: 'test'}}
|
||||||
))
|
)
|
||||||
|
|
||||||
dev = next(filter(lambda x: x.entity_id == 'light.ceiling_2',
|
dev = next(filter(lambda x: x.entity_id == 'light.ceiling_2',
|
||||||
platform.DEVICES))
|
platform.DEVICES))
|
||||||
common.turn_on(self.hass, dev.entity_id)
|
common.turn_on(self.hass, dev.entity_id)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
_, data = dev.last_call('turn_on')
|
_, data = dev.last_call('turn_on')
|
||||||
self.assertEqual({
|
assert {
|
||||||
light.ATTR_HS_COLOR: (50.353, 100),
|
light.ATTR_HS_COLOR: (50.353, 100),
|
||||||
light.ATTR_BRIGHTNESS: 100
|
light.ATTR_BRIGHTNESS: 100
|
||||||
}, data)
|
} == data
|
||||||
|
|
||||||
|
|
||||||
async def test_intent_set_color(hass):
|
async def test_intent_set_color(hass):
|
||||||
|
|
|
@ -50,7 +50,7 @@ class TestMochadSwitchSetup(unittest.TestCase):
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.assertTrue(setup_component(self.hass, light.DOMAIN, good_config))
|
assert setup_component(self.hass, light.DOMAIN, good_config)
|
||||||
|
|
||||||
|
|
||||||
class TestMochadLight(unittest.TestCase):
|
class TestMochadLight(unittest.TestCase):
|
||||||
|
@ -71,7 +71,7 @@ class TestMochadLight(unittest.TestCase):
|
||||||
|
|
||||||
def test_name(self):
|
def test_name(self):
|
||||||
"""Test the name."""
|
"""Test the name."""
|
||||||
self.assertEqual('fake_light', self.light.name)
|
assert 'fake_light' == self.light.name
|
||||||
|
|
||||||
def test_turn_on_with_no_brightness(self):
|
def test_turn_on_with_no_brightness(self):
|
||||||
"""Test turn_on."""
|
"""Test turn_on."""
|
||||||
|
|
|
@ -193,7 +193,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
self.assertIsNone(self.hass.states.get('light.test'))
|
assert self.hass.states.get('light.test') is None
|
||||||
|
|
||||||
def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(self):
|
def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(self):
|
||||||
"""Test if there is no color and brightness if no topic."""
|
"""Test if there is no color and brightness if no topic."""
|
||||||
|
@ -208,25 +208,25 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
assert state.attributes.get('rgb_color') is None
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertIsNone(state.attributes.get('color_temp'))
|
assert state.attributes.get('color_temp') is None
|
||||||
self.assertIsNone(state.attributes.get('hs_color'))
|
assert state.attributes.get('hs_color') is None
|
||||||
self.assertIsNone(state.attributes.get('white_value'))
|
assert state.attributes.get('white_value') is None
|
||||||
self.assertIsNone(state.attributes.get('xy_color'))
|
assert state.attributes.get('xy_color') is None
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
assert state.attributes.get('rgb_color') is None
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertIsNone(state.attributes.get('color_temp'))
|
assert state.attributes.get('color_temp') is None
|
||||||
self.assertIsNone(state.attributes.get('hs_color'))
|
assert state.attributes.get('hs_color') is None
|
||||||
self.assertIsNone(state.attributes.get('white_value'))
|
assert state.attributes.get('white_value') is None
|
||||||
self.assertIsNone(state.attributes.get('xy_color'))
|
assert state.attributes.get('xy_color') is None
|
||||||
|
|
||||||
def test_controlling_state_via_topic(self):
|
def test_controlling_state_via_topic(self):
|
||||||
"""Test the controlling of the state via topic."""
|
"""Test the controlling of the state via topic."""
|
||||||
|
@ -258,34 +258,34 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
assert setup_component(self.hass, light.DOMAIN, config)
|
assert setup_component(self.hass, light.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
assert state.attributes.get('rgb_color') is None
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertIsNone(state.attributes.get('color_temp'))
|
assert state.attributes.get('color_temp') is None
|
||||||
self.assertIsNone(state.attributes.get('effect'))
|
assert state.attributes.get('effect') is None
|
||||||
self.assertIsNone(state.attributes.get('hs_color'))
|
assert state.attributes.get('hs_color') is None
|
||||||
self.assertIsNone(state.attributes.get('white_value'))
|
assert state.attributes.get('white_value') is None
|
||||||
self.assertIsNone(state.attributes.get('xy_color'))
|
assert state.attributes.get('xy_color') is None
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', '1')
|
fire_mqtt_message(self.hass, 'test_light_rgb/status', '1')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual((255, 255, 255), state.attributes.get('rgb_color'))
|
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||||
self.assertEqual(255, state.attributes.get('brightness'))
|
assert 255 == state.attributes.get('brightness')
|
||||||
self.assertEqual(150, state.attributes.get('color_temp'))
|
assert 150 == state.attributes.get('color_temp')
|
||||||
self.assertEqual('none', state.attributes.get('effect'))
|
assert 'none' == state.attributes.get('effect')
|
||||||
self.assertEqual((0, 0), state.attributes.get('hs_color'))
|
assert (0, 0) == state.attributes.get('hs_color')
|
||||||
self.assertEqual(255, state.attributes.get('white_value'))
|
assert 255 == state.attributes.get('white_value')
|
||||||
self.assertEqual((0.323, 0.329), state.attributes.get('xy_color'))
|
assert (0.323, 0.329) == state.attributes.get('xy_color')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', '0')
|
fire_mqtt_message(self.hass, 'test_light_rgb/status', '0')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', '1')
|
fire_mqtt_message(self.hass, 'test_light_rgb/status', '1')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
@ -295,20 +295,20 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(100,
|
assert 100 == \
|
||||||
light_state.attributes['brightness'])
|
light_state.attributes['brightness']
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/color_temp/status', '300')
|
fire_mqtt_message(self.hass, 'test_light_rgb/color_temp/status', '300')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(300, light_state.attributes['color_temp'])
|
assert 300 == light_state.attributes['color_temp']
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/effect/status', 'rainbow')
|
fire_mqtt_message(self.hass, 'test_light_rgb/effect/status', 'rainbow')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual('rainbow', light_state.attributes['effect'])
|
assert 'rainbow' == light_state.attributes['effect']
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/white_value/status',
|
fire_mqtt_message(self.hass, 'test_light_rgb/white_value/status',
|
||||||
'100')
|
'100')
|
||||||
|
@ -316,8 +316,8 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(100,
|
assert 100 == \
|
||||||
light_state.attributes['white_value'])
|
light_state.attributes['white_value']
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', '1')
|
fire_mqtt_message(self.hass, 'test_light_rgb/status', '1')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
@ -327,24 +327,24 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.assertEqual((255, 255, 255),
|
assert (255, 255, 255) == \
|
||||||
light_state.attributes.get('rgb_color'))
|
light_state.attributes.get('rgb_color')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/hs/status',
|
fire_mqtt_message(self.hass, 'test_light_rgb/hs/status',
|
||||||
'200,50')
|
'200,50')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.assertEqual((200, 50),
|
assert (200, 50) == \
|
||||||
light_state.attributes.get('hs_color'))
|
light_state.attributes.get('hs_color')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/xy/status',
|
fire_mqtt_message(self.hass, 'test_light_rgb/xy/status',
|
||||||
'0.675,0.322')
|
'0.675,0.322')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.assertEqual((0.672, 0.324),
|
assert (0.672, 0.324) == \
|
||||||
light_state.attributes.get('xy_color'))
|
light_state.attributes.get('xy_color')
|
||||||
|
|
||||||
def test_brightness_controlling_scale(self):
|
def test_brightness_controlling_scale(self):
|
||||||
"""Test the brightness controlling scale."""
|
"""Test the brightness controlling scale."""
|
||||||
|
@ -365,22 +365,22 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_scale/status', 'on')
|
fire_mqtt_message(self.hass, 'test_scale/status', 'on')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(255, state.attributes.get('brightness'))
|
assert 255 == state.attributes.get('brightness')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_scale/status', 'off')
|
fire_mqtt_message(self.hass, 'test_scale/status', 'off')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_scale/status', 'on')
|
fire_mqtt_message(self.hass, 'test_scale/status', 'on')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
@ -390,8 +390,8 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(255,
|
assert 255 == \
|
||||||
light_state.attributes['brightness'])
|
light_state.attributes['brightness']
|
||||||
|
|
||||||
def test_brightness_from_rgb_controlling_scale(self):
|
def test_brightness_from_rgb_controlling_scale(self):
|
||||||
"""Test the brightness controlling scale."""
|
"""Test the brightness controlling scale."""
|
||||||
|
@ -411,22 +411,22 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_scale_rgb/status', 'on')
|
fire_mqtt_message(self.hass, 'test_scale_rgb/status', 'on')
|
||||||
fire_mqtt_message(self.hass, 'test_scale_rgb/rgb/status', '255,0,0')
|
fire_mqtt_message(self.hass, 'test_scale_rgb/rgb/status', '255,0,0')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(255, state.attributes.get('brightness'))
|
assert 255 == state.attributes.get('brightness')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_scale_rgb/rgb/status', '127,0,0')
|
fire_mqtt_message(self.hass, 'test_scale_rgb/rgb/status', '127,0,0')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(127, state.attributes.get('brightness'))
|
assert 127 == state.attributes.get('brightness')
|
||||||
|
|
||||||
def test_white_value_controlling_scale(self):
|
def test_white_value_controlling_scale(self):
|
||||||
"""Test the white_value controlling scale."""
|
"""Test the white_value controlling scale."""
|
||||||
|
@ -447,22 +447,22 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('white_value'))
|
assert state.attributes.get('white_value') is None
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_scale/status', 'on')
|
fire_mqtt_message(self.hass, 'test_scale/status', 'on')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(255, state.attributes.get('white_value'))
|
assert 255 == state.attributes.get('white_value')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_scale/status', 'off')
|
fire_mqtt_message(self.hass, 'test_scale/status', 'off')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_scale/status', 'on')
|
fire_mqtt_message(self.hass, 'test_scale/status', 'on')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
@ -472,8 +472,8 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(255,
|
assert 255 == \
|
||||||
light_state.attributes['white_value'])
|
light_state.attributes['white_value']
|
||||||
|
|
||||||
def test_controlling_state_via_topic_with_templates(self):
|
def test_controlling_state_via_topic_with_templates(self):
|
||||||
"""Test the setting of the state with a template."""
|
"""Test the setting of the state with a template."""
|
||||||
|
@ -510,9 +510,9 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
assert setup_component(self.hass, light.DOMAIN, config)
|
assert setup_component(self.hass, light.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
assert state.attributes.get('rgb_color') is None
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/rgb/status',
|
fire_mqtt_message(self.hass, 'test_light_rgb/rgb/status',
|
||||||
'{"hello": [1, 2, 3]}')
|
'{"hello": [1, 2, 3]}')
|
||||||
|
@ -529,26 +529,26 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(50, state.attributes.get('brightness'))
|
assert 50 == state.attributes.get('brightness')
|
||||||
self.assertEqual((84, 169, 255), state.attributes.get('rgb_color'))
|
assert (84, 169, 255) == state.attributes.get('rgb_color')
|
||||||
self.assertEqual(300, state.attributes.get('color_temp'))
|
assert 300 == state.attributes.get('color_temp')
|
||||||
self.assertEqual('rainbow', state.attributes.get('effect'))
|
assert 'rainbow' == state.attributes.get('effect')
|
||||||
self.assertEqual(75, state.attributes.get('white_value'))
|
assert 75 == state.attributes.get('white_value')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/hs/status',
|
fire_mqtt_message(self.hass, 'test_light_rgb/hs/status',
|
||||||
'{"hello": [100,50]}')
|
'{"hello": [100,50]}')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual((100, 50), state.attributes.get('hs_color'))
|
assert (100, 50) == state.attributes.get('hs_color')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/xy/status',
|
fire_mqtt_message(self.hass, 'test_light_rgb/xy/status',
|
||||||
'{"hello": [0.123,0.123]}')
|
'{"hello": [0.123,0.123]}')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual((0.14, 0.131), state.attributes.get('xy_color'))
|
assert (0.14, 0.131) == state.attributes.get('xy_color')
|
||||||
|
|
||||||
def test_sending_mqtt_commands_and_optimistic(self):
|
def test_sending_mqtt_commands_and_optimistic(self):
|
||||||
"""Test the sending of command in optimistic mode."""
|
"""Test the sending of command in optimistic mode."""
|
||||||
|
@ -579,13 +579,13 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
assert setup_component(self.hass, light.DOMAIN, config)
|
assert setup_component(self.hass, light.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(95, state.attributes.get('brightness'))
|
assert 95 == state.attributes.get('brightness')
|
||||||
self.assertEqual((100, 100), state.attributes.get('hs_color'))
|
assert (100, 100) == state.attributes.get('hs_color')
|
||||||
self.assertEqual('random', state.attributes.get('effect'))
|
assert 'random' == state.attributes.get('effect')
|
||||||
self.assertEqual(100, state.attributes.get('color_temp'))
|
assert 100 == state.attributes.get('color_temp')
|
||||||
self.assertEqual(50, state.attributes.get('white_value'))
|
assert 50 == state.attributes.get('white_value')
|
||||||
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
common.turn_on(self.hass, 'light.test')
|
common.turn_on(self.hass, 'light.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
@ -594,7 +594,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
'test_light_rgb/set', 'on', 2, False)
|
'test_light_rgb/set', 'on', 2, False)
|
||||||
self.mock_publish.async_publish.reset_mock()
|
self.mock_publish.async_publish.reset_mock()
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
|
|
||||||
common.turn_off(self.hass, 'light.test')
|
common.turn_off(self.hass, 'light.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
@ -603,7 +603,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
'test_light_rgb/set', 'off', 2, False)
|
'test_light_rgb/set', 'off', 2, False)
|
||||||
self.mock_publish.async_publish.reset_mock()
|
self.mock_publish.async_publish.reset_mock()
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
self.mock_publish.reset_mock()
|
self.mock_publish.reset_mock()
|
||||||
common.turn_on(self.hass, 'light.test',
|
common.turn_on(self.hass, 'light.test',
|
||||||
|
@ -624,12 +624,12 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
], any_order=True)
|
], any_order=True)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual((255, 128, 0), state.attributes['rgb_color'])
|
assert (255, 128, 0) == state.attributes['rgb_color']
|
||||||
self.assertEqual(50, state.attributes['brightness'])
|
assert 50 == state.attributes['brightness']
|
||||||
self.assertEqual((30.118, 100), state.attributes['hs_color'])
|
assert (30.118, 100) == state.attributes['hs_color']
|
||||||
self.assertEqual(80, state.attributes['white_value'])
|
assert 80 == state.attributes['white_value']
|
||||||
self.assertEqual((0.611, 0.375), state.attributes['xy_color'])
|
assert (0.611, 0.375) == state.attributes['xy_color']
|
||||||
|
|
||||||
def test_sending_mqtt_rgb_command_with_template(self):
|
def test_sending_mqtt_rgb_command_with_template(self):
|
||||||
"""Test the sending of RGB command with template."""
|
"""Test the sending of RGB command with template."""
|
||||||
|
@ -649,7 +649,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
assert setup_component(self.hass, light.DOMAIN, config)
|
assert setup_component(self.hass, light.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
common.turn_on(self.hass, 'light.test', rgb_color=[255, 128, 64])
|
common.turn_on(self.hass, 'light.test', rgb_color=[255, 128, 64])
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
@ -660,8 +660,8 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
], any_order=True)
|
], any_order=True)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual((255, 128, 63), state.attributes['rgb_color'])
|
assert (255, 128, 63) == state.attributes['rgb_color']
|
||||||
|
|
||||||
def test_show_brightness_if_only_command_topic(self):
|
def test_show_brightness_if_only_command_topic(self):
|
||||||
"""Test the brightness if only a command topic is present."""
|
"""Test the brightness if only a command topic is present."""
|
||||||
|
@ -677,15 +677,15 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
assert setup_component(self.hass, light.DOMAIN, config)
|
assert setup_component(self.hass, light.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(255, state.attributes.get('brightness'))
|
assert 255 == state.attributes.get('brightness')
|
||||||
|
|
||||||
def test_show_color_temp_only_if_command_topic(self):
|
def test_show_color_temp_only_if_command_topic(self):
|
||||||
"""Test the color temp only if a command topic is present."""
|
"""Test the color temp only if a command topic is present."""
|
||||||
|
@ -701,15 +701,15 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
assert setup_component(self.hass, light.DOMAIN, config)
|
assert setup_component(self.hass, light.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('color_temp'))
|
assert state.attributes.get('color_temp') is None
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(150, state.attributes.get('color_temp'))
|
assert 150 == state.attributes.get('color_temp')
|
||||||
|
|
||||||
def test_show_effect_only_if_command_topic(self):
|
def test_show_effect_only_if_command_topic(self):
|
||||||
"""Test the color temp only if a command topic is present."""
|
"""Test the color temp only if a command topic is present."""
|
||||||
|
@ -725,15 +725,15 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
assert setup_component(self.hass, light.DOMAIN, config)
|
assert setup_component(self.hass, light.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('effect'))
|
assert state.attributes.get('effect') is None
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual('none', state.attributes.get('effect'))
|
assert 'none' == state.attributes.get('effect')
|
||||||
|
|
||||||
def test_show_hs_if_only_command_topic(self):
|
def test_show_hs_if_only_command_topic(self):
|
||||||
"""Test the hs if only a command topic is present."""
|
"""Test the hs if only a command topic is present."""
|
||||||
|
@ -749,15 +749,15 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
assert setup_component(self.hass, light.DOMAIN, config)
|
assert setup_component(self.hass, light.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('hs_color'))
|
assert state.attributes.get('hs_color') is None
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual((0, 0), state.attributes.get('hs_color'))
|
assert (0, 0) == state.attributes.get('hs_color')
|
||||||
|
|
||||||
def test_show_white_value_if_only_command_topic(self):
|
def test_show_white_value_if_only_command_topic(self):
|
||||||
"""Test the white_value if only a command topic is present."""
|
"""Test the white_value if only a command topic is present."""
|
||||||
|
@ -773,15 +773,15 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
assert setup_component(self.hass, light.DOMAIN, config)
|
assert setup_component(self.hass, light.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('white_value'))
|
assert state.attributes.get('white_value') is None
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(255, state.attributes.get('white_value'))
|
assert 255 == state.attributes.get('white_value')
|
||||||
|
|
||||||
def test_show_xy_if_only_command_topic(self):
|
def test_show_xy_if_only_command_topic(self):
|
||||||
"""Test the xy if only a command topic is present."""
|
"""Test the xy if only a command topic is present."""
|
||||||
|
@ -797,15 +797,15 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
assert setup_component(self.hass, light.DOMAIN, config)
|
assert setup_component(self.hass, light.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('xy_color'))
|
assert state.attributes.get('xy_color') is None
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual((0.323, 0.329), state.attributes.get('xy_color'))
|
assert (0.323, 0.329) == state.attributes.get('xy_color')
|
||||||
|
|
||||||
def test_on_command_first(self):
|
def test_on_command_first(self):
|
||||||
"""Test on command being sent before brightness."""
|
"""Test on command being sent before brightness."""
|
||||||
|
@ -821,7 +821,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
assert setup_component(self.hass, light.DOMAIN, config)
|
assert setup_component(self.hass, light.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
common.turn_on(self.hass, 'light.test', brightness=50)
|
common.turn_on(self.hass, 'light.test', brightness=50)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
@ -854,7 +854,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
assert setup_component(self.hass, light.DOMAIN, config)
|
assert setup_component(self.hass, light.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
common.turn_on(self.hass, 'light.test', brightness=50)
|
common.turn_on(self.hass, 'light.test', brightness=50)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
@ -889,7 +889,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
assert setup_component(self.hass, light.DOMAIN, config)
|
assert setup_component(self.hass, light.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
# Turn on w/ no brightness - should set to max
|
# Turn on w/ no brightness - should set to max
|
||||||
common.turn_on(self.hass, 'light.test')
|
common.turn_on(self.hass, 'light.test')
|
||||||
|
@ -942,7 +942,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
assert setup_component(self.hass, light.DOMAIN, config)
|
assert setup_component(self.hass, light.DOMAIN, config)
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
common.turn_on(self.hass, 'light.test', brightness=127)
|
common.turn_on(self.hass, 'light.test', brightness=127)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
@ -964,7 +964,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
|
|
||||||
def test_default_availability_payload(self):
|
def test_default_availability_payload(self):
|
||||||
"""Test availability by default payload with defined topic."""
|
"""Test availability by default payload with defined topic."""
|
||||||
self.assertTrue(setup_component(self.hass, light.DOMAIN, {
|
assert setup_component(self.hass, light.DOMAIN, {
|
||||||
light.DOMAIN: {
|
light.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -973,26 +973,26 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
'rgb_command_topic': "test_light/rgb",
|
'rgb_command_topic': "test_light/rgb",
|
||||||
'availability_topic': 'availability-topic'
|
'availability_topic': 'availability-topic'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
def test_custom_availability_payload(self):
|
def test_custom_availability_payload(self):
|
||||||
"""Test availability by custom payload with defined topic."""
|
"""Test availability by custom payload with defined topic."""
|
||||||
self.assertTrue(setup_component(self.hass, light.DOMAIN, {
|
assert setup_component(self.hass, light.DOMAIN, {
|
||||||
light.DOMAIN: {
|
light.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -1003,22 +1003,22 @@ class TestLightMQTT(unittest.TestCase):
|
||||||
'payload_available': 'good',
|
'payload_available': 'good',
|
||||||
'payload_not_available': 'nogood'
|
'payload_not_available': 'nogood'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_light(hass, mqtt_mock, caplog):
|
async def test_discovery_removal_light(hass, mqtt_mock, caplog):
|
||||||
|
|
|
@ -127,7 +127,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
self.assertIsNone(self.hass.states.get('light.test'))
|
assert self.hass.states.get('light.test') is None
|
||||||
|
|
||||||
def test_no_color_brightness_color_temp_white_val_if_no_topics(self):
|
def test_no_color_brightness_color_temp_white_val_if_no_topics(self):
|
||||||
"""Test for no RGB, brightness, color temp, effect, white val or XY."""
|
"""Test for no RGB, brightness, color temp, effect, white val or XY."""
|
||||||
|
@ -141,28 +141,28 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertEqual(40, state.attributes.get(ATTR_SUPPORTED_FEATURES))
|
assert 40 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
assert state.attributes.get('rgb_color') is None
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertIsNone(state.attributes.get('color_temp'))
|
assert state.attributes.get('color_temp') is None
|
||||||
self.assertIsNone(state.attributes.get('effect'))
|
assert state.attributes.get('effect') is None
|
||||||
self.assertIsNone(state.attributes.get('white_value'))
|
assert state.attributes.get('white_value') is None
|
||||||
self.assertIsNone(state.attributes.get('xy_color'))
|
assert state.attributes.get('xy_color') is None
|
||||||
self.assertIsNone(state.attributes.get('hs_color'))
|
assert state.attributes.get('hs_color') is None
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"ON"}')
|
fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"ON"}')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
assert state.attributes.get('rgb_color') is None
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertIsNone(state.attributes.get('color_temp'))
|
assert state.attributes.get('color_temp') is None
|
||||||
self.assertIsNone(state.attributes.get('effect'))
|
assert state.attributes.get('effect') is None
|
||||||
self.assertIsNone(state.attributes.get('white_value'))
|
assert state.attributes.get('white_value') is None
|
||||||
self.assertIsNone(state.attributes.get('xy_color'))
|
assert state.attributes.get('xy_color') is None
|
||||||
self.assertIsNone(state.attributes.get('hs_color'))
|
assert state.attributes.get('hs_color') is None
|
||||||
|
|
||||||
def test_controlling_state_via_topic(self):
|
def test_controlling_state_via_topic(self):
|
||||||
"""Test the controlling of the state via topic."""
|
"""Test the controlling of the state via topic."""
|
||||||
|
@ -184,16 +184,16 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertEqual(191, state.attributes.get(ATTR_SUPPORTED_FEATURES))
|
assert 191 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
assert state.attributes.get('rgb_color') is None
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertIsNone(state.attributes.get('color_temp'))
|
assert state.attributes.get('color_temp') is None
|
||||||
self.assertIsNone(state.attributes.get('effect'))
|
assert state.attributes.get('effect') is None
|
||||||
self.assertIsNone(state.attributes.get('white_value'))
|
assert state.attributes.get('white_value') is None
|
||||||
self.assertIsNone(state.attributes.get('xy_color'))
|
assert state.attributes.get('xy_color') is None
|
||||||
self.assertIsNone(state.attributes.get('hs_color'))
|
assert state.attributes.get('hs_color') is None
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
# Turn on the light, full white
|
# Turn on the light, full white
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
|
@ -206,21 +206,21 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual((255, 255, 255), state.attributes.get('rgb_color'))
|
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||||
self.assertEqual(255, state.attributes.get('brightness'))
|
assert 255 == state.attributes.get('brightness')
|
||||||
self.assertEqual(155, state.attributes.get('color_temp'))
|
assert 155 == state.attributes.get('color_temp')
|
||||||
self.assertEqual('colorloop', state.attributes.get('effect'))
|
assert 'colorloop' == state.attributes.get('effect')
|
||||||
self.assertEqual(150, state.attributes.get('white_value'))
|
assert 150 == state.attributes.get('white_value')
|
||||||
self.assertEqual((0.323, 0.329), state.attributes.get('xy_color'))
|
assert (0.323, 0.329) == state.attributes.get('xy_color')
|
||||||
self.assertEqual((0.0, 0.0), state.attributes.get('hs_color'))
|
assert (0.0, 0.0) == state.attributes.get('hs_color')
|
||||||
|
|
||||||
# Turn the light off
|
# Turn the light off
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"OFF"}')
|
fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"OFF"}')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
'{"state":"ON",'
|
'{"state":"ON",'
|
||||||
|
@ -229,8 +229,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(100,
|
assert 100 == \
|
||||||
light_state.attributes['brightness'])
|
light_state.attributes['brightness']
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
'{"state":"ON",'
|
'{"state":"ON",'
|
||||||
|
@ -238,8 +238,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.assertEqual((255, 255, 255),
|
assert (255, 255, 255) == \
|
||||||
light_state.attributes.get('rgb_color'))
|
light_state.attributes.get('rgb_color')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
'{"state":"ON",'
|
'{"state":"ON",'
|
||||||
|
@ -247,8 +247,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.assertEqual((0.141, 0.14),
|
assert (0.141, 0.14) == \
|
||||||
light_state.attributes.get('xy_color'))
|
light_state.attributes.get('xy_color')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
'{"state":"ON",'
|
'{"state":"ON",'
|
||||||
|
@ -256,8 +256,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.assertEqual((180.0, 50.0),
|
assert (180.0, 50.0) == \
|
||||||
light_state.attributes.get('hs_color'))
|
light_state.attributes.get('hs_color')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
'{"state":"ON",'
|
'{"state":"ON",'
|
||||||
|
@ -265,7 +265,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(155, light_state.attributes.get('color_temp'))
|
assert 155 == light_state.attributes.get('color_temp')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
'{"state":"ON",'
|
'{"state":"ON",'
|
||||||
|
@ -273,7 +273,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.assertEqual('colorloop', light_state.attributes.get('effect'))
|
assert 'colorloop' == light_state.attributes.get('effect')
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
'{"state":"ON",'
|
'{"state":"ON",'
|
||||||
|
@ -281,7 +281,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(155, light_state.attributes.get('white_value'))
|
assert 155 == light_state.attributes.get('white_value')
|
||||||
|
|
||||||
def test_sending_mqtt_commands_and_optimistic(self):
|
def test_sending_mqtt_commands_and_optimistic(self):
|
||||||
"""Test the sending of command in optimistic mode."""
|
"""Test the sending of command in optimistic mode."""
|
||||||
|
@ -309,14 +309,14 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(95, state.attributes.get('brightness'))
|
assert 95 == state.attributes.get('brightness')
|
||||||
self.assertEqual((100, 100), state.attributes.get('hs_color'))
|
assert (100, 100) == state.attributes.get('hs_color')
|
||||||
self.assertEqual('random', state.attributes.get('effect'))
|
assert 'random' == state.attributes.get('effect')
|
||||||
self.assertEqual(100, state.attributes.get('color_temp'))
|
assert 100 == state.attributes.get('color_temp')
|
||||||
self.assertEqual(50, state.attributes.get('white_value'))
|
assert 50 == state.attributes.get('white_value')
|
||||||
self.assertEqual(191, state.attributes.get(ATTR_SUPPORTED_FEATURES))
|
assert 191 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||||
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
common.turn_on(self.hass, 'light.test')
|
common.turn_on(self.hass, 'light.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
@ -325,7 +325,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
'test_light_rgb/set', '{"state": "ON"}', 2, False)
|
'test_light_rgb/set', '{"state": "ON"}', 2, False)
|
||||||
self.mock_publish.async_publish.reset_mock()
|
self.mock_publish.async_publish.reset_mock()
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
|
|
||||||
common.turn_off(self.hass, 'light.test')
|
common.turn_off(self.hass, 'light.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
@ -334,61 +334,59 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
'test_light_rgb/set', '{"state": "OFF"}', 2, False)
|
'test_light_rgb/set', '{"state": "OFF"}', 2, False)
|
||||||
self.mock_publish.async_publish.reset_mock()
|
self.mock_publish.async_publish.reset_mock()
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
common.turn_on(self.hass, 'light.test',
|
common.turn_on(self.hass, 'light.test',
|
||||||
brightness=50, color_temp=155, effect='colorloop',
|
brightness=50, color_temp=155, effect='colorloop',
|
||||||
white_value=170)
|
white_value=170)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual('test_light_rgb/set',
|
assert 'test_light_rgb/set' == \
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][0])
|
self.mock_publish.async_publish.mock_calls[0][1][0]
|
||||||
self.assertEqual(2,
|
assert 2 == \
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][2])
|
self.mock_publish.async_publish.mock_calls[0][1][2]
|
||||||
self.assertEqual(False,
|
assert self.mock_publish.async_publish.mock_calls[0][1][3] is False
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][3])
|
|
||||||
# Get the sent message
|
# Get the sent message
|
||||||
message_json = json.loads(
|
message_json = json.loads(
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][1])
|
self.mock_publish.async_publish.mock_calls[0][1][1])
|
||||||
self.assertEqual(50, message_json["brightness"])
|
assert 50 == message_json["brightness"]
|
||||||
self.assertEqual(155, message_json["color_temp"])
|
assert 155 == message_json["color_temp"]
|
||||||
self.assertEqual('colorloop', message_json["effect"])
|
assert 'colorloop' == message_json["effect"]
|
||||||
self.assertEqual(170, message_json["white_value"])
|
assert 170 == message_json["white_value"]
|
||||||
self.assertEqual("ON", message_json["state"])
|
assert "ON" == message_json["state"]
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(50, state.attributes['brightness'])
|
assert 50 == state.attributes['brightness']
|
||||||
self.assertEqual(155, state.attributes['color_temp'])
|
assert 155 == state.attributes['color_temp']
|
||||||
self.assertEqual('colorloop', state.attributes['effect'])
|
assert 'colorloop' == state.attributes['effect']
|
||||||
self.assertEqual(170, state.attributes['white_value'])
|
assert 170 == state.attributes['white_value']
|
||||||
|
|
||||||
# Test a color command
|
# Test a color command
|
||||||
common.turn_on(self.hass, 'light.test',
|
common.turn_on(self.hass, 'light.test',
|
||||||
brightness=50, hs_color=(125, 100))
|
brightness=50, hs_color=(125, 100))
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual('test_light_rgb/set',
|
assert 'test_light_rgb/set' == \
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][0])
|
self.mock_publish.async_publish.mock_calls[0][1][0]
|
||||||
self.assertEqual(2,
|
assert 2 == \
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][2])
|
self.mock_publish.async_publish.mock_calls[0][1][2]
|
||||||
self.assertEqual(False,
|
assert self.mock_publish.async_publish.mock_calls[0][1][3] is False
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][3])
|
|
||||||
# Get the sent message
|
# Get the sent message
|
||||||
message_json = json.loads(
|
message_json = json.loads(
|
||||||
self.mock_publish.async_publish.mock_calls[1][1][1])
|
self.mock_publish.async_publish.mock_calls[1][1][1])
|
||||||
self.assertEqual(50, message_json["brightness"])
|
assert 50 == message_json["brightness"]
|
||||||
self.assertEqual({
|
assert {
|
||||||
'r': 0,
|
'r': 0,
|
||||||
'g': 255,
|
'g': 255,
|
||||||
'b': 21,
|
'b': 21,
|
||||||
}, message_json["color"])
|
} == message_json["color"]
|
||||||
self.assertEqual("ON", message_json["state"])
|
assert "ON" == message_json["state"]
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(50, state.attributes['brightness'])
|
assert 50 == state.attributes['brightness']
|
||||||
self.assertEqual((125, 100), state.attributes['hs_color'])
|
assert (125, 100) == state.attributes['hs_color']
|
||||||
|
|
||||||
def test_sending_hs_color(self):
|
def test_sending_hs_color(self):
|
||||||
"""Test light.turn_on with hs color sends hs color parameters."""
|
"""Test light.turn_on with hs color sends hs color parameters."""
|
||||||
|
@ -406,11 +404,11 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
|
|
||||||
message_json = json.loads(
|
message_json = json.loads(
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][1])
|
self.mock_publish.async_publish.mock_calls[0][1][1])
|
||||||
self.assertEqual("ON", message_json["state"])
|
assert "ON" == message_json["state"]
|
||||||
self.assertEqual({
|
assert {
|
||||||
'h': 180.0,
|
'h': 180.0,
|
||||||
's': 50.0,
|
's': 50.0,
|
||||||
}, message_json["color"])
|
} == message_json["color"]
|
||||||
|
|
||||||
def test_flash_short_and_long(self):
|
def test_flash_short_and_long(self):
|
||||||
"""Test for flash length being sent when included."""
|
"""Test for flash length being sent when included."""
|
||||||
|
@ -427,39 +425,37 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertEqual(40, state.attributes.get(ATTR_SUPPORTED_FEATURES))
|
assert 40 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||||
|
|
||||||
common.turn_on(self.hass, 'light.test', flash="short")
|
common.turn_on(self.hass, 'light.test', flash="short")
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual('test_light_rgb/set',
|
assert 'test_light_rgb/set' == \
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][0])
|
self.mock_publish.async_publish.mock_calls[0][1][0]
|
||||||
self.assertEqual(0,
|
assert 0 == \
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][2])
|
self.mock_publish.async_publish.mock_calls[0][1][2]
|
||||||
self.assertEqual(False,
|
assert self.mock_publish.async_publish.mock_calls[0][1][3] is False
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][3])
|
|
||||||
# Get the sent message
|
# Get the sent message
|
||||||
message_json = json.loads(
|
message_json = json.loads(
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][1])
|
self.mock_publish.async_publish.mock_calls[0][1][1])
|
||||||
self.assertEqual(5, message_json["flash"])
|
assert 5 == message_json["flash"]
|
||||||
self.assertEqual("ON", message_json["state"])
|
assert "ON" == message_json["state"]
|
||||||
|
|
||||||
self.mock_publish.async_publish.reset_mock()
|
self.mock_publish.async_publish.reset_mock()
|
||||||
common.turn_on(self.hass, 'light.test', flash="long")
|
common.turn_on(self.hass, 'light.test', flash="long")
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual('test_light_rgb/set',
|
assert 'test_light_rgb/set' == \
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][0])
|
self.mock_publish.async_publish.mock_calls[0][1][0]
|
||||||
self.assertEqual(0,
|
assert 0 == \
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][2])
|
self.mock_publish.async_publish.mock_calls[0][1][2]
|
||||||
self.assertEqual(False,
|
assert self.mock_publish.async_publish.mock_calls[0][1][3] is False
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][3])
|
|
||||||
# Get the sent message
|
# Get the sent message
|
||||||
message_json = json.loads(
|
message_json = json.loads(
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][1])
|
self.mock_publish.async_publish.mock_calls[0][1][1])
|
||||||
self.assertEqual(15, message_json["flash"])
|
assert 15 == message_json["flash"]
|
||||||
self.assertEqual("ON", message_json["state"])
|
assert "ON" == message_json["state"]
|
||||||
|
|
||||||
def test_transition(self):
|
def test_transition(self):
|
||||||
"""Test for transition time being sent when included."""
|
"""Test for transition time being sent when included."""
|
||||||
|
@ -474,39 +470,37 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertEqual(40, state.attributes.get(ATTR_SUPPORTED_FEATURES))
|
assert 40 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||||
|
|
||||||
common.turn_on(self.hass, 'light.test', transition=10)
|
common.turn_on(self.hass, 'light.test', transition=10)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual('test_light_rgb/set',
|
assert 'test_light_rgb/set' == \
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][0])
|
self.mock_publish.async_publish.mock_calls[0][1][0]
|
||||||
self.assertEqual(0,
|
assert 0 == \
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][2])
|
self.mock_publish.async_publish.mock_calls[0][1][2]
|
||||||
self.assertEqual(False,
|
assert self.mock_publish.async_publish.mock_calls[0][1][3] is False
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][3])
|
|
||||||
# Get the sent message
|
# Get the sent message
|
||||||
message_json = json.loads(
|
message_json = json.loads(
|
||||||
self.mock_publish.async_publish.mock_calls[0][1][1])
|
self.mock_publish.async_publish.mock_calls[0][1][1])
|
||||||
self.assertEqual(10, message_json["transition"])
|
assert 10 == message_json["transition"]
|
||||||
self.assertEqual("ON", message_json["state"])
|
assert "ON" == message_json["state"]
|
||||||
|
|
||||||
# Transition back off
|
# Transition back off
|
||||||
common.turn_off(self.hass, 'light.test', transition=10)
|
common.turn_off(self.hass, 'light.test', transition=10)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual('test_light_rgb/set',
|
assert 'test_light_rgb/set' == \
|
||||||
self.mock_publish.async_publish.mock_calls[1][1][0])
|
self.mock_publish.async_publish.mock_calls[1][1][0]
|
||||||
self.assertEqual(0,
|
assert 0 == \
|
||||||
self.mock_publish.async_publish.mock_calls[1][1][2])
|
self.mock_publish.async_publish.mock_calls[1][1][2]
|
||||||
self.assertEqual(False,
|
assert self.mock_publish.async_publish.mock_calls[1][1][3] is False
|
||||||
self.mock_publish.async_publish.mock_calls[1][1][3])
|
|
||||||
# Get the sent message
|
# Get the sent message
|
||||||
message_json = json.loads(
|
message_json = json.loads(
|
||||||
self.mock_publish.async_publish.mock_calls[1][1][1])
|
self.mock_publish.async_publish.mock_calls[1][1][1])
|
||||||
self.assertEqual(10, message_json["transition"])
|
assert 10 == message_json["transition"]
|
||||||
self.assertEqual("OFF", message_json["state"])
|
assert "OFF" == message_json["state"]
|
||||||
|
|
||||||
def test_brightness_scale(self):
|
def test_brightness_scale(self):
|
||||||
"""Test for brightness scaling."""
|
"""Test for brightness scaling."""
|
||||||
|
@ -522,9 +516,9 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
# Turn on the light
|
# Turn on the light
|
||||||
fire_mqtt_message(self.hass, 'test_light_bright_scale',
|
fire_mqtt_message(self.hass, 'test_light_bright_scale',
|
||||||
|
@ -532,8 +526,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(255, state.attributes.get('brightness'))
|
assert 255 == state.attributes.get('brightness')
|
||||||
|
|
||||||
# Turn on the light with brightness
|
# Turn on the light with brightness
|
||||||
fire_mqtt_message(self.hass, 'test_light_bright_scale',
|
fire_mqtt_message(self.hass, 'test_light_bright_scale',
|
||||||
|
@ -542,8 +536,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(255, state.attributes.get('brightness'))
|
assert 255 == state.attributes.get('brightness')
|
||||||
|
|
||||||
def test_invalid_color_brightness_and_white_values(self):
|
def test_invalid_color_brightness_and_white_values(self):
|
||||||
"""Test that invalid color/brightness/white values are ignored."""
|
"""Test that invalid color/brightness/white values are ignored."""
|
||||||
|
@ -561,12 +555,12 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertEqual(185, state.attributes.get(ATTR_SUPPORTED_FEATURES))
|
assert 185 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
assert state.attributes.get('rgb_color') is None
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertIsNone(state.attributes.get('white_value'))
|
assert state.attributes.get('white_value') is None
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
# Turn on the light
|
# Turn on the light
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
|
@ -577,10 +571,10 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual((255, 255, 255), state.attributes.get('rgb_color'))
|
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||||
self.assertEqual(255, state.attributes.get('brightness'))
|
assert 255 == state.attributes.get('brightness')
|
||||||
self.assertEqual(255, state.attributes.get('white_value'))
|
assert 255 == state.attributes.get('white_value')
|
||||||
|
|
||||||
# Bad color values
|
# Bad color values
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
|
@ -590,8 +584,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
|
|
||||||
# Color should not have changed
|
# Color should not have changed
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual((255, 255, 255), state.attributes.get('rgb_color'))
|
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||||
|
|
||||||
# Bad brightness values
|
# Bad brightness values
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
|
@ -601,8 +595,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
|
|
||||||
# Brightness should not have changed
|
# Brightness should not have changed
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(255, state.attributes.get('brightness'))
|
assert 255 == state.attributes.get('brightness')
|
||||||
|
|
||||||
# Bad white value
|
# Bad white value
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
|
@ -612,12 +606,12 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
|
|
||||||
# White value should not have changed
|
# White value should not have changed
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(255, state.attributes.get('white_value'))
|
assert 255 == state.attributes.get('white_value')
|
||||||
|
|
||||||
def test_default_availability_payload(self):
|
def test_default_availability_payload(self):
|
||||||
"""Test availability by default payload with defined topic."""
|
"""Test availability by default payload with defined topic."""
|
||||||
self.assertTrue(setup_component(self.hass, light.DOMAIN, {
|
assert setup_component(self.hass, light.DOMAIN, {
|
||||||
light.DOMAIN: {
|
light.DOMAIN: {
|
||||||
'platform': 'mqtt_json',
|
'platform': 'mqtt_json',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -625,26 +619,26 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
'command_topic': 'test_light_rgb/set',
|
'command_topic': 'test_light_rgb/set',
|
||||||
'availability_topic': 'availability-topic'
|
'availability_topic': 'availability-topic'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
def test_custom_availability_payload(self):
|
def test_custom_availability_payload(self):
|
||||||
"""Test availability by custom payload with defined topic."""
|
"""Test availability by custom payload with defined topic."""
|
||||||
self.assertTrue(setup_component(self.hass, light.DOMAIN, {
|
assert setup_component(self.hass, light.DOMAIN, {
|
||||||
light.DOMAIN: {
|
light.DOMAIN: {
|
||||||
'platform': 'mqtt_json',
|
'platform': 'mqtt_json',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -654,22 +648,22 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||||
'payload_available': 'good',
|
'payload_available': 'good',
|
||||||
'payload_not_available': 'nogood'
|
'payload_not_available': 'nogood'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal(hass, mqtt_mock, caplog):
|
async def test_discovery_removal(hass, mqtt_mock, caplog):
|
||||||
|
|
|
@ -62,7 +62,7 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
self.assertIsNone(self.hass.states.get('light.test'))
|
assert self.hass.states.get('light.test') is None
|
||||||
|
|
||||||
def test_state_change_via_topic(self):
|
def test_state_change_via_topic(self):
|
||||||
"""Test state change via topic."""
|
"""Test state change via topic."""
|
||||||
|
@ -86,22 +86,22 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
assert state.attributes.get('rgb_color') is None
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertIsNone(state.attributes.get('color_temp'))
|
assert state.attributes.get('color_temp') is None
|
||||||
self.assertIsNone(state.attributes.get('white_value'))
|
assert state.attributes.get('white_value') is None
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb', 'on')
|
fire_mqtt_message(self.hass, 'test_light_rgb', 'on')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
assert state.attributes.get('rgb_color') is None
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertIsNone(state.attributes.get('color_temp'))
|
assert state.attributes.get('color_temp') is None
|
||||||
self.assertIsNone(state.attributes.get('white_value'))
|
assert state.attributes.get('white_value') is None
|
||||||
|
|
||||||
def test_state_brightness_color_effect_temp_white_change_via_topic(self):
|
def test_state_brightness_color_effect_temp_white_change_via_topic(self):
|
||||||
"""Test state, bri, color, effect, color temp, white val change."""
|
"""Test state, bri, color, effect, color temp, white val change."""
|
||||||
|
@ -137,13 +137,13 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
assert state.attributes.get('rgb_color') is None
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertIsNone(state.attributes.get('effect'))
|
assert state.attributes.get('effect') is None
|
||||||
self.assertIsNone(state.attributes.get('color_temp'))
|
assert state.attributes.get('color_temp') is None
|
||||||
self.assertIsNone(state.attributes.get('white_value'))
|
assert state.attributes.get('white_value') is None
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
# turn on the light, full white
|
# turn on the light, full white
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
|
@ -151,19 +151,19 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual((255, 128, 63), state.attributes.get('rgb_color'))
|
assert (255, 128, 63) == state.attributes.get('rgb_color')
|
||||||
self.assertEqual(255, state.attributes.get('brightness'))
|
assert 255 == state.attributes.get('brightness')
|
||||||
self.assertEqual(145, state.attributes.get('color_temp'))
|
assert 145 == state.attributes.get('color_temp')
|
||||||
self.assertEqual(123, state.attributes.get('white_value'))
|
assert 123 == state.attributes.get('white_value')
|
||||||
self.assertIsNone(state.attributes.get('effect'))
|
assert state.attributes.get('effect') is None
|
||||||
|
|
||||||
# turn the light off
|
# turn the light off
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb', 'off')
|
fire_mqtt_message(self.hass, 'test_light_rgb', 'off')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
# lower the brightness
|
# lower the brightness
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,100')
|
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,100')
|
||||||
|
@ -171,7 +171,7 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(100, light_state.attributes['brightness'])
|
assert 100 == light_state.attributes['brightness']
|
||||||
|
|
||||||
# change the color temp
|
# change the color temp
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,,195')
|
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,,195')
|
||||||
|
@ -179,15 +179,15 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(195, light_state.attributes['color_temp'])
|
assert 195 == light_state.attributes['color_temp']
|
||||||
|
|
||||||
# change the color
|
# change the color
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,,,,41-42-43')
|
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,,,,41-42-43')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.assertEqual((243, 249, 255),
|
assert (243, 249, 255) == \
|
||||||
light_state.attributes.get('rgb_color'))
|
light_state.attributes.get('rgb_color')
|
||||||
|
|
||||||
# change the white value
|
# change the white value
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,,,134')
|
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,,,134')
|
||||||
|
@ -195,7 +195,7 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(134, light_state.attributes['white_value'])
|
assert 134 == light_state.attributes['white_value']
|
||||||
|
|
||||||
# change the effect
|
# change the effect
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
|
@ -203,7 +203,7 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
light_state = self.hass.states.get('light.test')
|
light_state = self.hass.states.get('light.test')
|
||||||
self.assertEqual('rainbow', light_state.attributes.get('effect'))
|
assert 'rainbow' == light_state.attributes.get('effect')
|
||||||
|
|
||||||
def test_optimistic(self):
|
def test_optimistic(self):
|
||||||
"""Test optimistic mode."""
|
"""Test optimistic mode."""
|
||||||
|
@ -237,13 +237,13 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(95, state.attributes.get('brightness'))
|
assert 95 == state.attributes.get('brightness')
|
||||||
self.assertEqual((100, 100), state.attributes.get('hs_color'))
|
assert (100, 100) == state.attributes.get('hs_color')
|
||||||
self.assertEqual('random', state.attributes.get('effect'))
|
assert 'random' == state.attributes.get('effect')
|
||||||
self.assertEqual(100, state.attributes.get('color_temp'))
|
assert 100 == state.attributes.get('color_temp')
|
||||||
self.assertEqual(50, state.attributes.get('white_value'))
|
assert 50 == state.attributes.get('white_value')
|
||||||
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
# turn on the light
|
# turn on the light
|
||||||
common.turn_on(self.hass, 'light.test')
|
common.turn_on(self.hass, 'light.test')
|
||||||
|
@ -253,7 +253,7 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
'test_light_rgb/set', 'on,,,,--', 2, False)
|
'test_light_rgb/set', 'on,,,,--', 2, False)
|
||||||
self.mock_publish.async_publish.reset_mock()
|
self.mock_publish.async_publish.reset_mock()
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
|
|
||||||
# turn the light off
|
# turn the light off
|
||||||
common.turn_off(self.hass, 'light.test')
|
common.turn_off(self.hass, 'light.test')
|
||||||
|
@ -263,7 +263,7 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
'test_light_rgb/set', 'off', 2, False)
|
'test_light_rgb/set', 'off', 2, False)
|
||||||
self.mock_publish.async_publish.reset_mock()
|
self.mock_publish.async_publish.reset_mock()
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
# turn on the light with brightness, color
|
# turn on the light with brightness, color
|
||||||
common.turn_on(self.hass, 'light.test', brightness=50,
|
common.turn_on(self.hass, 'light.test', brightness=50,
|
||||||
|
@ -284,11 +284,11 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
|
|
||||||
# check the state
|
# check the state
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual((255, 255, 255), state.attributes['rgb_color'])
|
assert (255, 255, 255) == state.attributes['rgb_color']
|
||||||
self.assertEqual(50, state.attributes['brightness'])
|
assert 50 == state.attributes['brightness']
|
||||||
self.assertEqual(200, state.attributes['color_temp'])
|
assert 200 == state.attributes['color_temp']
|
||||||
self.assertEqual(139, state.attributes['white_value'])
|
assert 139 == state.attributes['white_value']
|
||||||
|
|
||||||
def test_flash(self):
|
def test_flash(self):
|
||||||
"""Test flash."""
|
"""Test flash."""
|
||||||
|
@ -305,7 +305,7 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
# short flash
|
# short flash
|
||||||
common.turn_on(self.hass, 'light.test', flash='short')
|
common.turn_on(self.hass, 'light.test', flash='short')
|
||||||
|
@ -336,7 +336,7 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
|
|
||||||
# transition on
|
# transition on
|
||||||
common.turn_on(self.hass, 'light.test', transition=10)
|
common.turn_on(self.hass, 'light.test', transition=10)
|
||||||
|
@ -386,13 +386,13 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_OFF, state.state)
|
assert STATE_OFF == state.state
|
||||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
assert state.attributes.get('rgb_color') is None
|
||||||
self.assertIsNone(state.attributes.get('brightness'))
|
assert state.attributes.get('brightness') is None
|
||||||
self.assertIsNone(state.attributes.get('color_temp'))
|
assert state.attributes.get('color_temp') is None
|
||||||
self.assertIsNone(state.attributes.get('effect'))
|
assert state.attributes.get('effect') is None
|
||||||
self.assertIsNone(state.attributes.get('white_value'))
|
assert state.attributes.get('white_value') is None
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
# turn on the light, full white
|
# turn on the light, full white
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||||
|
@ -400,12 +400,12 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
self.assertEqual(255, state.attributes.get('brightness'))
|
assert 255 == state.attributes.get('brightness')
|
||||||
self.assertEqual(215, state.attributes.get('color_temp'))
|
assert 215 == state.attributes.get('color_temp')
|
||||||
self.assertEqual((255, 255, 255), state.attributes.get('rgb_color'))
|
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||||
self.assertEqual(222, state.attributes.get('white_value'))
|
assert 222 == state.attributes.get('white_value')
|
||||||
self.assertEqual('rainbow', state.attributes.get('effect'))
|
assert 'rainbow' == state.attributes.get('effect')
|
||||||
|
|
||||||
# bad state value
|
# bad state value
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb', 'offf')
|
fire_mqtt_message(self.hass, 'test_light_rgb', 'offf')
|
||||||
|
@ -413,7 +413,7 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
|
|
||||||
# state should not have changed
|
# state should not have changed
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_ON, state.state)
|
assert STATE_ON == state.state
|
||||||
|
|
||||||
# bad brightness values
|
# bad brightness values
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,off,255-255-255')
|
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,off,255-255-255')
|
||||||
|
@ -421,7 +421,7 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
|
|
||||||
# brightness should not have changed
|
# brightness should not have changed
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(255, state.attributes.get('brightness'))
|
assert 255 == state.attributes.get('brightness')
|
||||||
|
|
||||||
# bad color temp values
|
# bad color temp values
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,,off,255-255-255')
|
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,,off,255-255-255')
|
||||||
|
@ -429,7 +429,7 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
|
|
||||||
# color temp should not have changed
|
# color temp should not have changed
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(215, state.attributes.get('color_temp'))
|
assert 215 == state.attributes.get('color_temp')
|
||||||
|
|
||||||
# bad color values
|
# bad color values
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,255,a-b-c')
|
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,255,a-b-c')
|
||||||
|
@ -437,7 +437,7 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
|
|
||||||
# color should not have changed
|
# color should not have changed
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual((255, 255, 255), state.attributes.get('rgb_color'))
|
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||||
|
|
||||||
# bad white value values
|
# bad white value values
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,,,off,255-255-255')
|
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,,,off,255-255-255')
|
||||||
|
@ -445,7 +445,7 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
|
|
||||||
# white value should not have changed
|
# white value should not have changed
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(222, state.attributes.get('white_value'))
|
assert 222 == state.attributes.get('white_value')
|
||||||
|
|
||||||
# bad effect value
|
# bad effect value
|
||||||
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,255,a-b-c,white')
|
fire_mqtt_message(self.hass, 'test_light_rgb', 'on,255,a-b-c,white')
|
||||||
|
@ -453,11 +453,11 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
|
|
||||||
# effect should not have changed
|
# effect should not have changed
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual('rainbow', state.attributes.get('effect'))
|
assert 'rainbow' == state.attributes.get('effect')
|
||||||
|
|
||||||
def test_default_availability_payload(self):
|
def test_default_availability_payload(self):
|
||||||
"""Test availability by default payload with defined topic."""
|
"""Test availability by default payload with defined topic."""
|
||||||
self.assertTrue(setup_component(self.hass, light.DOMAIN, {
|
assert setup_component(self.hass, light.DOMAIN, {
|
||||||
light.DOMAIN: {
|
light.DOMAIN: {
|
||||||
'platform': 'mqtt_template',
|
'platform': 'mqtt_template',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -466,26 +466,26 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
'command_off_template': 'off,{{ transition|d }}',
|
'command_off_template': 'off,{{ transition|d }}',
|
||||||
'availability_topic': 'availability-topic'
|
'availability_topic': 'availability-topic'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
def test_custom_availability_payload(self):
|
def test_custom_availability_payload(self):
|
||||||
"""Test availability by custom payload with defined topic."""
|
"""Test availability by custom payload with defined topic."""
|
||||||
self.assertTrue(setup_component(self.hass, light.DOMAIN, {
|
assert setup_component(self.hass, light.DOMAIN, {
|
||||||
light.DOMAIN: {
|
light.DOMAIN: {
|
||||||
'platform': 'mqtt_template',
|
'platform': 'mqtt_template',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -496,19 +496,19 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
||||||
'payload_available': 'good',
|
'payload_available': 'good',
|
||||||
'payload_not_available': 'nogood'
|
'payload_not_available': 'nogood'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
|
@ -28,26 +28,26 @@ class TestLightRfxtrx(unittest.TestCase):
|
||||||
|
|
||||||
def test_valid_config(self):
|
def test_valid_config(self):
|
||||||
"""Test configuration."""
|
"""Test configuration."""
|
||||||
self.assertTrue(setup_component(self.hass, 'light', {
|
assert setup_component(self.hass, 'light', {
|
||||||
'light': {'platform': 'rfxtrx',
|
'light': {'platform': 'rfxtrx',
|
||||||
'automatic_add': True,
|
'automatic_add': True,
|
||||||
'devices':
|
'devices':
|
||||||
{'0b1100cd0213c7f210010f51': {
|
{'0b1100cd0213c7f210010f51': {
|
||||||
'name': 'Test',
|
'name': 'Test',
|
||||||
rfxtrx_core.ATTR_FIREEVENT: True}}}}))
|
rfxtrx_core.ATTR_FIREEVENT: True}}}})
|
||||||
|
|
||||||
self.assertTrue(setup_component(self.hass, 'light', {
|
assert setup_component(self.hass, 'light', {
|
||||||
'light': {'platform': 'rfxtrx',
|
'light': {'platform': 'rfxtrx',
|
||||||
'automatic_add': True,
|
'automatic_add': True,
|
||||||
'devices':
|
'devices':
|
||||||
{'213c7f216': {
|
{'213c7f216': {
|
||||||
'name': 'Test',
|
'name': 'Test',
|
||||||
'packetid': '0b1100cd0213c7f210010f51',
|
'packetid': '0b1100cd0213c7f210010f51',
|
||||||
'signal_repetitions': 3}}}}))
|
'signal_repetitions': 3}}}})
|
||||||
|
|
||||||
def test_invalid_config(self):
|
def test_invalid_config(self):
|
||||||
"""Test configuration."""
|
"""Test configuration."""
|
||||||
self.assertFalse(setup_component(self.hass, 'light', {
|
assert not setup_component(self.hass, 'light', {
|
||||||
'light': {'platform': 'rfxtrx',
|
'light': {'platform': 'rfxtrx',
|
||||||
'automatic_add': True,
|
'automatic_add': True,
|
||||||
'invalid_key': 'afda',
|
'invalid_key': 'afda',
|
||||||
|
@ -55,182 +55,183 @@ class TestLightRfxtrx(unittest.TestCase):
|
||||||
{'213c7f216': {
|
{'213c7f216': {
|
||||||
'name': 'Test',
|
'name': 'Test',
|
||||||
'packetid': '0b1100cd0213c7f210010f51',
|
'packetid': '0b1100cd0213c7f210010f51',
|
||||||
rfxtrx_core.ATTR_FIREEVENT: True}}}}))
|
rfxtrx_core.ATTR_FIREEVENT: True}}}})
|
||||||
|
|
||||||
def test_default_config(self):
|
def test_default_config(self):
|
||||||
"""Test with 0 switches."""
|
"""Test with 0 switches."""
|
||||||
self.assertTrue(setup_component(self.hass, 'light', {
|
assert setup_component(self.hass, 'light', {
|
||||||
'light': {'platform': 'rfxtrx',
|
'light': {'platform': 'rfxtrx',
|
||||||
'devices': {}}}))
|
'devices': {}}})
|
||||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
def test_old_config(self):
|
def test_old_config(self):
|
||||||
"""Test with 1 light."""
|
"""Test with 1 light."""
|
||||||
self.assertTrue(setup_component(self.hass, 'light', {
|
assert setup_component(self.hass, 'light', {
|
||||||
'light': {'platform': 'rfxtrx',
|
'light': {'platform': 'rfxtrx',
|
||||||
'devices':
|
'devices':
|
||||||
{'123efab1': {
|
{'123efab1': {
|
||||||
'name': 'Test',
|
'name': 'Test',
|
||||||
'packetid': '0b1100cd0213c7f210010f51'}}}}))
|
'packetid': '0b1100cd0213c7f210010f51'}}}})
|
||||||
|
|
||||||
import RFXtrx as rfxtrxmod
|
import RFXtrx as rfxtrxmod
|
||||||
rfxtrx_core.RFXOBJECT =\
|
rfxtrx_core.RFXOBJECT =\
|
||||||
rfxtrxmod.Core("", transport_protocol=rfxtrxmod.DummyTransport)
|
rfxtrxmod.Core("", transport_protocol=rfxtrxmod.DummyTransport)
|
||||||
|
|
||||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
assert 1 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
entity = rfxtrx_core.RFX_DEVICES['213c7f216']
|
entity = rfxtrx_core.RFX_DEVICES['213c7f216']
|
||||||
self.assertEqual('Test', entity.name)
|
assert 'Test' == entity.name
|
||||||
self.assertEqual('off', entity.state)
|
assert 'off' == entity.state
|
||||||
self.assertTrue(entity.assumed_state)
|
assert entity.assumed_state
|
||||||
self.assertEqual(entity.signal_repetitions, 1)
|
assert entity.signal_repetitions == 1
|
||||||
self.assertFalse(entity.should_fire_event)
|
assert not entity.should_fire_event
|
||||||
self.assertFalse(entity.should_poll)
|
assert not entity.should_poll
|
||||||
|
|
||||||
self.assertFalse(entity.is_on)
|
assert not entity.is_on
|
||||||
|
|
||||||
entity.turn_on()
|
entity.turn_on()
|
||||||
self.assertTrue(entity.is_on)
|
assert entity.is_on
|
||||||
self.assertEqual(entity.brightness, 255)
|
assert entity.brightness == 255
|
||||||
|
|
||||||
entity.turn_off()
|
entity.turn_off()
|
||||||
self.assertFalse(entity.is_on)
|
assert not entity.is_on
|
||||||
self.assertEqual(entity.brightness, 0)
|
assert entity.brightness == 0
|
||||||
|
|
||||||
entity.turn_on(brightness=100)
|
entity.turn_on(brightness=100)
|
||||||
self.assertTrue(entity.is_on)
|
assert entity.is_on
|
||||||
self.assertEqual(entity.brightness, 100)
|
assert entity.brightness == 100
|
||||||
|
|
||||||
entity.turn_on(brightness=10)
|
entity.turn_on(brightness=10)
|
||||||
self.assertTrue(entity.is_on)
|
assert entity.is_on
|
||||||
self.assertEqual(entity.brightness, 10)
|
assert entity.brightness == 10
|
||||||
|
|
||||||
entity.turn_on(brightness=255)
|
entity.turn_on(brightness=255)
|
||||||
self.assertTrue(entity.is_on)
|
assert entity.is_on
|
||||||
self.assertEqual(entity.brightness, 255)
|
assert entity.brightness == 255
|
||||||
|
|
||||||
def test_one_light(self):
|
def test_one_light(self):
|
||||||
"""Test with 1 light."""
|
"""Test with 1 light."""
|
||||||
self.assertTrue(setup_component(self.hass, 'light', {
|
assert setup_component(self.hass, 'light', {
|
||||||
'light': {'platform': 'rfxtrx',
|
'light': {'platform': 'rfxtrx',
|
||||||
'devices':
|
'devices':
|
||||||
{'0b1100cd0213c7f210010f51': {
|
{'0b1100cd0213c7f210010f51': {
|
||||||
'name': 'Test'}}}}))
|
'name': 'Test'}}}})
|
||||||
|
|
||||||
import RFXtrx as rfxtrxmod
|
import RFXtrx as rfxtrxmod
|
||||||
rfxtrx_core.RFXOBJECT =\
|
rfxtrx_core.RFXOBJECT =\
|
||||||
rfxtrxmod.Core("", transport_protocol=rfxtrxmod.DummyTransport)
|
rfxtrxmod.Core("", transport_protocol=rfxtrxmod.DummyTransport)
|
||||||
|
|
||||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
assert 1 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
entity = rfxtrx_core.RFX_DEVICES['213c7f216']
|
entity = rfxtrx_core.RFX_DEVICES['213c7f216']
|
||||||
self.assertEqual('Test', entity.name)
|
assert 'Test' == entity.name
|
||||||
self.assertEqual('off', entity.state)
|
assert 'off' == entity.state
|
||||||
self.assertTrue(entity.assumed_state)
|
assert entity.assumed_state
|
||||||
self.assertEqual(entity.signal_repetitions, 1)
|
assert entity.signal_repetitions == 1
|
||||||
self.assertFalse(entity.should_fire_event)
|
assert not entity.should_fire_event
|
||||||
self.assertFalse(entity.should_poll)
|
assert not entity.should_poll
|
||||||
|
|
||||||
self.assertFalse(entity.is_on)
|
assert not entity.is_on
|
||||||
|
|
||||||
entity.turn_on()
|
entity.turn_on()
|
||||||
self.assertTrue(entity.is_on)
|
assert entity.is_on
|
||||||
self.assertEqual(entity.brightness, 255)
|
assert entity.brightness == 255
|
||||||
|
|
||||||
entity.turn_off()
|
entity.turn_off()
|
||||||
self.assertFalse(entity.is_on)
|
assert not entity.is_on
|
||||||
self.assertEqual(entity.brightness, 0)
|
assert entity.brightness == 0
|
||||||
|
|
||||||
entity.turn_on(brightness=100)
|
entity.turn_on(brightness=100)
|
||||||
self.assertTrue(entity.is_on)
|
assert entity.is_on
|
||||||
self.assertEqual(entity.brightness, 100)
|
assert entity.brightness == 100
|
||||||
|
|
||||||
entity.turn_on(brightness=10)
|
entity.turn_on(brightness=10)
|
||||||
self.assertTrue(entity.is_on)
|
assert entity.is_on
|
||||||
self.assertEqual(entity.brightness, 10)
|
assert entity.brightness == 10
|
||||||
|
|
||||||
entity.turn_on(brightness=255)
|
entity.turn_on(brightness=255)
|
||||||
self.assertTrue(entity.is_on)
|
assert entity.is_on
|
||||||
self.assertEqual(entity.brightness, 255)
|
assert entity.brightness == 255
|
||||||
|
|
||||||
entity.turn_off()
|
entity.turn_off()
|
||||||
entity_id = rfxtrx_core.RFX_DEVICES['213c7f216'].entity_id
|
entity_id = rfxtrx_core.RFX_DEVICES['213c7f216'].entity_id
|
||||||
entity_hass = self.hass.states.get(entity_id)
|
entity_hass = self.hass.states.get(entity_id)
|
||||||
self.assertEqual('Test', entity_hass.name)
|
assert 'Test' == entity_hass.name
|
||||||
self.assertEqual('off', entity_hass.state)
|
assert 'off' == entity_hass.state
|
||||||
|
|
||||||
entity.turn_on()
|
entity.turn_on()
|
||||||
entity_hass = self.hass.states.get(entity_id)
|
entity_hass = self.hass.states.get(entity_id)
|
||||||
self.assertEqual('on', entity_hass.state)
|
assert 'on' == entity_hass.state
|
||||||
|
|
||||||
entity.turn_off()
|
entity.turn_off()
|
||||||
entity_hass = self.hass.states.get(entity_id)
|
entity_hass = self.hass.states.get(entity_id)
|
||||||
self.assertEqual('off', entity_hass.state)
|
assert 'off' == entity_hass.state
|
||||||
|
|
||||||
entity.turn_on(brightness=100)
|
entity.turn_on(brightness=100)
|
||||||
entity_hass = self.hass.states.get(entity_id)
|
entity_hass = self.hass.states.get(entity_id)
|
||||||
self.assertEqual('on', entity_hass.state)
|
assert 'on' == entity_hass.state
|
||||||
|
|
||||||
entity.turn_on(brightness=10)
|
entity.turn_on(brightness=10)
|
||||||
entity_hass = self.hass.states.get(entity_id)
|
entity_hass = self.hass.states.get(entity_id)
|
||||||
self.assertEqual('on', entity_hass.state)
|
assert 'on' == entity_hass.state
|
||||||
|
|
||||||
entity.turn_on(brightness=255)
|
entity.turn_on(brightness=255)
|
||||||
entity_hass = self.hass.states.get(entity_id)
|
entity_hass = self.hass.states.get(entity_id)
|
||||||
self.assertEqual('on', entity_hass.state)
|
assert 'on' == entity_hass.state
|
||||||
|
|
||||||
def test_several_lights(self):
|
def test_several_lights(self):
|
||||||
"""Test with 3 lights."""
|
"""Test with 3 lights."""
|
||||||
self.assertTrue(setup_component(self.hass, 'light', {
|
assert setup_component(self.hass, 'light', {
|
||||||
'light': {'platform': 'rfxtrx',
|
'light': {
|
||||||
'signal_repetitions': 3,
|
'platform': 'rfxtrx',
|
||||||
'devices':
|
'signal_repetitions': 3,
|
||||||
{'0b1100cd0213c7f230010f71': {
|
'devices': {
|
||||||
'name': 'Test'},
|
'0b1100cd0213c7f230010f71': {
|
||||||
'0b1100100118cdea02010f70': {
|
'name': 'Test'},
|
||||||
'name': 'Bath'},
|
'0b1100100118cdea02010f70': {
|
||||||
'0b1100101118cdea02010f70': {
|
'name': 'Bath'},
|
||||||
'name': 'Living'}}}}))
|
'0b1100101118cdea02010f70': {
|
||||||
|
'name': 'Living'}}}})
|
||||||
|
|
||||||
self.assertEqual(3, len(rfxtrx_core.RFX_DEVICES))
|
assert 3 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
device_num = 0
|
device_num = 0
|
||||||
for id in rfxtrx_core.RFX_DEVICES:
|
for id in rfxtrx_core.RFX_DEVICES:
|
||||||
entity = rfxtrx_core.RFX_DEVICES[id]
|
entity = rfxtrx_core.RFX_DEVICES[id]
|
||||||
self.assertEqual(entity.signal_repetitions, 3)
|
assert entity.signal_repetitions == 3
|
||||||
if entity.name == 'Living':
|
if entity.name == 'Living':
|
||||||
device_num = device_num + 1
|
device_num = device_num + 1
|
||||||
self.assertEqual('off', entity.state)
|
assert 'off' == entity.state
|
||||||
self.assertEqual('<Entity Living: off>', entity.__str__())
|
assert '<Entity Living: off>' == entity.__str__()
|
||||||
elif entity.name == 'Bath':
|
elif entity.name == 'Bath':
|
||||||
device_num = device_num + 1
|
device_num = device_num + 1
|
||||||
self.assertEqual('off', entity.state)
|
assert 'off' == entity.state
|
||||||
self.assertEqual('<Entity Bath: off>', entity.__str__())
|
assert '<Entity Bath: off>' == entity.__str__()
|
||||||
elif entity.name == 'Test':
|
elif entity.name == 'Test':
|
||||||
device_num = device_num + 1
|
device_num = device_num + 1
|
||||||
self.assertEqual('off', entity.state)
|
assert 'off' == entity.state
|
||||||
self.assertEqual('<Entity Test: off>', entity.__str__())
|
assert '<Entity Test: off>' == entity.__str__()
|
||||||
|
|
||||||
self.assertEqual(3, device_num)
|
assert 3 == device_num
|
||||||
|
|
||||||
def test_discover_light(self):
|
def test_discover_light(self):
|
||||||
"""Test with discovery of lights."""
|
"""Test with discovery of lights."""
|
||||||
self.assertTrue(setup_component(self.hass, 'light', {
|
assert setup_component(self.hass, 'light', {
|
||||||
'light': {'platform': 'rfxtrx',
|
'light': {'platform': 'rfxtrx',
|
||||||
'automatic_add': True,
|
'automatic_add': True,
|
||||||
'devices': {}}}))
|
'devices': {}}})
|
||||||
|
|
||||||
event = rfxtrx_core.get_rfx_object('0b11009e00e6116202020070')
|
event = rfxtrx_core.get_rfx_object('0b11009e00e6116202020070')
|
||||||
event.data = bytearray(b'\x0b\x11\x00\x9e\x00\xe6\x11b\x02\x02\x00p')
|
event.data = bytearray(b'\x0b\x11\x00\x9e\x00\xe6\x11b\x02\x02\x00p')
|
||||||
|
|
||||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||||
entity = rfxtrx_core.RFX_DEVICES['0e611622']
|
entity = rfxtrx_core.RFX_DEVICES['0e611622']
|
||||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
assert 1 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
self.assertEqual('<Entity 0b11009e00e6116202020070: on>',
|
assert '<Entity 0b11009e00e6116202020070: on>' == \
|
||||||
entity.__str__())
|
entity.__str__()
|
||||||
|
|
||||||
event = rfxtrx_core.get_rfx_object('0b11009e00e6116201010070')
|
event = rfxtrx_core.get_rfx_object('0b11009e00e6116201010070')
|
||||||
event.data = bytearray(b'\x0b\x11\x00\x9e\x00\xe6\x11b\x01\x01\x00p')
|
event.data = bytearray(b'\x0b\x11\x00\x9e\x00\xe6\x11b\x01\x01\x00p')
|
||||||
|
|
||||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
assert 1 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
event = rfxtrx_core.get_rfx_object('0b1100120118cdea02020070')
|
event = rfxtrx_core.get_rfx_object('0b1100120118cdea02020070')
|
||||||
event.data = bytearray([0x0b, 0x11, 0x00, 0x12, 0x01, 0x18,
|
event.data = bytearray([0x0b, 0x11, 0x00, 0x12, 0x01, 0x18,
|
||||||
|
@ -238,15 +239,15 @@ class TestLightRfxtrx(unittest.TestCase):
|
||||||
|
|
||||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||||
entity = rfxtrx_core.RFX_DEVICES['118cdea2']
|
entity = rfxtrx_core.RFX_DEVICES['118cdea2']
|
||||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
assert 2 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
self.assertEqual('<Entity 0b1100120118cdea02020070: on>',
|
assert '<Entity 0b1100120118cdea02020070: on>' == \
|
||||||
entity.__str__())
|
entity.__str__()
|
||||||
|
|
||||||
# trying to add a sensor
|
# trying to add a sensor
|
||||||
event = rfxtrx_core.get_rfx_object('0a52085e070100b31b0279')
|
event = rfxtrx_core.get_rfx_object('0a52085e070100b31b0279')
|
||||||
event.data = bytearray(b'\nR\x08^\x07\x01\x00\xb3\x1b\x02y')
|
event.data = bytearray(b'\nR\x08^\x07\x01\x00\xb3\x1b\x02y')
|
||||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
assert 2 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
# trying to add a switch
|
# trying to add a switch
|
||||||
event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70')
|
event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70')
|
||||||
|
@ -254,59 +255,59 @@ class TestLightRfxtrx(unittest.TestCase):
|
||||||
0xcd, 0xea, 0x01, 0x01, 0x0f, 0x70])
|
0xcd, 0xea, 0x01, 0x01, 0x0f, 0x70])
|
||||||
|
|
||||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
assert 2 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
# Trying to add a rollershutter
|
# Trying to add a rollershutter
|
||||||
event = rfxtrx_core.get_rfx_object('0a1400adf394ab020e0060')
|
event = rfxtrx_core.get_rfx_object('0a1400adf394ab020e0060')
|
||||||
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
||||||
0xAB, 0x02, 0x0E, 0x00, 0x60])
|
0xAB, 0x02, 0x0E, 0x00, 0x60])
|
||||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
assert 2 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
def test_discover_light_noautoadd(self):
|
def test_discover_light_noautoadd(self):
|
||||||
"""Test with discover of light when auto add is False."""
|
"""Test with discover of light when auto add is False."""
|
||||||
self.assertTrue(setup_component(self.hass, 'light', {
|
assert setup_component(self.hass, 'light', {
|
||||||
'light': {'platform': 'rfxtrx',
|
'light': {'platform': 'rfxtrx',
|
||||||
'automatic_add': False,
|
'automatic_add': False,
|
||||||
'devices': {}}}))
|
'devices': {}}})
|
||||||
|
|
||||||
event = rfxtrx_core.get_rfx_object('0b1100120118cdea02020070')
|
event = rfxtrx_core.get_rfx_object('0b1100120118cdea02020070')
|
||||||
event.data = bytearray([0x0b, 0x11, 0x00, 0x12, 0x01, 0x18,
|
event.data = bytearray([0x0b, 0x11, 0x00, 0x12, 0x01, 0x18,
|
||||||
0xcd, 0xea, 0x02, 0x02, 0x00, 0x70])
|
0xcd, 0xea, 0x02, 0x02, 0x00, 0x70])
|
||||||
|
|
||||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
event = rfxtrx_core.get_rfx_object('0b1100120118cdea02010070')
|
event = rfxtrx_core.get_rfx_object('0b1100120118cdea02010070')
|
||||||
event.data = bytearray([0x0b, 0x11, 0x00, 0x12, 0x01, 0x18,
|
event.data = bytearray([0x0b, 0x11, 0x00, 0x12, 0x01, 0x18,
|
||||||
0xcd, 0xea, 0x02, 0x01, 0x00, 0x70])
|
0xcd, 0xea, 0x02, 0x01, 0x00, 0x70])
|
||||||
|
|
||||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
event = rfxtrx_core.get_rfx_object('0b1100120118cdea02020070')
|
event = rfxtrx_core.get_rfx_object('0b1100120118cdea02020070')
|
||||||
event.data = bytearray([0x0b, 0x11, 0x00, 0x12, 0x01, 0x18,
|
event.data = bytearray([0x0b, 0x11, 0x00, 0x12, 0x01, 0x18,
|
||||||
0xcd, 0xea, 0x02, 0x02, 0x00, 0x70])
|
0xcd, 0xea, 0x02, 0x02, 0x00, 0x70])
|
||||||
|
|
||||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
# Trying to add a sensor
|
# Trying to add a sensor
|
||||||
event = rfxtrx_core.get_rfx_object('0a52085e070100b31b0279')
|
event = rfxtrx_core.get_rfx_object('0a52085e070100b31b0279')
|
||||||
event.data = bytearray(b'\nR\x08^\x07\x01\x00\xb3\x1b\x02y')
|
event.data = bytearray(b'\nR\x08^\x07\x01\x00\xb3\x1b\x02y')
|
||||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
# Trying to add a switch
|
# Trying to add a switch
|
||||||
event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70')
|
event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70')
|
||||||
event.data = bytearray([0x0b, 0x11, 0x00, 0x10, 0x01, 0x18,
|
event.data = bytearray([0x0b, 0x11, 0x00, 0x10, 0x01, 0x18,
|
||||||
0xcd, 0xea, 0x01, 0x01, 0x0f, 0x70])
|
0xcd, 0xea, 0x01, 0x01, 0x0f, 0x70])
|
||||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
||||||
# Trying to add a rollershutter
|
# Trying to add a rollershutter
|
||||||
event = rfxtrx_core.get_rfx_object('0a1400adf394ab020e0060')
|
event = rfxtrx_core.get_rfx_object('0a1400adf394ab020e0060')
|
||||||
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
||||||
0xAB, 0x02, 0x0E, 0x00, 0x60])
|
0xAB, 0x02, 0x0E, 0x00, 0x60])
|
||||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||||
|
|
|
@ -18,11 +18,11 @@ class TestLockDemo(unittest.TestCase):
|
||||||
def setUp(self): # pylint: disable=invalid-name
|
def setUp(self): # pylint: disable=invalid-name
|
||||||
"""Set up things to be run when tests are started."""
|
"""Set up things to be run when tests are started."""
|
||||||
self.hass = get_test_home_assistant()
|
self.hass = get_test_home_assistant()
|
||||||
self.assertTrue(setup_component(self.hass, lock.DOMAIN, {
|
assert setup_component(self.hass, lock.DOMAIN, {
|
||||||
'lock': {
|
'lock': {
|
||||||
'platform': 'demo'
|
'platform': 'demo'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
"""Stop everything that was started."""
|
"""Stop everything that was started."""
|
||||||
|
@ -30,10 +30,10 @@ class TestLockDemo(unittest.TestCase):
|
||||||
|
|
||||||
def test_is_locked(self):
|
def test_is_locked(self):
|
||||||
"""Test if lock is locked."""
|
"""Test if lock is locked."""
|
||||||
self.assertTrue(lock.is_locked(self.hass, FRONT))
|
assert lock.is_locked(self.hass, FRONT)
|
||||||
self.hass.states.is_state(FRONT, 'locked')
|
self.hass.states.is_state(FRONT, 'locked')
|
||||||
|
|
||||||
self.assertFalse(lock.is_locked(self.hass, KITCHEN))
|
assert not lock.is_locked(self.hass, KITCHEN)
|
||||||
self.hass.states.is_state(KITCHEN, 'unlocked')
|
self.hass.states.is_state(KITCHEN, 'unlocked')
|
||||||
|
|
||||||
def test_locking(self):
|
def test_locking(self):
|
||||||
|
@ -41,18 +41,18 @@ class TestLockDemo(unittest.TestCase):
|
||||||
common.lock(self.hass, KITCHEN)
|
common.lock(self.hass, KITCHEN)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertTrue(lock.is_locked(self.hass, KITCHEN))
|
assert lock.is_locked(self.hass, KITCHEN)
|
||||||
|
|
||||||
def test_unlocking(self):
|
def test_unlocking(self):
|
||||||
"""Test the unlocking of a lock."""
|
"""Test the unlocking of a lock."""
|
||||||
common.unlock(self.hass, FRONT)
|
common.unlock(self.hass, FRONT)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertFalse(lock.is_locked(self.hass, FRONT))
|
assert not lock.is_locked(self.hass, FRONT)
|
||||||
|
|
||||||
def test_opening(self):
|
def test_opening(self):
|
||||||
"""Test the opening of a lock."""
|
"""Test the opening of a lock."""
|
||||||
calls = mock_service(self.hass, lock.DOMAIN, lock.SERVICE_OPEN)
|
calls = mock_service(self.hass, lock.DOMAIN, lock.SERVICE_OPEN)
|
||||||
common.open_lock(self.hass, OPENABLE_LOCK)
|
common.open_lock(self.hass, OPENABLE_LOCK)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(calls))
|
assert 1 == len(calls)
|
||||||
|
|
|
@ -39,20 +39,20 @@ class TestLockMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertEqual(STATE_UNLOCKED, state.state)
|
assert STATE_UNLOCKED == state.state
|
||||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', 'LOCK')
|
fire_mqtt_message(self.hass, 'state-topic', 'LOCK')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertEqual(STATE_LOCKED, state.state)
|
assert STATE_LOCKED == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', 'UNLOCK')
|
fire_mqtt_message(self.hass, 'state-topic', 'UNLOCK')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertEqual(STATE_UNLOCKED, state.state)
|
assert STATE_UNLOCKED == state.state
|
||||||
|
|
||||||
def test_sending_mqtt_commands_and_optimistic(self):
|
def test_sending_mqtt_commands_and_optimistic(self):
|
||||||
"""Test the sending MQTT commands in optimistic mode."""
|
"""Test the sending MQTT commands in optimistic mode."""
|
||||||
|
@ -68,8 +68,8 @@ class TestLockMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertEqual(STATE_UNLOCKED, state.state)
|
assert STATE_UNLOCKED == state.state
|
||||||
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
|
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
common.lock(self.hass, 'lock.test')
|
common.lock(self.hass, 'lock.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
@ -78,7 +78,7 @@ class TestLockMQTT(unittest.TestCase):
|
||||||
'command-topic', 'LOCK', 2, False)
|
'command-topic', 'LOCK', 2, False)
|
||||||
self.mock_publish.async_publish.reset_mock()
|
self.mock_publish.async_publish.reset_mock()
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertEqual(STATE_LOCKED, state.state)
|
assert STATE_LOCKED == state.state
|
||||||
|
|
||||||
common.unlock(self.hass, 'lock.test')
|
common.unlock(self.hass, 'lock.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
@ -86,7 +86,7 @@ class TestLockMQTT(unittest.TestCase):
|
||||||
self.mock_publish.async_publish.assert_called_once_with(
|
self.mock_publish.async_publish.assert_called_once_with(
|
||||||
'command-topic', 'UNLOCK', 2, False)
|
'command-topic', 'UNLOCK', 2, False)
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertEqual(STATE_UNLOCKED, state.state)
|
assert STATE_UNLOCKED == state.state
|
||||||
|
|
||||||
def test_controlling_state_via_topic_and_json_message(self):
|
def test_controlling_state_via_topic_and_json_message(self):
|
||||||
"""Test the controlling state via topic and JSON message."""
|
"""Test the controlling state via topic and JSON message."""
|
||||||
|
@ -103,23 +103,23 @@ class TestLockMQTT(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertEqual(STATE_UNLOCKED, state.state)
|
assert STATE_UNLOCKED == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', '{"val":"LOCK"}')
|
fire_mqtt_message(self.hass, 'state-topic', '{"val":"LOCK"}')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertEqual(STATE_LOCKED, state.state)
|
assert STATE_LOCKED == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'state-topic', '{"val":"UNLOCK"}')
|
fire_mqtt_message(self.hass, 'state-topic', '{"val":"UNLOCK"}')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertEqual(STATE_UNLOCKED, state.state)
|
assert STATE_UNLOCKED == state.state
|
||||||
|
|
||||||
def test_default_availability_payload(self):
|
def test_default_availability_payload(self):
|
||||||
"""Test availability by default payload with defined topic."""
|
"""Test availability by default payload with defined topic."""
|
||||||
self.assertTrue(setup_component(self.hass, lock.DOMAIN, {
|
assert setup_component(self.hass, lock.DOMAIN, {
|
||||||
lock.DOMAIN: {
|
lock.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -129,26 +129,26 @@ class TestLockMQTT(unittest.TestCase):
|
||||||
'payload_unlock': 'UNLOCK',
|
'payload_unlock': 'UNLOCK',
|
||||||
'availability_topic': 'availability-topic'
|
'availability_topic': 'availability-topic'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
fire_mqtt_message(self.hass, 'availability-topic', 'online')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
def test_custom_availability_payload(self):
|
def test_custom_availability_payload(self):
|
||||||
"""Test availability by custom payload with defined topic."""
|
"""Test availability by custom payload with defined topic."""
|
||||||
self.assertTrue(setup_component(self.hass, lock.DOMAIN, {
|
assert setup_component(self.hass, lock.DOMAIN, {
|
||||||
lock.DOMAIN: {
|
lock.DOMAIN: {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
|
@ -160,22 +160,22 @@ class TestLockMQTT(unittest.TestCase):
|
||||||
'payload_available': 'good',
|
'payload_available': 'good',
|
||||||
'payload_not_available': 'nogood'
|
'payload_not_available': 'nogood'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE != state.state
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get('lock.test')
|
state = self.hass.states.get('lock.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
assert STATE_UNAVAILABLE == state.state
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_lock(hass, mqtt_mock, caplog):
|
async def test_discovery_removal_lock(hass, mqtt_mock, caplog):
|
||||||
|
|
|
@ -11,6 +11,7 @@ from homeassistant.components.websocket_api.const import TYPE_RESULT
|
||||||
from homeassistant.components.lovelace import (load_yaml,
|
from homeassistant.components.lovelace import (load_yaml,
|
||||||
save_yaml, load_config,
|
save_yaml, load_config,
|
||||||
UnsupportedYamlError)
|
UnsupportedYamlError)
|
||||||
|
import pytest
|
||||||
|
|
||||||
TEST_YAML_A = """\
|
TEST_YAML_A = """\
|
||||||
title: My Awesome Home
|
title: My Awesome Home
|
||||||
|
@ -138,7 +139,7 @@ class TestYAML(unittest.TestCase):
|
||||||
fname = self._path_for("test1")
|
fname = self._path_for("test1")
|
||||||
save_yaml(fname, self.yaml.load(TEST_YAML_A))
|
save_yaml(fname, self.yaml.load(TEST_YAML_A))
|
||||||
data = load_yaml(fname)
|
data = load_yaml(fname)
|
||||||
self.assertEqual(data, self.yaml.load(TEST_YAML_A))
|
assert data == self.yaml.load(TEST_YAML_A)
|
||||||
|
|
||||||
def test_overwrite_and_reload(self):
|
def test_overwrite_and_reload(self):
|
||||||
"""Test that we can overwrite an existing file and read back."""
|
"""Test that we can overwrite an existing file and read back."""
|
||||||
|
@ -146,14 +147,14 @@ class TestYAML(unittest.TestCase):
|
||||||
save_yaml(fname, self.yaml.load(TEST_YAML_A))
|
save_yaml(fname, self.yaml.load(TEST_YAML_A))
|
||||||
save_yaml(fname, self.yaml.load(TEST_YAML_B))
|
save_yaml(fname, self.yaml.load(TEST_YAML_B))
|
||||||
data = load_yaml(fname)
|
data = load_yaml(fname)
|
||||||
self.assertEqual(data, self.yaml.load(TEST_YAML_B))
|
assert data == self.yaml.load(TEST_YAML_B)
|
||||||
|
|
||||||
def test_load_bad_data(self):
|
def test_load_bad_data(self):
|
||||||
"""Test error from trying to load unserialisable data."""
|
"""Test error from trying to load unserialisable data."""
|
||||||
fname = self._path_for("test5")
|
fname = self._path_for("test5")
|
||||||
with open(fname, "w") as fh:
|
with open(fname, "w") as fh:
|
||||||
fh.write(TEST_BAD_YAML)
|
fh.write(TEST_BAD_YAML)
|
||||||
with self.assertRaises(HomeAssistantError):
|
with pytest.raises(HomeAssistantError):
|
||||||
load_yaml(fname)
|
load_yaml(fname)
|
||||||
|
|
||||||
def test_add_id(self):
|
def test_add_id(self):
|
||||||
|
@ -172,7 +173,7 @@ class TestYAML(unittest.TestCase):
|
||||||
with patch('homeassistant.components.lovelace.load_yaml',
|
with patch('homeassistant.components.lovelace.load_yaml',
|
||||||
return_value=self.yaml.load(TEST_YAML_B)):
|
return_value=self.yaml.load(TEST_YAML_B)):
|
||||||
data = load_config(fname)
|
data = load_config(fname)
|
||||||
self.assertEqual(data, self.yaml.load(TEST_YAML_B))
|
assert data == self.yaml.load(TEST_YAML_B)
|
||||||
|
|
||||||
|
|
||||||
async def test_deprecated_lovelace_ui(hass, hass_ws_client):
|
async def test_deprecated_lovelace_ui(hass, hass_ws_client):
|
||||||
|
|
|
@ -133,43 +133,43 @@ class TestAsyncMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
def test_volume_up(self):
|
def test_volume_up(self):
|
||||||
"""Test the volume_up helper function."""
|
"""Test the volume_up helper function."""
|
||||||
self.assertEqual(self.player.volume_level, 0)
|
assert self.player.volume_level == 0
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.player.async_set_volume_level(0.5), self.hass.loop).result()
|
self.player.async_set_volume_level(0.5), self.hass.loop).result()
|
||||||
self.assertEqual(self.player.volume_level, 0.5)
|
assert self.player.volume_level == 0.5
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.player.async_volume_up(), self.hass.loop).result()
|
self.player.async_volume_up(), self.hass.loop).result()
|
||||||
self.assertEqual(self.player.volume_level, 0.6)
|
assert self.player.volume_level == 0.6
|
||||||
|
|
||||||
def test_volume_down(self):
|
def test_volume_down(self):
|
||||||
"""Test the volume_down helper function."""
|
"""Test the volume_down helper function."""
|
||||||
self.assertEqual(self.player.volume_level, 0)
|
assert self.player.volume_level == 0
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.player.async_set_volume_level(0.5), self.hass.loop).result()
|
self.player.async_set_volume_level(0.5), self.hass.loop).result()
|
||||||
self.assertEqual(self.player.volume_level, 0.5)
|
assert self.player.volume_level == 0.5
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.player.async_volume_down(), self.hass.loop).result()
|
self.player.async_volume_down(), self.hass.loop).result()
|
||||||
self.assertEqual(self.player.volume_level, 0.4)
|
assert self.player.volume_level == 0.4
|
||||||
|
|
||||||
def test_media_play_pause(self):
|
def test_media_play_pause(self):
|
||||||
"""Test the media_play_pause helper function."""
|
"""Test the media_play_pause helper function."""
|
||||||
self.assertEqual(self.player.state, STATE_OFF)
|
assert self.player.state == STATE_OFF
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.player.async_media_play_pause(), self.hass.loop).result()
|
self.player.async_media_play_pause(), self.hass.loop).result()
|
||||||
self.assertEqual(self.player.state, STATE_PLAYING)
|
assert self.player.state == STATE_PLAYING
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.player.async_media_play_pause(), self.hass.loop).result()
|
self.player.async_media_play_pause(), self.hass.loop).result()
|
||||||
self.assertEqual(self.player.state, STATE_PAUSED)
|
assert self.player.state == STATE_PAUSED
|
||||||
|
|
||||||
def test_toggle(self):
|
def test_toggle(self):
|
||||||
"""Test the toggle helper function."""
|
"""Test the toggle helper function."""
|
||||||
self.assertEqual(self.player.state, STATE_OFF)
|
assert self.player.state == STATE_OFF
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.player.async_toggle(), self.hass.loop).result()
|
self.player.async_toggle(), self.hass.loop).result()
|
||||||
self.assertEqual(self.player.state, STATE_ON)
|
assert self.player.state == STATE_ON
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.player.async_toggle(), self.hass.loop).result()
|
self.player.async_toggle(), self.hass.loop).result()
|
||||||
self.assertEqual(self.player.state, STATE_OFF)
|
assert self.player.state == STATE_OFF
|
||||||
|
|
||||||
|
|
||||||
class TestSyncMediaPlayer(unittest.TestCase):
|
class TestSyncMediaPlayer(unittest.TestCase):
|
||||||
|
@ -186,38 +186,38 @@ class TestSyncMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
def test_volume_up(self):
|
def test_volume_up(self):
|
||||||
"""Test the volume_up helper function."""
|
"""Test the volume_up helper function."""
|
||||||
self.assertEqual(self.player.volume_level, 0)
|
assert self.player.volume_level == 0
|
||||||
self.player.set_volume_level(0.5)
|
self.player.set_volume_level(0.5)
|
||||||
self.assertEqual(self.player.volume_level, 0.5)
|
assert self.player.volume_level == 0.5
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.player.async_volume_up(), self.hass.loop).result()
|
self.player.async_volume_up(), self.hass.loop).result()
|
||||||
self.assertEqual(self.player.volume_level, 0.7)
|
assert self.player.volume_level == 0.7
|
||||||
|
|
||||||
def test_volume_down(self):
|
def test_volume_down(self):
|
||||||
"""Test the volume_down helper function."""
|
"""Test the volume_down helper function."""
|
||||||
self.assertEqual(self.player.volume_level, 0)
|
assert self.player.volume_level == 0
|
||||||
self.player.set_volume_level(0.5)
|
self.player.set_volume_level(0.5)
|
||||||
self.assertEqual(self.player.volume_level, 0.5)
|
assert self.player.volume_level == 0.5
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.player.async_volume_down(), self.hass.loop).result()
|
self.player.async_volume_down(), self.hass.loop).result()
|
||||||
self.assertEqual(self.player.volume_level, 0.3)
|
assert self.player.volume_level == 0.3
|
||||||
|
|
||||||
def test_media_play_pause(self):
|
def test_media_play_pause(self):
|
||||||
"""Test the media_play_pause helper function."""
|
"""Test the media_play_pause helper function."""
|
||||||
self.assertEqual(self.player.state, STATE_OFF)
|
assert self.player.state == STATE_OFF
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.player.async_media_play_pause(), self.hass.loop).result()
|
self.player.async_media_play_pause(), self.hass.loop).result()
|
||||||
self.assertEqual(self.player.state, STATE_PLAYING)
|
assert self.player.state == STATE_PLAYING
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.player.async_media_play_pause(), self.hass.loop).result()
|
self.player.async_media_play_pause(), self.hass.loop).result()
|
||||||
self.assertEqual(self.player.state, STATE_PAUSED)
|
assert self.player.state == STATE_PAUSED
|
||||||
|
|
||||||
def test_toggle(self):
|
def test_toggle(self):
|
||||||
"""Test the toggle helper function."""
|
"""Test the toggle helper function."""
|
||||||
self.assertEqual(self.player.state, STATE_OFF)
|
assert self.player.state == STATE_OFF
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.player.async_toggle(), self.hass.loop).result()
|
self.player.async_toggle(), self.hass.loop).result()
|
||||||
self.assertEqual(self.player.state, STATE_ON)
|
assert self.player.state == STATE_ON
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.player.async_toggle(), self.hass.loop).result()
|
self.player.async_toggle(), self.hass.loop).result()
|
||||||
self.assertEqual(self.player.state, STATE_OFF)
|
assert self.player.state == STATE_OFF
|
||||||
|
|
|
@ -11,6 +11,7 @@ from homeassistant.const import STATE_ON, STATE_OFF
|
||||||
import tests.common
|
import tests.common
|
||||||
from homeassistant.components.media_player.blackbird import (
|
from homeassistant.components.media_player.blackbird import (
|
||||||
DATA_BLACKBIRD, PLATFORM_SCHEMA, SERVICE_SETALLZONES, setup_platform)
|
DATA_BLACKBIRD, PLATFORM_SCHEMA, SERVICE_SETALLZONES, setup_platform)
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
class AttrDict(dict):
|
class AttrDict(dict):
|
||||||
|
@ -157,7 +158,7 @@ class TestBlackbirdSchema(unittest.TestCase):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
for value in schemas:
|
for value in schemas:
|
||||||
with self.assertRaises(vol.MultipleInvalid):
|
with pytest.raises(vol.MultipleInvalid):
|
||||||
PLATFORM_SCHEMA(value)
|
PLATFORM_SCHEMA(value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -192,18 +193,17 @@ class TestBlackbirdMediaPlayer(unittest.TestCase):
|
||||||
def test_setup_platform(self, *args):
|
def test_setup_platform(self, *args):
|
||||||
"""Test setting up platform."""
|
"""Test setting up platform."""
|
||||||
# One service must be registered
|
# One service must be registered
|
||||||
self.assertTrue(self.hass.services.has_service(DOMAIN,
|
assert self.hass.services.has_service(DOMAIN, SERVICE_SETALLZONES)
|
||||||
SERVICE_SETALLZONES))
|
assert len(self.hass.data[DATA_BLACKBIRD]) == 1
|
||||||
self.assertEqual(len(self.hass.data[DATA_BLACKBIRD]), 1)
|
assert self.hass.data[DATA_BLACKBIRD]['/dev/ttyUSB0-3'].name == \
|
||||||
self.assertEqual(self.hass.data[DATA_BLACKBIRD]['/dev/ttyUSB0-3'].name,
|
'Zone name'
|
||||||
'Zone name')
|
|
||||||
|
|
||||||
def test_setallzones_service_call_with_entity_id(self):
|
def test_setallzones_service_call_with_entity_id(self):
|
||||||
"""Test set all zone source service call with entity id."""
|
"""Test set all zone source service call with entity id."""
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('Zone name', self.media_player.name)
|
assert 'Zone name' == self.media_player.name
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
self.assertEqual('one', self.media_player.source)
|
assert 'one' == self.media_player.source
|
||||||
|
|
||||||
# Call set all zones service
|
# Call set all zones service
|
||||||
self.hass.services.call(DOMAIN, SERVICE_SETALLZONES,
|
self.hass.services.call(DOMAIN, SERVICE_SETALLZONES,
|
||||||
|
@ -212,110 +212,110 @@ class TestBlackbirdMediaPlayer(unittest.TestCase):
|
||||||
blocking=True)
|
blocking=True)
|
||||||
|
|
||||||
# Check that source was changed
|
# Check that source was changed
|
||||||
self.assertEqual(3, self.blackbird.zones[3].av)
|
assert 3 == self.blackbird.zones[3].av
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('three', self.media_player.source)
|
assert 'three' == self.media_player.source
|
||||||
|
|
||||||
def test_setallzones_service_call_without_entity_id(self):
|
def test_setallzones_service_call_without_entity_id(self):
|
||||||
"""Test set all zone source service call without entity id."""
|
"""Test set all zone source service call without entity id."""
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('Zone name', self.media_player.name)
|
assert 'Zone name' == self.media_player.name
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
self.assertEqual('one', self.media_player.source)
|
assert 'one' == self.media_player.source
|
||||||
|
|
||||||
# Call set all zones service
|
# Call set all zones service
|
||||||
self.hass.services.call(DOMAIN, SERVICE_SETALLZONES,
|
self.hass.services.call(DOMAIN, SERVICE_SETALLZONES,
|
||||||
{'source': 'three'}, blocking=True)
|
{'source': 'three'}, blocking=True)
|
||||||
|
|
||||||
# Check that source was changed
|
# Check that source was changed
|
||||||
self.assertEqual(3, self.blackbird.zones[3].av)
|
assert 3 == self.blackbird.zones[3].av
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('three', self.media_player.source)
|
assert 'three' == self.media_player.source
|
||||||
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
"""Test updating values from blackbird."""
|
"""Test updating values from blackbird."""
|
||||||
self.assertIsNone(self.media_player.state)
|
assert self.media_player.state is None
|
||||||
self.assertIsNone(self.media_player.source)
|
assert self.media_player.source is None
|
||||||
|
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
|
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
self.assertEqual('one', self.media_player.source)
|
assert 'one' == self.media_player.source
|
||||||
|
|
||||||
def test_name(self):
|
def test_name(self):
|
||||||
"""Test name property."""
|
"""Test name property."""
|
||||||
self.assertEqual('Zone name', self.media_player.name)
|
assert 'Zone name' == self.media_player.name
|
||||||
|
|
||||||
def test_state(self):
|
def test_state(self):
|
||||||
"""Test state property."""
|
"""Test state property."""
|
||||||
self.assertIsNone(self.media_player.state)
|
assert self.media_player.state is None
|
||||||
|
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
|
|
||||||
self.blackbird.zones[3].power = False
|
self.blackbird.zones[3].power = False
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(STATE_OFF, self.media_player.state)
|
assert STATE_OFF == self.media_player.state
|
||||||
|
|
||||||
def test_supported_features(self):
|
def test_supported_features(self):
|
||||||
"""Test supported features property."""
|
"""Test supported features property."""
|
||||||
self.assertEqual(SUPPORT_TURN_ON | SUPPORT_TURN_OFF |
|
assert SUPPORT_TURN_ON | SUPPORT_TURN_OFF | \
|
||||||
SUPPORT_SELECT_SOURCE,
|
SUPPORT_SELECT_SOURCE == \
|
||||||
self.media_player.supported_features)
|
self.media_player.supported_features
|
||||||
|
|
||||||
def test_source(self):
|
def test_source(self):
|
||||||
"""Test source property."""
|
"""Test source property."""
|
||||||
self.assertIsNone(self.media_player.source)
|
assert self.media_player.source is None
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('one', self.media_player.source)
|
assert 'one' == self.media_player.source
|
||||||
|
|
||||||
def test_media_title(self):
|
def test_media_title(self):
|
||||||
"""Test media title property."""
|
"""Test media title property."""
|
||||||
self.assertIsNone(self.media_player.media_title)
|
assert self.media_player.media_title is None
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('one', self.media_player.media_title)
|
assert 'one' == self.media_player.media_title
|
||||||
|
|
||||||
def test_source_list(self):
|
def test_source_list(self):
|
||||||
"""Test source list property."""
|
"""Test source list property."""
|
||||||
# Note, the list is sorted!
|
# Note, the list is sorted!
|
||||||
self.assertEqual(['one', 'two', 'three'],
|
assert ['one', 'two', 'three'] == \
|
||||||
self.media_player.source_list)
|
self.media_player.source_list
|
||||||
|
|
||||||
def test_select_source(self):
|
def test_select_source(self):
|
||||||
"""Test source selection methods."""
|
"""Test source selection methods."""
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
|
|
||||||
self.assertEqual('one', self.media_player.source)
|
assert 'one' == self.media_player.source
|
||||||
|
|
||||||
self.media_player.select_source('two')
|
self.media_player.select_source('two')
|
||||||
self.assertEqual(2, self.blackbird.zones[3].av)
|
assert 2 == self.blackbird.zones[3].av
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('two', self.media_player.source)
|
assert 'two' == self.media_player.source
|
||||||
|
|
||||||
# Trying to set unknown source.
|
# Trying to set unknown source.
|
||||||
self.media_player.select_source('no name')
|
self.media_player.select_source('no name')
|
||||||
self.assertEqual(2, self.blackbird.zones[3].av)
|
assert 2 == self.blackbird.zones[3].av
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('two', self.media_player.source)
|
assert 'two' == self.media_player.source
|
||||||
|
|
||||||
def test_turn_on(self):
|
def test_turn_on(self):
|
||||||
"""Testing turning on the zone."""
|
"""Testing turning on the zone."""
|
||||||
self.blackbird.zones[3].power = False
|
self.blackbird.zones[3].power = False
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(STATE_OFF, self.media_player.state)
|
assert STATE_OFF == self.media_player.state
|
||||||
|
|
||||||
self.media_player.turn_on()
|
self.media_player.turn_on()
|
||||||
self.assertTrue(self.blackbird.zones[3].power)
|
assert self.blackbird.zones[3].power
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
|
|
||||||
def test_turn_off(self):
|
def test_turn_off(self):
|
||||||
"""Testing turning off the zone."""
|
"""Testing turning off the zone."""
|
||||||
self.blackbird.zones[3].power = True
|
self.blackbird.zones[3].power = True
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
|
|
||||||
self.media_player.turn_off()
|
self.media_player.turn_off()
|
||||||
self.assertFalse(self.blackbird.zones[3].power)
|
assert not self.blackbird.zones[3].power
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(STATE_OFF, self.media_player.state)
|
assert STATE_OFF == self.media_player.state
|
||||||
|
|
|
@ -13,6 +13,7 @@ import tests.common
|
||||||
from homeassistant.components.media_player.monoprice import (
|
from homeassistant.components.media_player.monoprice import (
|
||||||
DATA_MONOPRICE, PLATFORM_SCHEMA, SERVICE_SNAPSHOT,
|
DATA_MONOPRICE, PLATFORM_SCHEMA, SERVICE_SNAPSHOT,
|
||||||
SERVICE_RESTORE, setup_platform)
|
SERVICE_RESTORE, setup_platform)
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
class AttrDict(dict):
|
class AttrDict(dict):
|
||||||
|
@ -149,7 +150,7 @@ class TestMonopriceSchema(unittest.TestCase):
|
||||||
|
|
||||||
)
|
)
|
||||||
for value in schemas:
|
for value in schemas:
|
||||||
with self.assertRaises(vol.MultipleInvalid):
|
with pytest.raises(vol.MultipleInvalid):
|
||||||
PLATFORM_SCHEMA(value)
|
PLATFORM_SCHEMA(value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -185,21 +186,19 @@ class TestMonopriceMediaPlayer(unittest.TestCase):
|
||||||
def test_setup_platform(self, *args):
|
def test_setup_platform(self, *args):
|
||||||
"""Test setting up platform."""
|
"""Test setting up platform."""
|
||||||
# Two services must be registered
|
# Two services must be registered
|
||||||
self.assertTrue(self.hass.services.has_service(DOMAIN,
|
assert self.hass.services.has_service(DOMAIN, SERVICE_RESTORE)
|
||||||
SERVICE_RESTORE))
|
assert self.hass.services.has_service(DOMAIN, SERVICE_SNAPSHOT)
|
||||||
self.assertTrue(self.hass.services.has_service(DOMAIN,
|
assert len(self.hass.data[DATA_MONOPRICE]) == 1
|
||||||
SERVICE_SNAPSHOT))
|
assert self.hass.data[DATA_MONOPRICE][0].name == 'Zone name'
|
||||||
self.assertEqual(len(self.hass.data[DATA_MONOPRICE]), 1)
|
|
||||||
self.assertEqual(self.hass.data[DATA_MONOPRICE][0].name, 'Zone name')
|
|
||||||
|
|
||||||
def test_service_calls_with_entity_id(self):
|
def test_service_calls_with_entity_id(self):
|
||||||
"""Test snapshot save/restore service calls."""
|
"""Test snapshot save/restore service calls."""
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('Zone name', self.media_player.name)
|
assert 'Zone name' == self.media_player.name
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
self.assertEqual(0.0, self.media_player.volume_level, 0.0001)
|
assert 0.0 == self.media_player.volume_level, 0.0001
|
||||||
self.assertTrue(self.media_player.is_volume_muted)
|
assert self.media_player.is_volume_muted
|
||||||
self.assertEqual('one', self.media_player.source)
|
assert 'one' == self.media_player.source
|
||||||
|
|
||||||
# Saving default values
|
# Saving default values
|
||||||
self.hass.services.call(DOMAIN, SERVICE_SNAPSHOT,
|
self.hass.services.call(DOMAIN, SERVICE_SNAPSHOT,
|
||||||
|
@ -215,11 +214,11 @@ class TestMonopriceMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
# Checking that values were indeed changed
|
# Checking that values were indeed changed
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('Zone name', self.media_player.name)
|
assert 'Zone name' == self.media_player.name
|
||||||
self.assertEqual(STATE_OFF, self.media_player.state)
|
assert STATE_OFF == self.media_player.state
|
||||||
self.assertEqual(1.0, self.media_player.volume_level, 0.0001)
|
assert 1.0 == self.media_player.volume_level, 0.0001
|
||||||
self.assertFalse(self.media_player.is_volume_muted)
|
assert not self.media_player.is_volume_muted
|
||||||
self.assertEqual('two', self.media_player.source)
|
assert 'two' == self.media_player.source
|
||||||
|
|
||||||
# Restoring wrong media player to its previous state
|
# Restoring wrong media player to its previous state
|
||||||
# Nothing should be done
|
# Nothing should be done
|
||||||
|
@ -230,11 +229,11 @@ class TestMonopriceMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
# Checking that values were not (!) restored
|
# Checking that values were not (!) restored
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('Zone name', self.media_player.name)
|
assert 'Zone name' == self.media_player.name
|
||||||
self.assertEqual(STATE_OFF, self.media_player.state)
|
assert STATE_OFF == self.media_player.state
|
||||||
self.assertEqual(1.0, self.media_player.volume_level, 0.0001)
|
assert 1.0 == self.media_player.volume_level, 0.0001
|
||||||
self.assertFalse(self.media_player.is_volume_muted)
|
assert not self.media_player.is_volume_muted
|
||||||
self.assertEqual('two', self.media_player.source)
|
assert 'two' == self.media_player.source
|
||||||
|
|
||||||
# Restoring media player to its previous state
|
# Restoring media player to its previous state
|
||||||
self.hass.services.call(DOMAIN, SERVICE_RESTORE,
|
self.hass.services.call(DOMAIN, SERVICE_RESTORE,
|
||||||
|
@ -243,31 +242,31 @@ class TestMonopriceMediaPlayer(unittest.TestCase):
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
# Checking that values were restored
|
# Checking that values were restored
|
||||||
self.assertEqual('Zone name', self.media_player.name)
|
assert 'Zone name' == self.media_player.name
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
self.assertEqual(0.0, self.media_player.volume_level, 0.0001)
|
assert 0.0 == self.media_player.volume_level, 0.0001
|
||||||
self.assertTrue(self.media_player.is_volume_muted)
|
assert self.media_player.is_volume_muted
|
||||||
self.assertEqual('one', self.media_player.source)
|
assert 'one' == self.media_player.source
|
||||||
|
|
||||||
def test_service_calls_without_entity_id(self):
|
def test_service_calls_without_entity_id(self):
|
||||||
"""Test snapshot save/restore service calls."""
|
"""Test snapshot save/restore service calls."""
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('Zone name', self.media_player.name)
|
assert 'Zone name' == self.media_player.name
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
self.assertEqual(0.0, self.media_player.volume_level, 0.0001)
|
assert 0.0 == self.media_player.volume_level, 0.0001
|
||||||
self.assertTrue(self.media_player.is_volume_muted)
|
assert self.media_player.is_volume_muted
|
||||||
self.assertEqual('one', self.media_player.source)
|
assert 'one' == self.media_player.source
|
||||||
|
|
||||||
# Restoring media player
|
# Restoring media player
|
||||||
# since there is no snapshot, nothing should be done
|
# since there is no snapshot, nothing should be done
|
||||||
self.hass.services.call(DOMAIN, SERVICE_RESTORE, blocking=True)
|
self.hass.services.call(DOMAIN, SERVICE_RESTORE, blocking=True)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('Zone name', self.media_player.name)
|
assert 'Zone name' == self.media_player.name
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
self.assertEqual(0.0, self.media_player.volume_level, 0.0001)
|
assert 0.0 == self.media_player.volume_level, 0.0001
|
||||||
self.assertTrue(self.media_player.is_volume_muted)
|
assert self.media_player.is_volume_muted
|
||||||
self.assertEqual('one', self.media_player.source)
|
assert 'one' == self.media_player.source
|
||||||
|
|
||||||
# Saving default values
|
# Saving default values
|
||||||
self.hass.services.call(DOMAIN, SERVICE_SNAPSHOT, blocking=True)
|
self.hass.services.call(DOMAIN, SERVICE_SNAPSHOT, blocking=True)
|
||||||
|
@ -281,195 +280,195 @@ class TestMonopriceMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
# Checking that values were indeed changed
|
# Checking that values were indeed changed
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('Zone name', self.media_player.name)
|
assert 'Zone name' == self.media_player.name
|
||||||
self.assertEqual(STATE_OFF, self.media_player.state)
|
assert STATE_OFF == self.media_player.state
|
||||||
self.assertEqual(1.0, self.media_player.volume_level, 0.0001)
|
assert 1.0 == self.media_player.volume_level, 0.0001
|
||||||
self.assertFalse(self.media_player.is_volume_muted)
|
assert not self.media_player.is_volume_muted
|
||||||
self.assertEqual('two', self.media_player.source)
|
assert 'two' == self.media_player.source
|
||||||
|
|
||||||
# Restoring media player to its previous state
|
# Restoring media player to its previous state
|
||||||
self.hass.services.call(DOMAIN, SERVICE_RESTORE, blocking=True)
|
self.hass.services.call(DOMAIN, SERVICE_RESTORE, blocking=True)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
# Checking that values were restored
|
# Checking that values were restored
|
||||||
self.assertEqual('Zone name', self.media_player.name)
|
assert 'Zone name' == self.media_player.name
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
self.assertEqual(0.0, self.media_player.volume_level, 0.0001)
|
assert 0.0 == self.media_player.volume_level, 0.0001
|
||||||
self.assertTrue(self.media_player.is_volume_muted)
|
assert self.media_player.is_volume_muted
|
||||||
self.assertEqual('one', self.media_player.source)
|
assert 'one' == self.media_player.source
|
||||||
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
"""Test updating values from monoprice."""
|
"""Test updating values from monoprice."""
|
||||||
self.assertIsNone(self.media_player.state)
|
assert self.media_player.state is None
|
||||||
self.assertIsNone(self.media_player.volume_level)
|
assert self.media_player.volume_level is None
|
||||||
self.assertIsNone(self.media_player.is_volume_muted)
|
assert self.media_player.is_volume_muted is None
|
||||||
self.assertIsNone(self.media_player.source)
|
assert self.media_player.source is None
|
||||||
|
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
|
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
self.assertEqual(0.0, self.media_player.volume_level, 0.0001)
|
assert 0.0 == self.media_player.volume_level, 0.0001
|
||||||
self.assertTrue(self.media_player.is_volume_muted)
|
assert self.media_player.is_volume_muted
|
||||||
self.assertEqual('one', self.media_player.source)
|
assert 'one' == self.media_player.source
|
||||||
|
|
||||||
def test_name(self):
|
def test_name(self):
|
||||||
"""Test name property."""
|
"""Test name property."""
|
||||||
self.assertEqual('Zone name', self.media_player.name)
|
assert 'Zone name' == self.media_player.name
|
||||||
|
|
||||||
def test_state(self):
|
def test_state(self):
|
||||||
"""Test state property."""
|
"""Test state property."""
|
||||||
self.assertIsNone(self.media_player.state)
|
assert self.media_player.state is None
|
||||||
|
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
|
|
||||||
self.monoprice.zones[12].power = False
|
self.monoprice.zones[12].power = False
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(STATE_OFF, self.media_player.state)
|
assert STATE_OFF == self.media_player.state
|
||||||
|
|
||||||
def test_volume_level(self):
|
def test_volume_level(self):
|
||||||
"""Test volume level property."""
|
"""Test volume level property."""
|
||||||
self.assertIsNone(self.media_player.volume_level)
|
assert self.media_player.volume_level is None
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(0.0, self.media_player.volume_level, 0.0001)
|
assert 0.0 == self.media_player.volume_level, 0.0001
|
||||||
|
|
||||||
self.monoprice.zones[12].volume = 38
|
self.monoprice.zones[12].volume = 38
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(1.0, self.media_player.volume_level, 0.0001)
|
assert 1.0 == self.media_player.volume_level, 0.0001
|
||||||
|
|
||||||
self.monoprice.zones[12].volume = 19
|
self.monoprice.zones[12].volume = 19
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(.5, self.media_player.volume_level, 0.0001)
|
assert .5 == self.media_player.volume_level, 0.0001
|
||||||
|
|
||||||
def test_is_volume_muted(self):
|
def test_is_volume_muted(self):
|
||||||
"""Test volume muted property."""
|
"""Test volume muted property."""
|
||||||
self.assertIsNone(self.media_player.is_volume_muted)
|
assert self.media_player.is_volume_muted is None
|
||||||
|
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertTrue(self.media_player.is_volume_muted)
|
assert self.media_player.is_volume_muted
|
||||||
|
|
||||||
self.monoprice.zones[12].mute = False
|
self.monoprice.zones[12].mute = False
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertFalse(self.media_player.is_volume_muted)
|
assert not self.media_player.is_volume_muted
|
||||||
|
|
||||||
def test_supported_features(self):
|
def test_supported_features(self):
|
||||||
"""Test supported features property."""
|
"""Test supported features property."""
|
||||||
self.assertEqual(SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_SET |
|
assert SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_SET | \
|
||||||
SUPPORT_VOLUME_STEP | SUPPORT_TURN_ON |
|
SUPPORT_VOLUME_STEP | SUPPORT_TURN_ON | \
|
||||||
SUPPORT_TURN_OFF | SUPPORT_SELECT_SOURCE,
|
SUPPORT_TURN_OFF | SUPPORT_SELECT_SOURCE == \
|
||||||
self.media_player.supported_features)
|
self.media_player.supported_features
|
||||||
|
|
||||||
def test_source(self):
|
def test_source(self):
|
||||||
"""Test source property."""
|
"""Test source property."""
|
||||||
self.assertIsNone(self.media_player.source)
|
assert self.media_player.source is None
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('one', self.media_player.source)
|
assert 'one' == self.media_player.source
|
||||||
|
|
||||||
def test_media_title(self):
|
def test_media_title(self):
|
||||||
"""Test media title property."""
|
"""Test media title property."""
|
||||||
self.assertIsNone(self.media_player.media_title)
|
assert self.media_player.media_title is None
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('one', self.media_player.media_title)
|
assert 'one' == self.media_player.media_title
|
||||||
|
|
||||||
def test_source_list(self):
|
def test_source_list(self):
|
||||||
"""Test source list property."""
|
"""Test source list property."""
|
||||||
# Note, the list is sorted!
|
# Note, the list is sorted!
|
||||||
self.assertEqual(['one', 'two', 'three'],
|
assert ['one', 'two', 'three'] == \
|
||||||
self.media_player.source_list)
|
self.media_player.source_list
|
||||||
|
|
||||||
def test_select_source(self):
|
def test_select_source(self):
|
||||||
"""Test source selection methods."""
|
"""Test source selection methods."""
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
|
|
||||||
self.assertEqual('one', self.media_player.source)
|
assert 'one' == self.media_player.source
|
||||||
|
|
||||||
self.media_player.select_source('two')
|
self.media_player.select_source('two')
|
||||||
self.assertEqual(2, self.monoprice.zones[12].source)
|
assert 2 == self.monoprice.zones[12].source
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('two', self.media_player.source)
|
assert 'two' == self.media_player.source
|
||||||
|
|
||||||
# Trying to set unknown source
|
# Trying to set unknown source
|
||||||
self.media_player.select_source('no name')
|
self.media_player.select_source('no name')
|
||||||
self.assertEqual(2, self.monoprice.zones[12].source)
|
assert 2 == self.monoprice.zones[12].source
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual('two', self.media_player.source)
|
assert 'two' == self.media_player.source
|
||||||
|
|
||||||
def test_turn_on(self):
|
def test_turn_on(self):
|
||||||
"""Test turning on the zone."""
|
"""Test turning on the zone."""
|
||||||
self.monoprice.zones[12].power = False
|
self.monoprice.zones[12].power = False
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(STATE_OFF, self.media_player.state)
|
assert STATE_OFF == self.media_player.state
|
||||||
|
|
||||||
self.media_player.turn_on()
|
self.media_player.turn_on()
|
||||||
self.assertTrue(self.monoprice.zones[12].power)
|
assert self.monoprice.zones[12].power
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
|
|
||||||
def test_turn_off(self):
|
def test_turn_off(self):
|
||||||
"""Test turning off the zone."""
|
"""Test turning off the zone."""
|
||||||
self.monoprice.zones[12].power = True
|
self.monoprice.zones[12].power = True
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(STATE_ON, self.media_player.state)
|
assert STATE_ON == self.media_player.state
|
||||||
|
|
||||||
self.media_player.turn_off()
|
self.media_player.turn_off()
|
||||||
self.assertFalse(self.monoprice.zones[12].power)
|
assert not self.monoprice.zones[12].power
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertEqual(STATE_OFF, self.media_player.state)
|
assert STATE_OFF == self.media_player.state
|
||||||
|
|
||||||
def test_mute_volume(self):
|
def test_mute_volume(self):
|
||||||
"""Test mute functionality."""
|
"""Test mute functionality."""
|
||||||
self.monoprice.zones[12].mute = True
|
self.monoprice.zones[12].mute = True
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertTrue(self.media_player.is_volume_muted)
|
assert self.media_player.is_volume_muted
|
||||||
|
|
||||||
self.media_player.mute_volume(False)
|
self.media_player.mute_volume(False)
|
||||||
self.assertFalse(self.monoprice.zones[12].mute)
|
assert not self.monoprice.zones[12].mute
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertFalse(self.media_player.is_volume_muted)
|
assert not self.media_player.is_volume_muted
|
||||||
|
|
||||||
self.media_player.mute_volume(True)
|
self.media_player.mute_volume(True)
|
||||||
self.assertTrue(self.monoprice.zones[12].mute)
|
assert self.monoprice.zones[12].mute
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.assertTrue(self.media_player.is_volume_muted)
|
assert self.media_player.is_volume_muted
|
||||||
|
|
||||||
def test_set_volume_level(self):
|
def test_set_volume_level(self):
|
||||||
"""Test set volume level."""
|
"""Test set volume level."""
|
||||||
self.media_player.set_volume_level(1.0)
|
self.media_player.set_volume_level(1.0)
|
||||||
self.assertEqual(38, self.monoprice.zones[12].volume)
|
assert 38 == self.monoprice.zones[12].volume
|
||||||
self.assertTrue(isinstance(self.monoprice.zones[12].volume, int))
|
assert isinstance(self.monoprice.zones[12].volume, int)
|
||||||
|
|
||||||
self.media_player.set_volume_level(0.0)
|
self.media_player.set_volume_level(0.0)
|
||||||
self.assertEqual(0, self.monoprice.zones[12].volume)
|
assert 0 == self.monoprice.zones[12].volume
|
||||||
self.assertTrue(isinstance(self.monoprice.zones[12].volume, int))
|
assert isinstance(self.monoprice.zones[12].volume, int)
|
||||||
|
|
||||||
self.media_player.set_volume_level(0.5)
|
self.media_player.set_volume_level(0.5)
|
||||||
self.assertEqual(19, self.monoprice.zones[12].volume)
|
assert 19 == self.monoprice.zones[12].volume
|
||||||
self.assertTrue(isinstance(self.monoprice.zones[12].volume, int))
|
assert isinstance(self.monoprice.zones[12].volume, int)
|
||||||
|
|
||||||
def test_volume_up(self):
|
def test_volume_up(self):
|
||||||
"""Test increasing volume by one."""
|
"""Test increasing volume by one."""
|
||||||
self.monoprice.zones[12].volume = 37
|
self.monoprice.zones[12].volume = 37
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.media_player.volume_up()
|
self.media_player.volume_up()
|
||||||
self.assertEqual(38, self.monoprice.zones[12].volume)
|
assert 38 == self.monoprice.zones[12].volume
|
||||||
self.assertTrue(isinstance(self.monoprice.zones[12].volume, int))
|
assert isinstance(self.monoprice.zones[12].volume, int)
|
||||||
|
|
||||||
# Try to raise value beyond max
|
# Try to raise value beyond max
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.media_player.volume_up()
|
self.media_player.volume_up()
|
||||||
self.assertEqual(38, self.monoprice.zones[12].volume)
|
assert 38 == self.monoprice.zones[12].volume
|
||||||
self.assertTrue(isinstance(self.monoprice.zones[12].volume, int))
|
assert isinstance(self.monoprice.zones[12].volume, int)
|
||||||
|
|
||||||
def test_volume_down(self):
|
def test_volume_down(self):
|
||||||
"""Test decreasing volume by one."""
|
"""Test decreasing volume by one."""
|
||||||
self.monoprice.zones[12].volume = 1
|
self.monoprice.zones[12].volume = 1
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.media_player.volume_down()
|
self.media_player.volume_down()
|
||||||
self.assertEqual(0, self.monoprice.zones[12].volume)
|
assert 0 == self.monoprice.zones[12].volume
|
||||||
self.assertTrue(isinstance(self.monoprice.zones[12].volume, int))
|
assert isinstance(self.monoprice.zones[12].volume, int)
|
||||||
|
|
||||||
# Try to lower value beyond minimum
|
# Try to lower value beyond minimum
|
||||||
self.media_player.update()
|
self.media_player.update()
|
||||||
self.media_player.volume_down()
|
self.media_player.volume_down()
|
||||||
self.assertEqual(0, self.monoprice.zones[12].volume)
|
assert 0 == self.monoprice.zones[12].volume
|
||||||
self.assertTrue(isinstance(self.monoprice.zones[12].volume, int))
|
assert isinstance(self.monoprice.zones[12].volume, int)
|
||||||
|
|
|
@ -102,7 +102,7 @@ class TestSamsungTv(unittest.TestCase):
|
||||||
def test_update_on(self):
|
def test_update_on(self):
|
||||||
"""Testing update tv on."""
|
"""Testing update tv on."""
|
||||||
self.device.update()
|
self.device.update()
|
||||||
self.assertEqual(None, self.device._state)
|
assert self.device._state is None
|
||||||
|
|
||||||
def test_update_off(self):
|
def test_update_off(self):
|
||||||
"""Testing update tv off."""
|
"""Testing update tv off."""
|
||||||
|
@ -111,12 +111,12 @@ class TestSamsungTv(unittest.TestCase):
|
||||||
side_effect=OSError('Boom'))
|
side_effect=OSError('Boom'))
|
||||||
self.device.get_remote = mock.Mock(return_value=_remote)
|
self.device.get_remote = mock.Mock(return_value=_remote)
|
||||||
self.device.update()
|
self.device.update()
|
||||||
self.assertEqual(STATE_OFF, self.device._state)
|
assert STATE_OFF == self.device._state
|
||||||
|
|
||||||
def test_send_key(self):
|
def test_send_key(self):
|
||||||
"""Test for send key."""
|
"""Test for send key."""
|
||||||
self.device.send_key('KEY_POWER')
|
self.device.send_key('KEY_POWER')
|
||||||
self.assertEqual(None, self.device._state)
|
assert self.device._state is None
|
||||||
|
|
||||||
def test_send_key_broken_pipe(self):
|
def test_send_key_broken_pipe(self):
|
||||||
"""Testing broken pipe Exception."""
|
"""Testing broken pipe Exception."""
|
||||||
|
@ -125,8 +125,8 @@ class TestSamsungTv(unittest.TestCase):
|
||||||
side_effect=BrokenPipeError('Boom'))
|
side_effect=BrokenPipeError('Boom'))
|
||||||
self.device.get_remote = mock.Mock(return_value=_remote)
|
self.device.get_remote = mock.Mock(return_value=_remote)
|
||||||
self.device.send_key('HELLO')
|
self.device.send_key('HELLO')
|
||||||
self.assertIsNone(self.device._remote)
|
assert self.device._remote is None
|
||||||
self.assertEqual(None, self.device._state)
|
assert self.device._state is None
|
||||||
|
|
||||||
def test_send_key_connection_closed_retry_succeed(self):
|
def test_send_key_connection_closed_retry_succeed(self):
|
||||||
"""Test retry on connection closed."""
|
"""Test retry on connection closed."""
|
||||||
|
@ -137,11 +137,11 @@ class TestSamsungTv(unittest.TestCase):
|
||||||
self.device.get_remote = mock.Mock(return_value=_remote)
|
self.device.get_remote = mock.Mock(return_value=_remote)
|
||||||
command = 'HELLO'
|
command = 'HELLO'
|
||||||
self.device.send_key(command)
|
self.device.send_key(command)
|
||||||
self.assertEqual(None, self.device._state)
|
assert self.device._state is None
|
||||||
# verify that _remote.control() get called twice because of retry logic
|
# verify that _remote.control() get called twice because of retry logic
|
||||||
expected = [mock.call(command),
|
expected = [mock.call(command),
|
||||||
mock.call(command)]
|
mock.call(command)]
|
||||||
self.assertEqual(expected, _remote.control.call_args_list)
|
assert expected == _remote.control.call_args_list
|
||||||
|
|
||||||
def test_send_key_unhandled_response(self):
|
def test_send_key_unhandled_response(self):
|
||||||
"""Testing unhandled response exception."""
|
"""Testing unhandled response exception."""
|
||||||
|
@ -151,8 +151,8 @@ class TestSamsungTv(unittest.TestCase):
|
||||||
)
|
)
|
||||||
self.device.get_remote = mock.Mock(return_value=_remote)
|
self.device.get_remote = mock.Mock(return_value=_remote)
|
||||||
self.device.send_key('HELLO')
|
self.device.send_key('HELLO')
|
||||||
self.assertIsNone(self.device._remote)
|
assert self.device._remote is None
|
||||||
self.assertEqual(None, self.device._state)
|
assert self.device._state is None
|
||||||
|
|
||||||
def test_send_key_os_error(self):
|
def test_send_key_os_error(self):
|
||||||
"""Testing broken pipe Exception."""
|
"""Testing broken pipe Exception."""
|
||||||
|
@ -161,42 +161,41 @@ class TestSamsungTv(unittest.TestCase):
|
||||||
side_effect=OSError('Boom'))
|
side_effect=OSError('Boom'))
|
||||||
self.device.get_remote = mock.Mock(return_value=_remote)
|
self.device.get_remote = mock.Mock(return_value=_remote)
|
||||||
self.device.send_key('HELLO')
|
self.device.send_key('HELLO')
|
||||||
self.assertIsNone(self.device._remote)
|
assert self.device._remote is None
|
||||||
self.assertEqual(STATE_OFF, self.device._state)
|
assert STATE_OFF == self.device._state
|
||||||
|
|
||||||
def test_power_off_in_progress(self):
|
def test_power_off_in_progress(self):
|
||||||
"""Test for power_off_in_progress."""
|
"""Test for power_off_in_progress."""
|
||||||
self.assertFalse(self.device._power_off_in_progress())
|
assert not self.device._power_off_in_progress()
|
||||||
self.device._end_of_power_off = dt_util.utcnow() + timedelta(
|
self.device._end_of_power_off = dt_util.utcnow() + timedelta(
|
||||||
seconds=15)
|
seconds=15)
|
||||||
self.assertTrue(self.device._power_off_in_progress())
|
assert self.device._power_off_in_progress()
|
||||||
|
|
||||||
def test_name(self):
|
def test_name(self):
|
||||||
"""Test for name property."""
|
"""Test for name property."""
|
||||||
self.assertEqual('fake', self.device.name)
|
assert 'fake' == self.device.name
|
||||||
|
|
||||||
def test_state(self):
|
def test_state(self):
|
||||||
"""Test for state property."""
|
"""Test for state property."""
|
||||||
self.device._state = None
|
self.device._state = None
|
||||||
self.assertEqual(None, self.device.state)
|
assert self.device.state is None
|
||||||
self.device._state = STATE_OFF
|
self.device._state = STATE_OFF
|
||||||
self.assertEqual(STATE_OFF, self.device.state)
|
assert STATE_OFF == self.device.state
|
||||||
|
|
||||||
def test_is_volume_muted(self):
|
def test_is_volume_muted(self):
|
||||||
"""Test for is_volume_muted property."""
|
"""Test for is_volume_muted property."""
|
||||||
self.device._muted = False
|
self.device._muted = False
|
||||||
self.assertFalse(self.device.is_volume_muted)
|
assert not self.device.is_volume_muted
|
||||||
self.device._muted = True
|
self.device._muted = True
|
||||||
self.assertTrue(self.device.is_volume_muted)
|
assert self.device.is_volume_muted
|
||||||
|
|
||||||
def test_supported_features(self):
|
def test_supported_features(self):
|
||||||
"""Test for supported_features property."""
|
"""Test for supported_features property."""
|
||||||
self.device._mac = None
|
self.device._mac = None
|
||||||
self.assertEqual(SUPPORT_SAMSUNGTV, self.device.supported_features)
|
assert SUPPORT_SAMSUNGTV == self.device.supported_features
|
||||||
self.device._mac = "fake"
|
self.device._mac = "fake"
|
||||||
self.assertEqual(
|
assert SUPPORT_SAMSUNGTV | SUPPORT_TURN_ON == \
|
||||||
SUPPORT_SAMSUNGTV | SUPPORT_TURN_ON,
|
self.device.supported_features
|
||||||
self.device.supported_features)
|
|
||||||
|
|
||||||
def test_turn_off(self):
|
def test_turn_off(self):
|
||||||
"""Test for turn_off."""
|
"""Test for turn_off."""
|
||||||
|
@ -206,7 +205,7 @@ class TestSamsungTv(unittest.TestCase):
|
||||||
self.get_remote = mock.Mock(return_value=_remote)
|
self.get_remote = mock.Mock(return_value=_remote)
|
||||||
self.device._end_of_power_off = None
|
self.device._end_of_power_off = None
|
||||||
self.device.turn_off()
|
self.device.turn_off()
|
||||||
self.assertIsNotNone(self.device._end_of_power_off)
|
assert self.device._end_of_power_off is not None
|
||||||
self.device.send_key.assert_called_once_with('KEY_POWER')
|
self.device.send_key.assert_called_once_with('KEY_POWER')
|
||||||
self.device.send_key = mock.Mock()
|
self.device.send_key = mock.Mock()
|
||||||
self.device._config['method'] = 'legacy'
|
self.device._config['method'] = 'legacy'
|
||||||
|
@ -247,11 +246,11 @@ class TestSamsungTv(unittest.TestCase):
|
||||||
self.device._playing = False
|
self.device._playing = False
|
||||||
self.device.media_play_pause()
|
self.device.media_play_pause()
|
||||||
self.device.send_key.assert_called_once_with("KEY_PLAY")
|
self.device.send_key.assert_called_once_with("KEY_PLAY")
|
||||||
self.assertTrue(self.device._playing)
|
assert self.device._playing
|
||||||
self.device.send_key = mock.Mock()
|
self.device.send_key = mock.Mock()
|
||||||
self.device.media_play_pause()
|
self.device.media_play_pause()
|
||||||
self.device.send_key.assert_called_once_with("KEY_PAUSE")
|
self.device.send_key.assert_called_once_with("KEY_PAUSE")
|
||||||
self.assertFalse(self.device._playing)
|
assert not self.device._playing
|
||||||
|
|
||||||
def test_media_play(self):
|
def test_media_play(self):
|
||||||
"""Test for media_play."""
|
"""Test for media_play."""
|
||||||
|
@ -259,7 +258,7 @@ class TestSamsungTv(unittest.TestCase):
|
||||||
self.device._playing = False
|
self.device._playing = False
|
||||||
self.device.media_play()
|
self.device.media_play()
|
||||||
self.device.send_key.assert_called_once_with("KEY_PLAY")
|
self.device.send_key.assert_called_once_with("KEY_PLAY")
|
||||||
self.assertTrue(self.device._playing)
|
assert self.device._playing
|
||||||
|
|
||||||
def test_media_pause(self):
|
def test_media_pause(self):
|
||||||
"""Test for media_pause."""
|
"""Test for media_pause."""
|
||||||
|
@ -267,7 +266,7 @@ class TestSamsungTv(unittest.TestCase):
|
||||||
self.device._playing = True
|
self.device._playing = True
|
||||||
self.device.media_pause()
|
self.device.media_pause()
|
||||||
self.device.send_key.assert_called_once_with("KEY_PAUSE")
|
self.device.send_key.assert_called_once_with("KEY_PAUSE")
|
||||||
self.assertFalse(self.device._playing)
|
assert not self.device._playing
|
||||||
|
|
||||||
def test_media_next_track(self):
|
def test_media_next_track(self):
|
||||||
"""Test for media_next_track."""
|
"""Test for media_next_track."""
|
||||||
|
|
|
@ -162,8 +162,8 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
devices = list(self.hass.data[sonos.DATA_SONOS].devices)
|
devices = list(self.hass.data[sonos.DATA_SONOS].devices)
|
||||||
self.assertEqual(len(devices), 1)
|
assert len(devices) == 1
|
||||||
self.assertEqual(devices[0].name, 'Kitchen')
|
assert devices[0].name == 'Kitchen'
|
||||||
|
|
||||||
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
||||||
@mock.patch('socket.create_connection', side_effect=socket.error())
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
||||||
|
@ -181,8 +181,8 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
assert setup_component(self.hass, DOMAIN, config)
|
assert setup_component(self.hass, DOMAIN, config)
|
||||||
|
|
||||||
self.assertEqual(len(self.hass.data[sonos.DATA_SONOS].devices), 1)
|
assert len(self.hass.data[sonos.DATA_SONOS].devices) == 1
|
||||||
self.assertEqual(discover_mock.call_count, 1)
|
assert discover_mock.call_count == 1
|
||||||
|
|
||||||
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
||||||
@mock.patch('socket.create_connection', side_effect=socket.error())
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
||||||
|
@ -198,8 +198,8 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
||||||
assert setup_component(self.hass, DOMAIN, config)
|
assert setup_component(self.hass, DOMAIN, config)
|
||||||
|
|
||||||
devices = self.hass.data[sonos.DATA_SONOS].devices
|
devices = self.hass.data[sonos.DATA_SONOS].devices
|
||||||
self.assertEqual(len(devices), 1)
|
assert len(devices) == 1
|
||||||
self.assertEqual(devices[0].name, 'Kitchen')
|
assert devices[0].name == 'Kitchen'
|
||||||
|
|
||||||
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
||||||
@mock.patch('socket.create_connection', side_effect=socket.error())
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
||||||
|
@ -215,8 +215,8 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
||||||
assert setup_component(self.hass, DOMAIN, config)
|
assert setup_component(self.hass, DOMAIN, config)
|
||||||
|
|
||||||
devices = self.hass.data[sonos.DATA_SONOS].devices
|
devices = self.hass.data[sonos.DATA_SONOS].devices
|
||||||
self.assertEqual(len(devices), 2)
|
assert len(devices) == 2
|
||||||
self.assertEqual(devices[0].name, 'Kitchen')
|
assert devices[0].name == 'Kitchen'
|
||||||
|
|
||||||
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
||||||
@mock.patch('socket.create_connection', side_effect=socket.error())
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
||||||
|
@ -232,8 +232,8 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
||||||
assert setup_component(self.hass, DOMAIN, config)
|
assert setup_component(self.hass, DOMAIN, config)
|
||||||
|
|
||||||
devices = self.hass.data[sonos.DATA_SONOS].devices
|
devices = self.hass.data[sonos.DATA_SONOS].devices
|
||||||
self.assertEqual(len(devices), 2)
|
assert len(devices) == 2
|
||||||
self.assertEqual(devices[0].name, 'Kitchen')
|
assert devices[0].name == 'Kitchen'
|
||||||
|
|
||||||
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
||||||
@mock.patch.object(pysonos, 'discover', new=pysonosDiscoverMock.discover)
|
@mock.patch.object(pysonos, 'discover', new=pysonosDiscoverMock.discover)
|
||||||
|
@ -242,8 +242,8 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
||||||
"""Test a single device using the autodiscovery provided by Sonos."""
|
"""Test a single device using the autodiscovery provided by Sonos."""
|
||||||
sonos.setup_platform(self.hass, {}, add_entities_factory(self.hass))
|
sonos.setup_platform(self.hass, {}, add_entities_factory(self.hass))
|
||||||
devices = list(self.hass.data[sonos.DATA_SONOS].devices)
|
devices = list(self.hass.data[sonos.DATA_SONOS].devices)
|
||||||
self.assertEqual(len(devices), 1)
|
assert len(devices) == 1
|
||||||
self.assertEqual(devices[0].name, 'Kitchen')
|
assert devices[0].name == 'Kitchen'
|
||||||
|
|
||||||
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
||||||
@mock.patch('socket.create_connection', side_effect=socket.error())
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
||||||
|
@ -296,11 +296,11 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
||||||
device.set_alarm(alarm_id=2)
|
device.set_alarm(alarm_id=2)
|
||||||
alarm1.save.assert_not_called()
|
alarm1.save.assert_not_called()
|
||||||
device.set_alarm(alarm_id=1, **attrs)
|
device.set_alarm(alarm_id=1, **attrs)
|
||||||
self.assertEqual(alarm1.enabled, attrs['enabled'])
|
assert alarm1.enabled == attrs['enabled']
|
||||||
self.assertEqual(alarm1.start_time, attrs['time'])
|
assert alarm1.start_time == attrs['time']
|
||||||
self.assertEqual(alarm1.include_linked_zones,
|
assert alarm1.include_linked_zones == \
|
||||||
attrs['include_linked_zones'])
|
attrs['include_linked_zones']
|
||||||
self.assertEqual(alarm1.volume, 30)
|
assert alarm1.volume == 30
|
||||||
alarm1.save.assert_called_once_with()
|
alarm1.save.assert_called_once_with()
|
||||||
|
|
||||||
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
||||||
|
@ -316,8 +316,8 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
snapshotMock.return_value = True
|
snapshotMock.return_value = True
|
||||||
device.snapshot()
|
device.snapshot()
|
||||||
self.assertEqual(snapshotMock.call_count, 1)
|
assert snapshotMock.call_count == 1
|
||||||
self.assertEqual(snapshotMock.call_args, mock.call())
|
assert snapshotMock.call_args == mock.call()
|
||||||
|
|
||||||
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
||||||
@mock.patch('socket.create_connection', side_effect=socket.error())
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
||||||
|
@ -337,5 +337,5 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
||||||
device._snapshot_coordinator.soco_device = SoCoMock('192.0.2.17')
|
device._snapshot_coordinator.soco_device = SoCoMock('192.0.2.17')
|
||||||
device._soco_snapshot = Snapshot(device._player)
|
device._soco_snapshot = Snapshot(device._player)
|
||||||
device.restore()
|
device.restore()
|
||||||
self.assertEqual(restoreMock.call_count, 1)
|
assert restoreMock.call_count == 1
|
||||||
self.assertEqual(restoreMock.call_args, mock.call(False))
|
assert restoreMock.call_args == mock.call(False)
|
||||||
|
|
|
@ -164,10 +164,10 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
default_component(),
|
default_component(),
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
self.assertEqual(len(all_devices), 1)
|
assert len(all_devices) == 1
|
||||||
self.assertEqual(all_devices[0].name, 'soundtouch')
|
assert all_devices[0].name == 'soundtouch'
|
||||||
self.assertEqual(all_devices[0].config['port'], 8090)
|
assert all_devices[0].config['port'] == 8090
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.soundtouch_device', side_effect=None)
|
@mock.patch('libsoundtouch.soundtouch_device', side_effect=None)
|
||||||
def test_ensure_setup_discovery(self, mocked_soundtouch_device):
|
def test_ensure_setup_discovery(self, mocked_soundtouch_device):
|
||||||
|
@ -181,10 +181,10 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
mock.MagicMock(),
|
mock.MagicMock(),
|
||||||
new_device)
|
new_device)
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
self.assertEqual(len(all_devices), 1)
|
assert len(all_devices) == 1
|
||||||
self.assertEqual(all_devices[0].config['port'], 8090)
|
assert all_devices[0].config['port'] == 8090
|
||||||
self.assertEqual(all_devices[0].config['host'], '192.168.1.1')
|
assert all_devices[0].config['host'] == '192.168.1.1'
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.soundtouch_device', side_effect=None)
|
@mock.patch('libsoundtouch.soundtouch_device', side_effect=None)
|
||||||
def test_ensure_setup_discovery_no_duplicate(self,
|
def test_ensure_setup_discovery_no_duplicate(self,
|
||||||
|
@ -193,7 +193,7 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
soundtouch.setup_platform(self.hass,
|
soundtouch.setup_platform(self.hass,
|
||||||
default_component(),
|
default_component(),
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
self.assertEqual(len(self.hass.data[soundtouch.DATA_SOUNDTOUCH]), 1)
|
assert len(self.hass.data[soundtouch.DATA_SOUNDTOUCH]) == 1
|
||||||
new_device = {"port": "8090",
|
new_device = {"port": "8090",
|
||||||
"host": "192.168.1.1",
|
"host": "192.168.1.1",
|
||||||
"properties": {},
|
"properties": {},
|
||||||
|
@ -203,7 +203,7 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
mock.MagicMock(),
|
mock.MagicMock(),
|
||||||
new_device # New device
|
new_device # New device
|
||||||
)
|
)
|
||||||
self.assertEqual(len(self.hass.data[soundtouch.DATA_SOUNDTOUCH]), 2)
|
assert len(self.hass.data[soundtouch.DATA_SOUNDTOUCH]) == 2
|
||||||
existing_device = {"port": "8090",
|
existing_device = {"port": "8090",
|
||||||
"host": "192.168.0.1",
|
"host": "192.168.0.1",
|
||||||
"properties": {},
|
"properties": {},
|
||||||
|
@ -213,8 +213,8 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
mock.MagicMock(),
|
mock.MagicMock(),
|
||||||
existing_device # Existing device
|
existing_device # Existing device
|
||||||
)
|
)
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 2)
|
assert mocked_soundtouch_device.call_count == 2
|
||||||
self.assertEqual(len(self.hass.data[soundtouch.DATA_SOUNDTOUCH]), 2)
|
assert len(self.hass.data[soundtouch.DATA_SOUNDTOUCH]) == 2
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
|
||||||
|
@ -226,12 +226,12 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
soundtouch.setup_platform(self.hass,
|
soundtouch.setup_platform(self.hass,
|
||||||
default_component(),
|
default_component(),
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
self.hass.data[soundtouch.DATA_SOUNDTOUCH][0].update()
|
self.hass.data[soundtouch.DATA_SOUNDTOUCH][0].update()
|
||||||
self.assertEqual(mocked_status.call_count, 2)
|
assert mocked_status.call_count == 2
|
||||||
self.assertEqual(mocked_volume.call_count, 2)
|
assert mocked_volume.call_count == 2
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.status',
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.status',
|
||||||
|
@ -244,17 +244,17 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
soundtouch.setup_platform(self.hass,
|
soundtouch.setup_platform(self.hass,
|
||||||
default_component(),
|
default_component(),
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
self.assertEqual(all_devices[0].state, STATE_PLAYING)
|
assert all_devices[0].state == STATE_PLAYING
|
||||||
self.assertEqual(all_devices[0].media_image_url, "image.url")
|
assert all_devices[0].media_image_url == "image.url"
|
||||||
self.assertEqual(all_devices[0].media_title, "artist - track")
|
assert all_devices[0].media_title == "artist - track"
|
||||||
self.assertEqual(all_devices[0].media_track, "track")
|
assert all_devices[0].media_track == "track"
|
||||||
self.assertEqual(all_devices[0].media_artist, "artist")
|
assert all_devices[0].media_artist == "artist"
|
||||||
self.assertEqual(all_devices[0].media_album_name, "album")
|
assert all_devices[0].media_album_name == "album"
|
||||||
self.assertEqual(all_devices[0].media_duration, 1)
|
assert all_devices[0].media_duration == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.status',
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.status',
|
||||||
|
@ -267,11 +267,11 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
soundtouch.setup_platform(self.hass,
|
soundtouch.setup_platform(self.hass,
|
||||||
default_component(),
|
default_component(),
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
self.assertEqual(all_devices[0].media_title, None)
|
assert all_devices[0].media_title is None
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.status',
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.status',
|
||||||
|
@ -284,17 +284,17 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
soundtouch.setup_platform(self.hass,
|
soundtouch.setup_platform(self.hass,
|
||||||
default_component(),
|
default_component(),
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
self.assertEqual(all_devices[0].state, STATE_PLAYING)
|
assert all_devices[0].state == STATE_PLAYING
|
||||||
self.assertEqual(all_devices[0].media_image_url, "image.url")
|
assert all_devices[0].media_image_url == "image.url"
|
||||||
self.assertEqual(all_devices[0].media_title, "station")
|
assert all_devices[0].media_title == "station"
|
||||||
self.assertEqual(all_devices[0].media_track, None)
|
assert all_devices[0].media_track is None
|
||||||
self.assertEqual(all_devices[0].media_artist, None)
|
assert all_devices[0].media_artist is None
|
||||||
self.assertEqual(all_devices[0].media_album_name, None)
|
assert all_devices[0].media_album_name is None
|
||||||
self.assertEqual(all_devices[0].media_duration, None)
|
assert all_devices[0].media_duration is None
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume',
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume',
|
||||||
side_effect=MockVolume)
|
side_effect=MockVolume)
|
||||||
|
@ -307,11 +307,11 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
soundtouch.setup_platform(self.hass,
|
soundtouch.setup_platform(self.hass,
|
||||||
default_component(),
|
default_component(),
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
self.assertEqual(all_devices[0].volume_level, 0.12)
|
assert all_devices[0].volume_level == 0.12
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.status',
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.status',
|
||||||
|
@ -324,11 +324,11 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
soundtouch.setup_platform(self.hass,
|
soundtouch.setup_platform(self.hass,
|
||||||
default_component(),
|
default_component(),
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
self.assertEqual(all_devices[0].state, STATE_OFF)
|
assert all_devices[0].state == STATE_OFF
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.status',
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.status',
|
||||||
|
@ -341,11 +341,11 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
soundtouch.setup_platform(self.hass,
|
soundtouch.setup_platform(self.hass,
|
||||||
default_component(),
|
default_component(),
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
self.assertEqual(all_devices[0].state, STATE_PAUSED)
|
assert all_devices[0].state == STATE_PAUSED
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume',
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume',
|
||||||
side_effect=MockVolumeMuted)
|
side_effect=MockVolumeMuted)
|
||||||
|
@ -358,11 +358,11 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
soundtouch.setup_platform(self.hass,
|
soundtouch.setup_platform(self.hass,
|
||||||
default_component(),
|
default_component(),
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
self.assertEqual(all_devices[0].is_volume_muted, True)
|
assert all_devices[0].is_volume_muted is True
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.soundtouch_device')
|
@mock.patch('libsoundtouch.soundtouch_device')
|
||||||
def test_media_commands(self, mocked_soundtouch_device):
|
def test_media_commands(self, mocked_soundtouch_device):
|
||||||
|
@ -370,9 +370,9 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
soundtouch.setup_platform(self.hass,
|
soundtouch.setup_platform(self.hass,
|
||||||
default_component(),
|
default_component(),
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
self.assertEqual(all_devices[0].supported_features, 17853)
|
assert all_devices[0].supported_features == 17853
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.power_off')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.power_off')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
|
@ -387,10 +387,10 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
all_devices[0].turn_off()
|
all_devices[0].turn_off()
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 2)
|
assert mocked_status.call_count == 2
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
self.assertEqual(mocked_power_off.call_count, 1)
|
assert mocked_power_off.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.power_on')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.power_on')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
|
@ -405,10 +405,10 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
all_devices[0].turn_on()
|
all_devices[0].turn_on()
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 2)
|
assert mocked_status.call_count == 2
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
self.assertEqual(mocked_power_on.call_count, 1)
|
assert mocked_power_on.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume_up')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume_up')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
|
@ -423,10 +423,10 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
all_devices[0].volume_up()
|
all_devices[0].volume_up()
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 2)
|
assert mocked_volume.call_count == 2
|
||||||
self.assertEqual(mocked_volume_up.call_count, 1)
|
assert mocked_volume_up.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume_down')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume_down')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
|
@ -441,10 +441,10 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
all_devices[0].volume_down()
|
all_devices[0].volume_down()
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 2)
|
assert mocked_volume.call_count == 2
|
||||||
self.assertEqual(mocked_volume_down.call_count, 1)
|
assert mocked_volume_down.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.set_volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.set_volume')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
|
@ -459,9 +459,9 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
all_devices[0].set_volume_level(0.17)
|
all_devices[0].set_volume_level(0.17)
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 2)
|
assert mocked_volume.call_count == 2
|
||||||
mocked_set_volume.assert_called_with(17)
|
mocked_set_volume.assert_called_with(17)
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.mute')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.mute')
|
||||||
|
@ -477,10 +477,10 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
all_devices[0].mute_volume(None)
|
all_devices[0].mute_volume(None)
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 2)
|
assert mocked_volume.call_count == 2
|
||||||
self.assertEqual(mocked_mute.call_count, 1)
|
assert mocked_mute.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.play')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.play')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
|
@ -495,10 +495,10 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
all_devices[0].media_play()
|
all_devices[0].media_play()
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 2)
|
assert mocked_status.call_count == 2
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
self.assertEqual(mocked_play.call_count, 1)
|
assert mocked_play.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.pause')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.pause')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
|
@ -513,10 +513,10 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
all_devices[0].media_pause()
|
all_devices[0].media_pause()
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 2)
|
assert mocked_status.call_count == 2
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
self.assertEqual(mocked_pause.call_count, 1)
|
assert mocked_pause.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.play_pause')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.play_pause')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
|
@ -531,10 +531,10 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
all_devices[0].media_play_pause()
|
all_devices[0].media_play_pause()
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 2)
|
assert mocked_status.call_count == 2
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
self.assertEqual(mocked_play_pause.call_count, 1)
|
assert mocked_play_pause.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.previous_track')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.previous_track')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.next_track')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.next_track')
|
||||||
|
@ -550,15 +550,15 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
default_component(),
|
default_component(),
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
all_devices[0].media_next_track()
|
all_devices[0].media_next_track()
|
||||||
self.assertEqual(mocked_status.call_count, 2)
|
assert mocked_status.call_count == 2
|
||||||
self.assertEqual(mocked_next_track.call_count, 1)
|
assert mocked_next_track.call_count == 1
|
||||||
all_devices[0].media_previous_track()
|
all_devices[0].media_previous_track()
|
||||||
self.assertEqual(mocked_status.call_count, 3)
|
assert mocked_status.call_count == 3
|
||||||
self.assertEqual(mocked_previous_track.call_count, 1)
|
assert mocked_previous_track.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.select_preset')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.select_preset')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.presets',
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.presets',
|
||||||
|
@ -574,15 +574,15 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
default_component(),
|
default_component(),
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
all_devices[0].play_media('PLAYLIST', 1)
|
all_devices[0].play_media('PLAYLIST', 1)
|
||||||
self.assertEqual(mocked_presets.call_count, 1)
|
assert mocked_presets.call_count == 1
|
||||||
self.assertEqual(mocked_select_preset.call_count, 1)
|
assert mocked_select_preset.call_count == 1
|
||||||
all_devices[0].play_media('PLAYLIST', 2)
|
all_devices[0].play_media('PLAYLIST', 2)
|
||||||
self.assertEqual(mocked_presets.call_count, 2)
|
assert mocked_presets.call_count == 2
|
||||||
self.assertEqual(mocked_select_preset.call_count, 1)
|
assert mocked_select_preset.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.play_url')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.play_url')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
|
@ -596,9 +596,9 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
default_component(),
|
default_component(),
|
||||||
mock.MagicMock())
|
mock.MagicMock())
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 1)
|
assert mocked_soundtouch_device.call_count == 1
|
||||||
self.assertEqual(mocked_status.call_count, 1)
|
assert mocked_status.call_count == 1
|
||||||
self.assertEqual(mocked_volume.call_count, 1)
|
assert mocked_volume.call_count == 1
|
||||||
all_devices[0].play_media('MUSIC', "http://fqdn/file.mp3")
|
all_devices[0].play_media('MUSIC', "http://fqdn/file.mp3")
|
||||||
mocked_play_url.assert_called_with("http://fqdn/file.mp3")
|
mocked_play_url.assert_called_with("http://fqdn/file.mp3")
|
||||||
|
|
||||||
|
@ -619,28 +619,28 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
all_devices[0].entity_id = "media_player.entity_1"
|
all_devices[0].entity_id = "media_player.entity_1"
|
||||||
all_devices[1].entity_id = "media_player.entity_2"
|
all_devices[1].entity_id = "media_player.entity_2"
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 2)
|
assert mocked_soundtouch_device.call_count == 2
|
||||||
self.assertEqual(mocked_status.call_count, 2)
|
assert mocked_status.call_count == 2
|
||||||
self.assertEqual(mocked_volume.call_count, 2)
|
assert mocked_volume.call_count == 2
|
||||||
|
|
||||||
# one master, one slave => create zone
|
# one master, one slave => create zone
|
||||||
self.hass.services.call(soundtouch.DOMAIN,
|
self.hass.services.call(soundtouch.DOMAIN,
|
||||||
soundtouch.SERVICE_PLAY_EVERYWHERE,
|
soundtouch.SERVICE_PLAY_EVERYWHERE,
|
||||||
{"master": "media_player.entity_1"}, True)
|
{"master": "media_player.entity_1"}, True)
|
||||||
self.assertEqual(mocked_create_zone.call_count, 1)
|
assert mocked_create_zone.call_count == 1
|
||||||
|
|
||||||
# unknown master. create zone is must not be called
|
# unknown master. create zone is must not be called
|
||||||
self.hass.services.call(soundtouch.DOMAIN,
|
self.hass.services.call(soundtouch.DOMAIN,
|
||||||
soundtouch.SERVICE_PLAY_EVERYWHERE,
|
soundtouch.SERVICE_PLAY_EVERYWHERE,
|
||||||
{"master": "media_player.entity_X"}, True)
|
{"master": "media_player.entity_X"}, True)
|
||||||
self.assertEqual(mocked_create_zone.call_count, 1)
|
assert mocked_create_zone.call_count == 1
|
||||||
|
|
||||||
# no slaves, create zone must not be called
|
# no slaves, create zone must not be called
|
||||||
all_devices.pop(1)
|
all_devices.pop(1)
|
||||||
self.hass.services.call(soundtouch.DOMAIN,
|
self.hass.services.call(soundtouch.DOMAIN,
|
||||||
soundtouch.SERVICE_PLAY_EVERYWHERE,
|
soundtouch.SERVICE_PLAY_EVERYWHERE,
|
||||||
{"master": "media_player.entity_1"}, True)
|
{"master": "media_player.entity_1"}, True)
|
||||||
self.assertEqual(mocked_create_zone.call_count, 1)
|
assert mocked_create_zone.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.create_zone')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.create_zone')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
|
@ -659,30 +659,30 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
all_devices[0].entity_id = "media_player.entity_1"
|
all_devices[0].entity_id = "media_player.entity_1"
|
||||||
all_devices[1].entity_id = "media_player.entity_2"
|
all_devices[1].entity_id = "media_player.entity_2"
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 2)
|
assert mocked_soundtouch_device.call_count == 2
|
||||||
self.assertEqual(mocked_status.call_count, 2)
|
assert mocked_status.call_count == 2
|
||||||
self.assertEqual(mocked_volume.call_count, 2)
|
assert mocked_volume.call_count == 2
|
||||||
|
|
||||||
# one master, one slave => create zone
|
# one master, one slave => create zone
|
||||||
self.hass.services.call(soundtouch.DOMAIN,
|
self.hass.services.call(soundtouch.DOMAIN,
|
||||||
soundtouch.SERVICE_CREATE_ZONE,
|
soundtouch.SERVICE_CREATE_ZONE,
|
||||||
{"master": "media_player.entity_1",
|
{"master": "media_player.entity_1",
|
||||||
"slaves": ["media_player.entity_2"]}, True)
|
"slaves": ["media_player.entity_2"]}, True)
|
||||||
self.assertEqual(mocked_create_zone.call_count, 1)
|
assert mocked_create_zone.call_count == 1
|
||||||
|
|
||||||
# unknown master. create zone is must not be called
|
# unknown master. create zone is must not be called
|
||||||
self.hass.services.call(soundtouch.DOMAIN,
|
self.hass.services.call(soundtouch.DOMAIN,
|
||||||
soundtouch.SERVICE_CREATE_ZONE,
|
soundtouch.SERVICE_CREATE_ZONE,
|
||||||
{"master": "media_player.entity_X",
|
{"master": "media_player.entity_X",
|
||||||
"slaves": ["media_player.entity_2"]}, True)
|
"slaves": ["media_player.entity_2"]}, True)
|
||||||
self.assertEqual(mocked_create_zone.call_count, 1)
|
assert mocked_create_zone.call_count == 1
|
||||||
|
|
||||||
# no slaves, create zone must not be called
|
# no slaves, create zone must not be called
|
||||||
self.hass.services.call(soundtouch.DOMAIN,
|
self.hass.services.call(soundtouch.DOMAIN,
|
||||||
soundtouch.SERVICE_CREATE_ZONE,
|
soundtouch.SERVICE_CREATE_ZONE,
|
||||||
{"master": "media_player.entity_X",
|
{"master": "media_player.entity_X",
|
||||||
"slaves": []}, True)
|
"slaves": []}, True)
|
||||||
self.assertEqual(mocked_create_zone.call_count, 1)
|
assert mocked_create_zone.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.remove_zone_slave')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.remove_zone_slave')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
|
@ -701,30 +701,30 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
all_devices[0].entity_id = "media_player.entity_1"
|
all_devices[0].entity_id = "media_player.entity_1"
|
||||||
all_devices[1].entity_id = "media_player.entity_2"
|
all_devices[1].entity_id = "media_player.entity_2"
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 2)
|
assert mocked_soundtouch_device.call_count == 2
|
||||||
self.assertEqual(mocked_status.call_count, 2)
|
assert mocked_status.call_count == 2
|
||||||
self.assertEqual(mocked_volume.call_count, 2)
|
assert mocked_volume.call_count == 2
|
||||||
|
|
||||||
# remove one slave
|
# remove one slave
|
||||||
self.hass.services.call(soundtouch.DOMAIN,
|
self.hass.services.call(soundtouch.DOMAIN,
|
||||||
soundtouch.SERVICE_REMOVE_ZONE_SLAVE,
|
soundtouch.SERVICE_REMOVE_ZONE_SLAVE,
|
||||||
{"master": "media_player.entity_1",
|
{"master": "media_player.entity_1",
|
||||||
"slaves": ["media_player.entity_2"]}, True)
|
"slaves": ["media_player.entity_2"]}, True)
|
||||||
self.assertEqual(mocked_remove_zone_slave.call_count, 1)
|
assert mocked_remove_zone_slave.call_count == 1
|
||||||
|
|
||||||
# unknown master. add zone slave is not called
|
# unknown master. add zone slave is not called
|
||||||
self.hass.services.call(soundtouch.DOMAIN,
|
self.hass.services.call(soundtouch.DOMAIN,
|
||||||
soundtouch.SERVICE_REMOVE_ZONE_SLAVE,
|
soundtouch.SERVICE_REMOVE_ZONE_SLAVE,
|
||||||
{"master": "media_player.entity_X",
|
{"master": "media_player.entity_X",
|
||||||
"slaves": ["media_player.entity_2"]}, True)
|
"slaves": ["media_player.entity_2"]}, True)
|
||||||
self.assertEqual(mocked_remove_zone_slave.call_count, 1)
|
assert mocked_remove_zone_slave.call_count == 1
|
||||||
|
|
||||||
# no slave to add, add zone slave is not called
|
# no slave to add, add zone slave is not called
|
||||||
self.hass.services.call(soundtouch.DOMAIN,
|
self.hass.services.call(soundtouch.DOMAIN,
|
||||||
soundtouch.SERVICE_REMOVE_ZONE_SLAVE,
|
soundtouch.SERVICE_REMOVE_ZONE_SLAVE,
|
||||||
{"master": "media_player.entity_1",
|
{"master": "media_player.entity_1",
|
||||||
"slaves": []}, True)
|
"slaves": []}, True)
|
||||||
self.assertEqual(mocked_remove_zone_slave.call_count, 1)
|
assert mocked_remove_zone_slave.call_count == 1
|
||||||
|
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.add_zone_slave')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.add_zone_slave')
|
||||||
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
|
||||||
|
@ -743,27 +743,27 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
|
||||||
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
|
||||||
all_devices[0].entity_id = "media_player.entity_1"
|
all_devices[0].entity_id = "media_player.entity_1"
|
||||||
all_devices[1].entity_id = "media_player.entity_2"
|
all_devices[1].entity_id = "media_player.entity_2"
|
||||||
self.assertEqual(mocked_soundtouch_device.call_count, 2)
|
assert mocked_soundtouch_device.call_count == 2
|
||||||
self.assertEqual(mocked_status.call_count, 2)
|
assert mocked_status.call_count == 2
|
||||||
self.assertEqual(mocked_volume.call_count, 2)
|
assert mocked_volume.call_count == 2
|
||||||
|
|
||||||
# add one slave
|
# add one slave
|
||||||
self.hass.services.call(soundtouch.DOMAIN,
|
self.hass.services.call(soundtouch.DOMAIN,
|
||||||
soundtouch.SERVICE_ADD_ZONE_SLAVE,
|
soundtouch.SERVICE_ADD_ZONE_SLAVE,
|
||||||
{"master": "media_player.entity_1",
|
{"master": "media_player.entity_1",
|
||||||
"slaves": ["media_player.entity_2"]}, True)
|
"slaves": ["media_player.entity_2"]}, True)
|
||||||
self.assertEqual(mocked_add_zone_slave.call_count, 1)
|
assert mocked_add_zone_slave.call_count == 1
|
||||||
|
|
||||||
# unknown master. add zone slave is not called
|
# unknown master. add zone slave is not called
|
||||||
self.hass.services.call(soundtouch.DOMAIN,
|
self.hass.services.call(soundtouch.DOMAIN,
|
||||||
soundtouch.SERVICE_ADD_ZONE_SLAVE,
|
soundtouch.SERVICE_ADD_ZONE_SLAVE,
|
||||||
{"master": "media_player.entity_X",
|
{"master": "media_player.entity_X",
|
||||||
"slaves": ["media_player.entity_2"]}, True)
|
"slaves": ["media_player.entity_2"]}, True)
|
||||||
self.assertEqual(mocked_add_zone_slave.call_count, 1)
|
assert mocked_add_zone_slave.call_count == 1
|
||||||
|
|
||||||
# no slave to add, add zone slave is not called
|
# no slave to add, add zone slave is not called
|
||||||
self.hass.services.call(soundtouch.DOMAIN,
|
self.hass.services.call(soundtouch.DOMAIN,
|
||||||
soundtouch.SERVICE_ADD_ZONE_SLAVE,
|
soundtouch.SERVICE_ADD_ZONE_SLAVE,
|
||||||
{"master": "media_player.entity_1",
|
{"master": "media_player.entity_1",
|
||||||
"slaves": ["media_player.entity_X"]}, True)
|
"slaves": ["media_player.entity_X"]}, True)
|
||||||
self.assertEqual(mocked_add_zone_slave.call_count, 1)
|
assert mocked_add_zone_slave.call_count == 1
|
||||||
|
|
|
@ -220,7 +220,7 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
config_start['attributes'] = {}
|
config_start['attributes'] = {}
|
||||||
|
|
||||||
config = validate_config(self.config_children_only)
|
config = validate_config(self.config_children_only)
|
||||||
self.assertEqual(config_start, config)
|
assert config_start == config
|
||||||
|
|
||||||
def test_config_children_and_attr(self):
|
def test_config_children_and_attr(self):
|
||||||
"""Check config with children and attributes."""
|
"""Check config with children and attributes."""
|
||||||
|
@ -229,7 +229,7 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
config_start['commands'] = {}
|
config_start['commands'] = {}
|
||||||
|
|
||||||
config = validate_config(self.config_children_and_attr)
|
config = validate_config(self.config_children_and_attr)
|
||||||
self.assertEqual(config_start, config)
|
assert config_start == config
|
||||||
|
|
||||||
def test_config_no_name(self):
|
def test_config_no_name(self):
|
||||||
"""Check config with no Name entry."""
|
"""Check config with no Name entry."""
|
||||||
|
@ -238,7 +238,7 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
validate_config({'platform': 'universal'})
|
validate_config({'platform': 'universal'})
|
||||||
except MultipleInvalid:
|
except MultipleInvalid:
|
||||||
response = False
|
response = False
|
||||||
self.assertFalse(response)
|
assert not response
|
||||||
|
|
||||||
def test_config_bad_children(self):
|
def test_config_bad_children(self):
|
||||||
"""Check config with bad children entry."""
|
"""Check config with bad children entry."""
|
||||||
|
@ -247,31 +247,31 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
'platform': 'universal'}
|
'platform': 'universal'}
|
||||||
|
|
||||||
config_no_children = validate_config(config_no_children)
|
config_no_children = validate_config(config_no_children)
|
||||||
self.assertEqual([], config_no_children['children'])
|
assert [] == config_no_children['children']
|
||||||
|
|
||||||
config_bad_children = validate_config(config_bad_children)
|
config_bad_children = validate_config(config_bad_children)
|
||||||
self.assertEqual([], config_bad_children['children'])
|
assert [] == config_bad_children['children']
|
||||||
|
|
||||||
def test_config_bad_commands(self):
|
def test_config_bad_commands(self):
|
||||||
"""Check config with bad commands entry."""
|
"""Check config with bad commands entry."""
|
||||||
config = {'name': 'test', 'platform': 'universal'}
|
config = {'name': 'test', 'platform': 'universal'}
|
||||||
|
|
||||||
config = validate_config(config)
|
config = validate_config(config)
|
||||||
self.assertEqual({}, config['commands'])
|
assert {} == config['commands']
|
||||||
|
|
||||||
def test_config_bad_attributes(self):
|
def test_config_bad_attributes(self):
|
||||||
"""Check config with bad attributes."""
|
"""Check config with bad attributes."""
|
||||||
config = {'name': 'test', 'platform': 'universal'}
|
config = {'name': 'test', 'platform': 'universal'}
|
||||||
|
|
||||||
config = validate_config(config)
|
config = validate_config(config)
|
||||||
self.assertEqual({}, config['attributes'])
|
assert {} == config['attributes']
|
||||||
|
|
||||||
def test_config_bad_key(self):
|
def test_config_bad_key(self):
|
||||||
"""Check config with bad key."""
|
"""Check config with bad key."""
|
||||||
config = {'name': 'test', 'asdf': 5, 'platform': 'universal'}
|
config = {'name': 'test', 'asdf': 5, 'platform': 'universal'}
|
||||||
|
|
||||||
config = validate_config(config)
|
config = validate_config(config)
|
||||||
self.assertFalse('asdf' in config)
|
assert not ('asdf' in config)
|
||||||
|
|
||||||
def test_platform_setup(self):
|
def test_platform_setup(self):
|
||||||
"""Test platform setup."""
|
"""Test platform setup."""
|
||||||
|
@ -292,15 +292,15 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
except MultipleInvalid:
|
except MultipleInvalid:
|
||||||
setup_ok = False
|
setup_ok = False
|
||||||
self.assertFalse(setup_ok)
|
assert not setup_ok
|
||||||
self.assertEqual(0, len(entities))
|
assert 0 == len(entities)
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
universal.async_setup_platform(
|
universal.async_setup_platform(
|
||||||
self.hass, validate_config(config), add_entities),
|
self.hass, validate_config(config), add_entities),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(1, len(entities))
|
assert 1 == len(entities)
|
||||||
self.assertEqual('test', entities[0].name)
|
assert 'test' == entities[0].name
|
||||||
|
|
||||||
def test_master_state(self):
|
def test_master_state(self):
|
||||||
"""Test master state property."""
|
"""Test master state property."""
|
||||||
|
@ -308,7 +308,7 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
||||||
|
|
||||||
self.assertEqual(None, ump.master_state)
|
assert ump.master_state is None
|
||||||
|
|
||||||
def test_master_state_with_attrs(self):
|
def test_master_state_with_attrs(self):
|
||||||
"""Test master state property."""
|
"""Test master state property."""
|
||||||
|
@ -316,9 +316,9 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
||||||
|
|
||||||
self.assertEqual(STATE_OFF, ump.master_state)
|
assert STATE_OFF == ump.master_state
|
||||||
self.hass.states.set(self.mock_state_switch_id, STATE_ON)
|
self.hass.states.set(self.mock_state_switch_id, STATE_ON)
|
||||||
self.assertEqual(STATE_ON, ump.master_state)
|
assert STATE_ON == ump.master_state
|
||||||
|
|
||||||
def test_master_state_with_template(self):
|
def test_master_state_with_template(self):
|
||||||
"""Test the state_template option."""
|
"""Test the state_template option."""
|
||||||
|
@ -331,9 +331,9 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
||||||
|
|
||||||
self.assertEqual(STATE_ON, ump.master_state)
|
assert STATE_ON == ump.master_state
|
||||||
self.hass.states.set('input_boolean.test', STATE_ON)
|
self.hass.states.set('input_boolean.test', STATE_ON)
|
||||||
self.assertEqual(STATE_OFF, ump.master_state)
|
assert STATE_OFF == ump.master_state
|
||||||
|
|
||||||
def test_master_state_with_bad_attrs(self):
|
def test_master_state_with_bad_attrs(self):
|
||||||
"""Test master state property."""
|
"""Test master state property."""
|
||||||
|
@ -343,7 +343,7 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
||||||
|
|
||||||
self.assertEqual(STATE_OFF, ump.master_state)
|
assert STATE_OFF == ump.master_state
|
||||||
|
|
||||||
def test_active_child_state(self):
|
def test_active_child_state(self):
|
||||||
"""Test active child state property."""
|
"""Test active child state property."""
|
||||||
|
@ -353,28 +353,28 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
|
|
||||||
self.assertEqual(None, ump._child_state)
|
assert ump._child_state is None
|
||||||
|
|
||||||
self.mock_mp_1._state = STATE_PLAYING
|
self.mock_mp_1._state = STATE_PLAYING
|
||||||
self.mock_mp_1.schedule_update_ha_state()
|
self.mock_mp_1.schedule_update_ha_state()
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
self.assertEqual(self.mock_mp_1.entity_id,
|
assert self.mock_mp_1.entity_id == \
|
||||||
ump._child_state.entity_id)
|
ump._child_state.entity_id
|
||||||
|
|
||||||
self.mock_mp_2._state = STATE_PLAYING
|
self.mock_mp_2._state = STATE_PLAYING
|
||||||
self.mock_mp_2.schedule_update_ha_state()
|
self.mock_mp_2.schedule_update_ha_state()
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
self.assertEqual(self.mock_mp_1.entity_id,
|
assert self.mock_mp_1.entity_id == \
|
||||||
ump._child_state.entity_id)
|
ump._child_state.entity_id
|
||||||
|
|
||||||
self.mock_mp_1._state = STATE_OFF
|
self.mock_mp_1._state = STATE_OFF
|
||||||
self.mock_mp_1.schedule_update_ha_state()
|
self.mock_mp_1.schedule_update_ha_state()
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
self.assertEqual(self.mock_mp_2.entity_id,
|
assert self.mock_mp_2.entity_id == \
|
||||||
ump._child_state.entity_id)
|
ump._child_state.entity_id
|
||||||
|
|
||||||
def test_name(self):
|
def test_name(self):
|
||||||
"""Test name property."""
|
"""Test name property."""
|
||||||
|
@ -382,7 +382,7 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
||||||
|
|
||||||
self.assertEqual(config['name'], ump.name)
|
assert config['name'] == ump.name
|
||||||
|
|
||||||
def test_polling(self):
|
def test_polling(self):
|
||||||
"""Test should_poll property."""
|
"""Test should_poll property."""
|
||||||
|
@ -390,7 +390,7 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
||||||
|
|
||||||
self.assertEqual(False, ump.should_poll)
|
assert ump.should_poll is False
|
||||||
|
|
||||||
def test_state_children_only(self):
|
def test_state_children_only(self):
|
||||||
"""Test media player state with only children."""
|
"""Test media player state with only children."""
|
||||||
|
@ -400,13 +400,13 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
|
|
||||||
self.assertTrue(ump.state, STATE_OFF)
|
assert ump.state, STATE_OFF
|
||||||
|
|
||||||
self.mock_mp_1._state = STATE_PLAYING
|
self.mock_mp_1._state = STATE_PLAYING
|
||||||
self.mock_mp_1.schedule_update_ha_state()
|
self.mock_mp_1.schedule_update_ha_state()
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
self.assertEqual(STATE_PLAYING, ump.state)
|
assert STATE_PLAYING == ump.state
|
||||||
|
|
||||||
def test_state_with_children_and_attrs(self):
|
def test_state_with_children_and_attrs(self):
|
||||||
"""Test media player with children and master state."""
|
"""Test media player with children and master state."""
|
||||||
|
@ -416,21 +416,21 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
|
|
||||||
self.assertEqual(STATE_OFF, ump.state)
|
assert STATE_OFF == ump.state
|
||||||
|
|
||||||
self.hass.states.set(self.mock_state_switch_id, STATE_ON)
|
self.hass.states.set(self.mock_state_switch_id, STATE_ON)
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
self.assertEqual(STATE_ON, ump.state)
|
assert STATE_ON == ump.state
|
||||||
|
|
||||||
self.mock_mp_1._state = STATE_PLAYING
|
self.mock_mp_1._state = STATE_PLAYING
|
||||||
self.mock_mp_1.schedule_update_ha_state()
|
self.mock_mp_1.schedule_update_ha_state()
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
self.assertEqual(STATE_PLAYING, ump.state)
|
assert STATE_PLAYING == ump.state
|
||||||
|
|
||||||
self.hass.states.set(self.mock_state_switch_id, STATE_OFF)
|
self.hass.states.set(self.mock_state_switch_id, STATE_OFF)
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
self.assertEqual(STATE_OFF, ump.state)
|
assert STATE_OFF == ump.state
|
||||||
|
|
||||||
def test_volume_level(self):
|
def test_volume_level(self):
|
||||||
"""Test volume level property."""
|
"""Test volume level property."""
|
||||||
|
@ -440,19 +440,19 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
|
|
||||||
self.assertEqual(None, ump.volume_level)
|
assert ump.volume_level is None
|
||||||
|
|
||||||
self.mock_mp_1._state = STATE_PLAYING
|
self.mock_mp_1._state = STATE_PLAYING
|
||||||
self.mock_mp_1.schedule_update_ha_state()
|
self.mock_mp_1.schedule_update_ha_state()
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
self.assertEqual(0, ump.volume_level)
|
assert 0 == ump.volume_level
|
||||||
|
|
||||||
self.mock_mp_1._volume_level = 1
|
self.mock_mp_1._volume_level = 1
|
||||||
self.mock_mp_1.schedule_update_ha_state()
|
self.mock_mp_1.schedule_update_ha_state()
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
self.assertEqual(1, ump.volume_level)
|
assert 1 == ump.volume_level
|
||||||
|
|
||||||
def test_media_image_url(self):
|
def test_media_image_url(self):
|
||||||
"""Test media_image_url property."""
|
"""Test media_image_url property."""
|
||||||
|
@ -463,7 +463,7 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
|
|
||||||
self.assertEqual(None, ump.media_image_url)
|
assert ump.media_image_url is None
|
||||||
|
|
||||||
self.mock_mp_1._state = STATE_PLAYING
|
self.mock_mp_1._state = STATE_PLAYING
|
||||||
self.mock_mp_1._media_image_url = test_url
|
self.mock_mp_1._media_image_url = test_url
|
||||||
|
@ -472,7 +472,7 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
# mock_mp_1 will convert the url to the api proxy url. This test
|
# mock_mp_1 will convert the url to the api proxy url. This test
|
||||||
# ensures ump passes through the same url without an additional proxy.
|
# ensures ump passes through the same url without an additional proxy.
|
||||||
self.assertEqual(self.mock_mp_1.entity_picture, ump.entity_picture)
|
assert self.mock_mp_1.entity_picture == ump.entity_picture
|
||||||
|
|
||||||
def test_is_volume_muted_children_only(self):
|
def test_is_volume_muted_children_only(self):
|
||||||
"""Test is volume muted property w/ children only."""
|
"""Test is volume muted property w/ children only."""
|
||||||
|
@ -482,19 +482,19 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
|
|
||||||
self.assertFalse(ump.is_volume_muted)
|
assert not ump.is_volume_muted
|
||||||
|
|
||||||
self.mock_mp_1._state = STATE_PLAYING
|
self.mock_mp_1._state = STATE_PLAYING
|
||||||
self.mock_mp_1.schedule_update_ha_state()
|
self.mock_mp_1.schedule_update_ha_state()
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
self.assertFalse(ump.is_volume_muted)
|
assert not ump.is_volume_muted
|
||||||
|
|
||||||
self.mock_mp_1._is_volume_muted = True
|
self.mock_mp_1._is_volume_muted = True
|
||||||
self.mock_mp_1.schedule_update_ha_state()
|
self.mock_mp_1.schedule_update_ha_state()
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
self.assertTrue(ump.is_volume_muted)
|
assert ump.is_volume_muted
|
||||||
|
|
||||||
def test_source_list_children_and_attr(self):
|
def test_source_list_children_and_attr(self):
|
||||||
"""Test source list property w/ children and attrs."""
|
"""Test source list property w/ children and attrs."""
|
||||||
|
@ -502,10 +502,10 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
||||||
|
|
||||||
self.assertEqual("['dvd', 'htpc']", ump.source_list)
|
assert "['dvd', 'htpc']" == ump.source_list
|
||||||
|
|
||||||
self.hass.states.set(self.mock_source_list_id, ['dvd', 'htpc', 'game'])
|
self.hass.states.set(self.mock_source_list_id, ['dvd', 'htpc', 'game'])
|
||||||
self.assertEqual("['dvd', 'htpc', 'game']", ump.source_list)
|
assert "['dvd', 'htpc', 'game']" == ump.source_list
|
||||||
|
|
||||||
def test_source_children_and_attr(self):
|
def test_source_children_and_attr(self):
|
||||||
"""Test source property w/ children and attrs."""
|
"""Test source property w/ children and attrs."""
|
||||||
|
@ -513,10 +513,10 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
||||||
|
|
||||||
self.assertEqual('dvd', ump.source)
|
assert 'dvd' == ump.source
|
||||||
|
|
||||||
self.hass.states.set(self.mock_source_id, 'htpc')
|
self.hass.states.set(self.mock_source_id, 'htpc')
|
||||||
self.assertEqual('htpc', ump.source)
|
assert 'htpc' == ump.source
|
||||||
|
|
||||||
def test_volume_level_children_and_attr(self):
|
def test_volume_level_children_and_attr(self):
|
||||||
"""Test volume level property w/ children and attrs."""
|
"""Test volume level property w/ children and attrs."""
|
||||||
|
@ -524,10 +524,10 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
||||||
|
|
||||||
self.assertEqual('0', ump.volume_level)
|
assert '0' == ump.volume_level
|
||||||
|
|
||||||
self.hass.states.set(self.mock_volume_id, 100)
|
self.hass.states.set(self.mock_volume_id, 100)
|
||||||
self.assertEqual('100', ump.volume_level)
|
assert '100' == ump.volume_level
|
||||||
|
|
||||||
def test_is_volume_muted_children_and_attr(self):
|
def test_is_volume_muted_children_and_attr(self):
|
||||||
"""Test is volume muted property w/ children and attrs."""
|
"""Test is volume muted property w/ children and attrs."""
|
||||||
|
@ -535,10 +535,10 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
|
|
||||||
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
||||||
|
|
||||||
self.assertFalse(ump.is_volume_muted)
|
assert not ump.is_volume_muted
|
||||||
|
|
||||||
self.hass.states.set(self.mock_mute_switch_id, STATE_ON)
|
self.hass.states.set(self.mock_mute_switch_id, STATE_ON)
|
||||||
self.assertTrue(ump.is_volume_muted)
|
assert ump.is_volume_muted
|
||||||
|
|
||||||
def test_supported_features_children_only(self):
|
def test_supported_features_children_only(self):
|
||||||
"""Test supported media commands with only children."""
|
"""Test supported media commands with only children."""
|
||||||
|
@ -548,14 +548,14 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
|
|
||||||
self.assertEqual(0, ump.supported_features)
|
assert 0 == ump.supported_features
|
||||||
|
|
||||||
self.mock_mp_1._supported_features = 512
|
self.mock_mp_1._supported_features = 512
|
||||||
self.mock_mp_1._state = STATE_PLAYING
|
self.mock_mp_1._state = STATE_PLAYING
|
||||||
self.mock_mp_1.schedule_update_ha_state()
|
self.mock_mp_1.schedule_update_ha_state()
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
self.assertEqual(512, ump.supported_features)
|
assert 512 == ump.supported_features
|
||||||
|
|
||||||
def test_supported_features_children_and_cmds(self):
|
def test_supported_features_children_and_cmds(self):
|
||||||
"""Test supported media commands with children and attrs."""
|
"""Test supported media commands with children and attrs."""
|
||||||
|
@ -586,7 +586,7 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
| universal.SUPPORT_VOLUME_STEP | universal.SUPPORT_VOLUME_MUTE \
|
| universal.SUPPORT_VOLUME_STEP | universal.SUPPORT_VOLUME_MUTE \
|
||||||
| universal.SUPPORT_SELECT_SOURCE | universal.SUPPORT_SHUFFLE_SET
|
| universal.SUPPORT_SELECT_SOURCE | universal.SUPPORT_SHUFFLE_SET
|
||||||
|
|
||||||
self.assertEqual(check_flags, ump.supported_features)
|
assert check_flags == ump.supported_features
|
||||||
|
|
||||||
def test_service_call_no_active_child(self):
|
def test_service_call_no_active_child(self):
|
||||||
"""Test a service call to children with no active child."""
|
"""Test a service call to children with no active child."""
|
||||||
|
@ -606,8 +606,8 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_turn_off(),
|
ump.async_turn_off(),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(0, len(self.mock_mp_1.service_calls['turn_off']))
|
assert 0 == len(self.mock_mp_1.service_calls['turn_off'])
|
||||||
self.assertEqual(0, len(self.mock_mp_2.service_calls['turn_off']))
|
assert 0 == len(self.mock_mp_2.service_calls['turn_off'])
|
||||||
|
|
||||||
def test_service_call_to_child(self):
|
def test_service_call_to_child(self):
|
||||||
"""Test service calls that should be routed to a child."""
|
"""Test service calls that should be routed to a child."""
|
||||||
|
@ -625,88 +625,82 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_turn_off(),
|
ump.async_turn_off(),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(1, len(self.mock_mp_2.service_calls['turn_off']))
|
assert 1 == len(self.mock_mp_2.service_calls['turn_off'])
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_turn_on(),
|
ump.async_turn_on(),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(1, len(self.mock_mp_2.service_calls['turn_on']))
|
assert 1 == len(self.mock_mp_2.service_calls['turn_on'])
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_mute_volume(True),
|
ump.async_mute_volume(True),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(1, len(self.mock_mp_2.service_calls['mute_volume']))
|
assert 1 == len(self.mock_mp_2.service_calls['mute_volume'])
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_set_volume_level(0.5),
|
ump.async_set_volume_level(0.5),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(
|
assert 1 == len(self.mock_mp_2.service_calls['set_volume_level'])
|
||||||
1, len(self.mock_mp_2.service_calls['set_volume_level']))
|
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_media_play(),
|
ump.async_media_play(),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(1, len(self.mock_mp_2.service_calls['media_play']))
|
assert 1 == len(self.mock_mp_2.service_calls['media_play'])
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_media_pause(),
|
ump.async_media_pause(),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(1, len(self.mock_mp_2.service_calls['media_pause']))
|
assert 1 == len(self.mock_mp_2.service_calls['media_pause'])
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_media_previous_track(),
|
ump.async_media_previous_track(),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(
|
assert 1 == len(self.mock_mp_2.service_calls['media_previous_track'])
|
||||||
1, len(self.mock_mp_2.service_calls['media_previous_track']))
|
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_media_next_track(),
|
ump.async_media_next_track(),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(
|
assert 1 == len(self.mock_mp_2.service_calls['media_next_track'])
|
||||||
1, len(self.mock_mp_2.service_calls['media_next_track']))
|
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_media_seek(100),
|
ump.async_media_seek(100),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(1, len(self.mock_mp_2.service_calls['media_seek']))
|
assert 1 == len(self.mock_mp_2.service_calls['media_seek'])
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_play_media('movie', 'batman'),
|
ump.async_play_media('movie', 'batman'),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(1, len(self.mock_mp_2.service_calls['play_media']))
|
assert 1 == len(self.mock_mp_2.service_calls['play_media'])
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_volume_up(),
|
ump.async_volume_up(),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(1, len(self.mock_mp_2.service_calls['volume_up']))
|
assert 1 == len(self.mock_mp_2.service_calls['volume_up'])
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_volume_down(),
|
ump.async_volume_down(),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(1, len(self.mock_mp_2.service_calls['volume_down']))
|
assert 1 == len(self.mock_mp_2.service_calls['volume_down'])
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_media_play_pause(),
|
ump.async_media_play_pause(),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(
|
assert 1 == len(self.mock_mp_2.service_calls['media_play_pause'])
|
||||||
1, len(self.mock_mp_2.service_calls['media_play_pause']))
|
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_select_source('dvd'),
|
ump.async_select_source('dvd'),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(
|
assert 1 == len(self.mock_mp_2.service_calls['select_source'])
|
||||||
1, len(self.mock_mp_2.service_calls['select_source']))
|
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_clear_playlist(),
|
ump.async_clear_playlist(),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(
|
assert 1 == len(self.mock_mp_2.service_calls['clear_playlist'])
|
||||||
1, len(self.mock_mp_2.service_calls['clear_playlist']))
|
|
||||||
|
|
||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
ump.async_set_shuffle(True),
|
ump.async_set_shuffle(True),
|
||||||
self.hass.loop).result()
|
self.hass.loop).result()
|
||||||
self.assertEqual(1, len(self.mock_mp_2.service_calls['shuffle_set']))
|
assert 1 == len(self.mock_mp_2.service_calls['shuffle_set'])
|
||||||
|
|
||||||
def test_service_call_to_command(self):
|
def test_service_call_to_command(self):
|
||||||
"""Test service call to command."""
|
"""Test service call to command."""
|
||||||
|
@ -727,4 +721,4 @@ class TestMediaPlayer(unittest.TestCase):
|
||||||
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
||||||
|
|
||||||
run_coroutine_threadsafe(ump.async_turn_off(), self.hass.loop).result()
|
run_coroutine_threadsafe(ump.async_turn_off(), self.hass.loop).result()
|
||||||
self.assertEqual(1, len(service))
|
assert 1 == len(service)
|
||||||
|
|
|
@ -67,7 +67,7 @@ class TestYamahaMediaPlayer(unittest.TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.assertTrue(setup_component(self.hass, mp.DOMAIN, config))
|
assert setup_component(self.hass, mp.DOMAIN, config)
|
||||||
|
|
||||||
@patch('rxv.RXV')
|
@patch('rxv.RXV')
|
||||||
def test_enable_output(self, mock_rxv):
|
def test_enable_output(self, mock_rxv):
|
||||||
|
|
|
@ -4,7 +4,7 @@ from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.components import mqtt
|
from homeassistant.components import mqtt
|
||||||
from homeassistant.components.mqtt.discovery import async_start, \
|
from homeassistant.components.mqtt.discovery import async_start, \
|
||||||
ALREADY_DISCOVERED
|
ALREADY_DISCOVERED
|
||||||
from homeassistant.const import STATE_ON, STATE_OFF
|
from homeassistant.const import STATE_ON, STATE_OFF
|
||||||
|
|
||||||
from tests.common import async_fire_mqtt_message, mock_coro, MockConfigEntry
|
from tests.common import async_fire_mqtt_message, mock_coro, MockConfigEntry
|
||||||
|
|
|
@ -71,7 +71,7 @@ class TestMQTTComponent(unittest.TestCase):
|
||||||
"""Test if client stops on HA stop."""
|
"""Test if client stops on HA stop."""
|
||||||
self.hass.bus.fire(EVENT_HOMEASSISTANT_STOP)
|
self.hass.bus.fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(self.hass.data['mqtt'].async_disconnect.called)
|
assert self.hass.data['mqtt'].async_disconnect.called
|
||||||
|
|
||||||
def test_publish_calls_service(self):
|
def test_publish_calls_service(self):
|
||||||
"""Test the publishing of call to services."""
|
"""Test the publishing of call to services."""
|
||||||
|
@ -81,13 +81,11 @@ class TestMQTTComponent(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual(
|
assert 'test-topic' == \
|
||||||
'test-topic',
|
self.calls[0][0].data['service_data'][mqtt.ATTR_TOPIC]
|
||||||
self.calls[0][0].data['service_data'][mqtt.ATTR_TOPIC])
|
assert 'test-payload' == \
|
||||||
self.assertEqual(
|
self.calls[0][0].data['service_data'][mqtt.ATTR_PAYLOAD]
|
||||||
'test-payload',
|
|
||||||
self.calls[0][0].data['service_data'][mqtt.ATTR_PAYLOAD])
|
|
||||||
|
|
||||||
def test_service_call_without_topic_does_not_publish(self):
|
def test_service_call_without_topic_does_not_publish(self):
|
||||||
"""Test the service call if topic is missing."""
|
"""Test the service call if topic is missing."""
|
||||||
|
@ -96,7 +94,7 @@ class TestMQTTComponent(unittest.TestCase):
|
||||||
ATTR_SERVICE: mqtt.SERVICE_PUBLISH
|
ATTR_SERVICE: mqtt.SERVICE_PUBLISH
|
||||||
})
|
})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(not self.hass.data['mqtt'].async_publish.called)
|
assert not self.hass.data['mqtt'].async_publish.called
|
||||||
|
|
||||||
def test_service_call_with_template_payload_renders_template(self):
|
def test_service_call_with_template_payload_renders_template(self):
|
||||||
"""Test the service call with rendered template.
|
"""Test the service call with rendered template.
|
||||||
|
@ -105,9 +103,8 @@ class TestMQTTComponent(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
mqtt.publish_template(self.hass, "test/topic", "{{ 1+1 }}")
|
mqtt.publish_template(self.hass, "test/topic", "{{ 1+1 }}")
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(self.hass.data['mqtt'].async_publish.called)
|
assert self.hass.data['mqtt'].async_publish.called
|
||||||
self.assertEqual(
|
assert self.hass.data['mqtt'].async_publish.call_args[0][1] == "2"
|
||||||
self.hass.data['mqtt'].async_publish.call_args[0][1], "2")
|
|
||||||
|
|
||||||
def test_service_call_with_payload_doesnt_render_template(self):
|
def test_service_call_with_payload_doesnt_render_template(self):
|
||||||
"""Test the service call with unrendered template.
|
"""Test the service call with unrendered template.
|
||||||
|
@ -121,7 +118,7 @@ class TestMQTTComponent(unittest.TestCase):
|
||||||
mqtt.ATTR_PAYLOAD: payload,
|
mqtt.ATTR_PAYLOAD: payload,
|
||||||
mqtt.ATTR_PAYLOAD_TEMPLATE: payload_template
|
mqtt.ATTR_PAYLOAD_TEMPLATE: payload_template
|
||||||
}, blocking=True)
|
}, blocking=True)
|
||||||
self.assertFalse(self.hass.data['mqtt'].async_publish.called)
|
assert not self.hass.data['mqtt'].async_publish.called
|
||||||
|
|
||||||
def test_service_call_with_ascii_qos_retain_flags(self):
|
def test_service_call_with_ascii_qos_retain_flags(self):
|
||||||
"""Test the service call with args that can be misinterpreted.
|
"""Test the service call with args that can be misinterpreted.
|
||||||
|
@ -134,22 +131,26 @@ class TestMQTTComponent(unittest.TestCase):
|
||||||
mqtt.ATTR_QOS: '2',
|
mqtt.ATTR_QOS: '2',
|
||||||
mqtt.ATTR_RETAIN: 'no'
|
mqtt.ATTR_RETAIN: 'no'
|
||||||
}, blocking=True)
|
}, blocking=True)
|
||||||
self.assertTrue(self.hass.data['mqtt'].async_publish.called)
|
assert self.hass.data['mqtt'].async_publish.called
|
||||||
self.assertEqual(
|
assert self.hass.data['mqtt'].async_publish.call_args[0][2] == 2
|
||||||
self.hass.data['mqtt'].async_publish.call_args[0][2], 2)
|
assert not self.hass.data['mqtt'].async_publish.call_args[0][3]
|
||||||
self.assertFalse(self.hass.data['mqtt'].async_publish.call_args[0][3])
|
|
||||||
|
|
||||||
def test_validate_topic(self):
|
def test_validate_topic(self):
|
||||||
"""Test topic name/filter validation."""
|
"""Test topic name/filter validation."""
|
||||||
# Invalid UTF-8, must not contain U+D800 to U+DFFF.
|
# Invalid UTF-8, must not contain U+D800 to U+DFFF.
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_topic, '\ud800')
|
with pytest.raises(vol.Invalid):
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_topic, '\udfff')
|
mqtt.valid_topic('\ud800')
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
mqtt.valid_topic('\udfff')
|
||||||
# Topic MUST NOT be empty
|
# Topic MUST NOT be empty
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_topic, '')
|
with pytest.raises(vol.Invalid):
|
||||||
|
mqtt.valid_topic('')
|
||||||
# Topic MUST NOT be longer than 65535 encoded bytes.
|
# Topic MUST NOT be longer than 65535 encoded bytes.
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_topic, 'ü' * 32768)
|
with pytest.raises(vol.Invalid):
|
||||||
|
mqtt.valid_topic('ü' * 32768)
|
||||||
# UTF-8 MUST NOT include null character
|
# UTF-8 MUST NOT include null character
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_topic, 'bad\0one')
|
with pytest.raises(vol.Invalid):
|
||||||
|
mqtt.valid_topic('bad\0one')
|
||||||
|
|
||||||
# Topics "SHOULD NOT" include these special characters
|
# Topics "SHOULD NOT" include these special characters
|
||||||
# (not MUST NOT, RFC2119). The receiver MAY close the connection.
|
# (not MUST NOT, RFC2119). The receiver MAY close the connection.
|
||||||
|
@ -163,17 +164,25 @@ class TestMQTTComponent(unittest.TestCase):
|
||||||
"""Test invalid subscribe topics."""
|
"""Test invalid subscribe topics."""
|
||||||
mqtt.valid_subscribe_topic('#')
|
mqtt.valid_subscribe_topic('#')
|
||||||
mqtt.valid_subscribe_topic('sport/#')
|
mqtt.valid_subscribe_topic('sport/#')
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_subscribe_topic, 'sport/#/')
|
with pytest.raises(vol.Invalid):
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_subscribe_topic, 'foo/bar#')
|
mqtt.valid_subscribe_topic('sport/#/')
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_subscribe_topic, 'foo/#/bar')
|
with pytest.raises(vol.Invalid):
|
||||||
|
mqtt.valid_subscribe_topic('foo/bar#')
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
mqtt.valid_subscribe_topic('foo/#/bar')
|
||||||
|
|
||||||
mqtt.valid_subscribe_topic('+')
|
mqtt.valid_subscribe_topic('+')
|
||||||
mqtt.valid_subscribe_topic('+/tennis/#')
|
mqtt.valid_subscribe_topic('+/tennis/#')
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_subscribe_topic, 'sport+')
|
with pytest.raises(vol.Invalid):
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_subscribe_topic, 'sport+/')
|
mqtt.valid_subscribe_topic('sport+')
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_subscribe_topic, 'sport/+1')
|
with pytest.raises(vol.Invalid):
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_subscribe_topic, 'sport/+#')
|
mqtt.valid_subscribe_topic('sport+/')
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_subscribe_topic, 'bad+topic')
|
with pytest.raises(vol.Invalid):
|
||||||
|
mqtt.valid_subscribe_topic('sport/+1')
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
mqtt.valid_subscribe_topic('sport/+#')
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
mqtt.valid_subscribe_topic('bad+topic')
|
||||||
mqtt.valid_subscribe_topic('sport/+/player1')
|
mqtt.valid_subscribe_topic('sport/+/player1')
|
||||||
mqtt.valid_subscribe_topic('/finance')
|
mqtt.valid_subscribe_topic('/finance')
|
||||||
mqtt.valid_subscribe_topic('+/+')
|
mqtt.valid_subscribe_topic('+/+')
|
||||||
|
@ -181,10 +190,14 @@ class TestMQTTComponent(unittest.TestCase):
|
||||||
|
|
||||||
def test_validate_publish_topic(self):
|
def test_validate_publish_topic(self):
|
||||||
"""Test invalid publish topics."""
|
"""Test invalid publish topics."""
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_publish_topic, 'pub+')
|
with pytest.raises(vol.Invalid):
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_publish_topic, 'pub/+')
|
mqtt.valid_publish_topic('pub+')
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_publish_topic, '1#')
|
with pytest.raises(vol.Invalid):
|
||||||
self.assertRaises(vol.Invalid, mqtt.valid_publish_topic, 'bad+topic')
|
mqtt.valid_publish_topic('pub/+')
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
mqtt.valid_publish_topic('1#')
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
mqtt.valid_publish_topic('bad+topic')
|
||||||
mqtt.valid_publish_topic('//')
|
mqtt.valid_publish_topic('//')
|
||||||
|
|
||||||
# Topic names beginning with $ SHOULD NOT be used, but can
|
# Topic names beginning with $ SHOULD NOT be used, but can
|
||||||
|
@ -218,18 +231,20 @@ class TestMQTTComponent(unittest.TestCase):
|
||||||
'sw_version': '0.1-beta',
|
'sw_version': '0.1-beta',
|
||||||
})
|
})
|
||||||
# no identifiers
|
# no identifiers
|
||||||
self.assertRaises(vol.Invalid, mqtt.MQTT_ENTITY_DEVICE_INFO_SCHEMA, {
|
with pytest.raises(vol.Invalid):
|
||||||
'manufacturer': 'Whatever',
|
mqtt.MQTT_ENTITY_DEVICE_INFO_SCHEMA({
|
||||||
'name': 'Beer',
|
'manufacturer': 'Whatever',
|
||||||
'model': 'Glass',
|
'name': 'Beer',
|
||||||
'sw_version': '0.1-beta',
|
'model': 'Glass',
|
||||||
})
|
'sw_version': '0.1-beta',
|
||||||
|
})
|
||||||
# empty identifiers
|
# empty identifiers
|
||||||
self.assertRaises(vol.Invalid, mqtt.MQTT_ENTITY_DEVICE_INFO_SCHEMA, {
|
with pytest.raises(vol.Invalid):
|
||||||
'identifiers': [],
|
mqtt.MQTT_ENTITY_DEVICE_INFO_SCHEMA({
|
||||||
'connections': [],
|
'identifiers': [],
|
||||||
'name': 'Beer',
|
'connections': [],
|
||||||
})
|
'name': 'Beer',
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
|
@ -253,7 +268,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
|
|
||||||
def aiohttp_client_starts_on_home_assistant_mqtt_setup(self):
|
def aiohttp_client_starts_on_home_assistant_mqtt_setup(self):
|
||||||
"""Test if client is connected after mqtt init on bootstrap."""
|
"""Test if client is connected after mqtt init on bootstrap."""
|
||||||
self.assertEqual(self.hass.data['mqtt']._mqttc.connect.call_count, 1)
|
assert self.hass.data['mqtt']._mqttc.connect.call_count == 1
|
||||||
|
|
||||||
def test_receiving_non_utf8_message_gets_logged(self):
|
def test_receiving_non_utf8_message_gets_logged(self):
|
||||||
"""Test receiving a non utf8 encoded message."""
|
"""Test receiving a non utf8 encoded message."""
|
||||||
|
@ -263,10 +278,10 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'test-topic', b'\x9a')
|
fire_mqtt_message(self.hass, 'test-topic', b'\x9a')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertIn(
|
assert \
|
||||||
"WARNING:homeassistant.components.mqtt:Can't decode payload "
|
"WARNING:homeassistant.components.mqtt:Can't decode payload " \
|
||||||
"b'\\x9a' on test-topic with encoding utf-8",
|
"b'\\x9a' on test-topic with encoding utf-8" in \
|
||||||
test_handle.output[0])
|
test_handle.output[0]
|
||||||
|
|
||||||
def test_all_subscriptions_run_when_decode_fails(self):
|
def test_all_subscriptions_run_when_decode_fails(self):
|
||||||
"""Test all other subscriptions still run when decode fails for one."""
|
"""Test all other subscriptions still run when decode fails for one."""
|
||||||
|
@ -277,7 +292,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'test-topic', '°C')
|
fire_mqtt_message(self.hass, 'test-topic', '°C')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_subscribe_topic(self):
|
def test_subscribe_topic(self):
|
||||||
"""Test the subscription of a topic."""
|
"""Test the subscription of a topic."""
|
||||||
|
@ -286,16 +301,16 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'test-topic', 'test-payload')
|
fire_mqtt_message(self.hass, 'test-topic', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual('test-topic', self.calls[0][0])
|
assert 'test-topic' == self.calls[0][0]
|
||||||
self.assertEqual('test-payload', self.calls[0][1])
|
assert 'test-payload' == self.calls[0][1]
|
||||||
|
|
||||||
unsub()
|
unsub()
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'test-topic', 'test-payload')
|
fire_mqtt_message(self.hass, 'test-topic', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
|
|
||||||
def test_subscribe_topic_not_match(self):
|
def test_subscribe_topic_not_match(self):
|
||||||
"""Test if subscribed topic is not a match."""
|
"""Test if subscribed topic is not a match."""
|
||||||
|
@ -304,7 +319,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'another-test-topic', 'test-payload')
|
fire_mqtt_message(self.hass, 'another-test-topic', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_subscribe_topic_level_wildcard(self):
|
def test_subscribe_topic_level_wildcard(self):
|
||||||
"""Test the subscription of wildcard topics."""
|
"""Test the subscription of wildcard topics."""
|
||||||
|
@ -313,9 +328,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'test-topic/bier/on', 'test-payload')
|
fire_mqtt_message(self.hass, 'test-topic/bier/on', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual('test-topic/bier/on', self.calls[0][0])
|
assert 'test-topic/bier/on' == self.calls[0][0]
|
||||||
self.assertEqual('test-payload', self.calls[0][1])
|
assert 'test-payload' == self.calls[0][1]
|
||||||
|
|
||||||
def test_subscribe_topic_level_wildcard_no_subtree_match(self):
|
def test_subscribe_topic_level_wildcard_no_subtree_match(self):
|
||||||
"""Test the subscription of wildcard topics."""
|
"""Test the subscription of wildcard topics."""
|
||||||
|
@ -324,7 +339,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'test-topic/bier', 'test-payload')
|
fire_mqtt_message(self.hass, 'test-topic/bier', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_subscribe_topic_level_wildcard_root_topic_no_subtree_match(self):
|
def test_subscribe_topic_level_wildcard_root_topic_no_subtree_match(self):
|
||||||
"""Test the subscription of wildcard topics."""
|
"""Test the subscription of wildcard topics."""
|
||||||
|
@ -333,7 +348,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'test-topic-123', 'test-payload')
|
fire_mqtt_message(self.hass, 'test-topic-123', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_subscribe_topic_subtree_wildcard_subtree_topic(self):
|
def test_subscribe_topic_subtree_wildcard_subtree_topic(self):
|
||||||
"""Test the subscription of wildcard topics."""
|
"""Test the subscription of wildcard topics."""
|
||||||
|
@ -342,9 +357,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'test-topic/bier/on', 'test-payload')
|
fire_mqtt_message(self.hass, 'test-topic/bier/on', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual('test-topic/bier/on', self.calls[0][0])
|
assert 'test-topic/bier/on' == self.calls[0][0]
|
||||||
self.assertEqual('test-payload', self.calls[0][1])
|
assert 'test-payload' == self.calls[0][1]
|
||||||
|
|
||||||
def test_subscribe_topic_subtree_wildcard_root_topic(self):
|
def test_subscribe_topic_subtree_wildcard_root_topic(self):
|
||||||
"""Test the subscription of wildcard topics."""
|
"""Test the subscription of wildcard topics."""
|
||||||
|
@ -353,9 +368,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'test-topic', 'test-payload')
|
fire_mqtt_message(self.hass, 'test-topic', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual('test-topic', self.calls[0][0])
|
assert 'test-topic' == self.calls[0][0]
|
||||||
self.assertEqual('test-payload', self.calls[0][1])
|
assert 'test-payload' == self.calls[0][1]
|
||||||
|
|
||||||
def test_subscribe_topic_subtree_wildcard_no_match(self):
|
def test_subscribe_topic_subtree_wildcard_no_match(self):
|
||||||
"""Test the subscription of wildcard topics."""
|
"""Test the subscription of wildcard topics."""
|
||||||
|
@ -364,7 +379,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'another-test-topic', 'test-payload')
|
fire_mqtt_message(self.hass, 'another-test-topic', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_subscribe_topic_level_wildcard_and_wildcard_root_topic(self):
|
def test_subscribe_topic_level_wildcard_and_wildcard_root_topic(self):
|
||||||
"""Test the subscription of wildcard topics."""
|
"""Test the subscription of wildcard topics."""
|
||||||
|
@ -373,9 +388,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'hi/test-topic', 'test-payload')
|
fire_mqtt_message(self.hass, 'hi/test-topic', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual('hi/test-topic', self.calls[0][0])
|
assert 'hi/test-topic' == self.calls[0][0]
|
||||||
self.assertEqual('test-payload', self.calls[0][1])
|
assert 'test-payload' == self.calls[0][1]
|
||||||
|
|
||||||
def test_subscribe_topic_level_wildcard_and_wildcard_subtree_topic(self):
|
def test_subscribe_topic_level_wildcard_and_wildcard_subtree_topic(self):
|
||||||
"""Test the subscription of wildcard topics."""
|
"""Test the subscription of wildcard topics."""
|
||||||
|
@ -384,9 +399,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'hi/test-topic/here-iam', 'test-payload')
|
fire_mqtt_message(self.hass, 'hi/test-topic/here-iam', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual('hi/test-topic/here-iam', self.calls[0][0])
|
assert 'hi/test-topic/here-iam' == self.calls[0][0]
|
||||||
self.assertEqual('test-payload', self.calls[0][1])
|
assert 'test-payload' == self.calls[0][1]
|
||||||
|
|
||||||
def test_subscribe_topic_level_wildcard_and_wildcard_level_no_match(self):
|
def test_subscribe_topic_level_wildcard_and_wildcard_level_no_match(self):
|
||||||
"""Test the subscription of wildcard topics."""
|
"""Test the subscription of wildcard topics."""
|
||||||
|
@ -395,7 +410,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'hi/here-iam/test-topic', 'test-payload')
|
fire_mqtt_message(self.hass, 'hi/here-iam/test-topic', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_subscribe_topic_level_wildcard_and_wildcard_no_match(self):
|
def test_subscribe_topic_level_wildcard_and_wildcard_no_match(self):
|
||||||
"""Test the subscription of wildcard topics."""
|
"""Test the subscription of wildcard topics."""
|
||||||
|
@ -404,7 +419,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, 'hi/another-test-topic', 'test-payload')
|
fire_mqtt_message(self.hass, 'hi/another-test-topic', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
assert 0 == len(self.calls)
|
||||||
|
|
||||||
def test_subscribe_topic_sys_root(self):
|
def test_subscribe_topic_sys_root(self):
|
||||||
"""Test the subscription of $ root topics."""
|
"""Test the subscription of $ root topics."""
|
||||||
|
@ -413,9 +428,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, '$test-topic/subtree/on', 'test-payload')
|
fire_mqtt_message(self.hass, '$test-topic/subtree/on', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual('$test-topic/subtree/on', self.calls[0][0])
|
assert '$test-topic/subtree/on' == self.calls[0][0]
|
||||||
self.assertEqual('test-payload', self.calls[0][1])
|
assert 'test-payload' == self.calls[0][1]
|
||||||
|
|
||||||
def test_subscribe_topic_sys_root_and_wildcard_topic(self):
|
def test_subscribe_topic_sys_root_and_wildcard_topic(self):
|
||||||
"""Test the subscription of $ root and wildcard topics."""
|
"""Test the subscription of $ root and wildcard topics."""
|
||||||
|
@ -424,9 +439,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
fire_mqtt_message(self.hass, '$test-topic/some-topic', 'test-payload')
|
fire_mqtt_message(self.hass, '$test-topic/some-topic', 'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual('$test-topic/some-topic', self.calls[0][0])
|
assert '$test-topic/some-topic' == self.calls[0][0]
|
||||||
self.assertEqual('test-payload', self.calls[0][1])
|
assert 'test-payload' == self.calls[0][1]
|
||||||
|
|
||||||
def test_subscribe_topic_sys_root_and_wildcard_subtree_topic(self):
|
def test_subscribe_topic_sys_root_and_wildcard_subtree_topic(self):
|
||||||
"""Test the subscription of $ root and wildcard subtree topics."""
|
"""Test the subscription of $ root and wildcard subtree topics."""
|
||||||
|
@ -436,9 +451,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
'test-payload')
|
'test-payload')
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual('$test-topic/subtree/some-topic', self.calls[0][0])
|
assert '$test-topic/subtree/some-topic' == self.calls[0][0]
|
||||||
self.assertEqual('test-payload', self.calls[0][1])
|
assert 'test-payload' == self.calls[0][1]
|
||||||
|
|
||||||
def test_subscribe_special_characters(self):
|
def test_subscribe_special_characters(self):
|
||||||
"""Test the subscription to topics with special characters."""
|
"""Test the subscription to topics with special characters."""
|
||||||
|
@ -449,9 +464,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, topic, payload)
|
fire_mqtt_message(self.hass, topic, payload)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
assert 1 == len(self.calls)
|
||||||
self.assertEqual(topic, self.calls[0][0])
|
assert topic == self.calls[0][0]
|
||||||
self.assertEqual(payload, self.calls[0][1])
|
assert payload == self.calls[0][1]
|
||||||
|
|
||||||
def test_mqtt_failed_connection_results_in_disconnect(self):
|
def test_mqtt_failed_connection_results_in_disconnect(self):
|
||||||
"""Test if connection failure leads to disconnect."""
|
"""Test if connection failure leads to disconnect."""
|
||||||
|
@ -459,12 +474,12 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
self.hass.data['mqtt']._mqttc = mock.MagicMock()
|
self.hass.data['mqtt']._mqttc = mock.MagicMock()
|
||||||
self.hass.data['mqtt']._mqtt_on_connect(
|
self.hass.data['mqtt']._mqtt_on_connect(
|
||||||
None, {'topics': {}}, 0, result_code)
|
None, {'topics': {}}, 0, result_code)
|
||||||
self.assertTrue(self.hass.data['mqtt']._mqttc.disconnect.called)
|
assert self.hass.data['mqtt']._mqttc.disconnect.called
|
||||||
|
|
||||||
def test_mqtt_disconnect_tries_no_reconnect_on_stop(self):
|
def test_mqtt_disconnect_tries_no_reconnect_on_stop(self):
|
||||||
"""Test the disconnect tries."""
|
"""Test the disconnect tries."""
|
||||||
self.hass.data['mqtt']._mqtt_on_disconnect(None, None, 0)
|
self.hass.data['mqtt']._mqtt_on_disconnect(None, None, 0)
|
||||||
self.assertFalse(self.hass.data['mqtt']._mqttc.reconnect.called)
|
assert not self.hass.data['mqtt']._mqttc.reconnect.called
|
||||||
|
|
||||||
@mock.patch('homeassistant.components.mqtt.time.sleep')
|
@mock.patch('homeassistant.components.mqtt.time.sleep')
|
||||||
def test_mqtt_disconnect_tries_reconnect(self, mock_sleep):
|
def test_mqtt_disconnect_tries_reconnect(self, mock_sleep):
|
||||||
|
@ -476,11 +491,10 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
]
|
]
|
||||||
self.hass.data['mqtt']._mqttc.reconnect.side_effect = [1, 1, 1, 0]
|
self.hass.data['mqtt']._mqttc.reconnect.side_effect = [1, 1, 1, 0]
|
||||||
self.hass.data['mqtt']._mqtt_on_disconnect(None, None, 1)
|
self.hass.data['mqtt']._mqtt_on_disconnect(None, None, 1)
|
||||||
self.assertTrue(self.hass.data['mqtt']._mqttc.reconnect.called)
|
assert self.hass.data['mqtt']._mqttc.reconnect.called
|
||||||
self.assertEqual(
|
assert 4 == len(self.hass.data['mqtt']._mqttc.reconnect.mock_calls)
|
||||||
4, len(self.hass.data['mqtt']._mqttc.reconnect.mock_calls))
|
assert [1, 2, 4] == \
|
||||||
self.assertEqual([1, 2, 4],
|
[call[1][0] for call in mock_sleep.mock_calls]
|
||||||
[call[1][0] for call in mock_sleep.mock_calls])
|
|
||||||
|
|
||||||
def test_retained_message_on_subscribe_received(self):
|
def test_retained_message_on_subscribe_received(self):
|
||||||
"""Test every subscriber receives retained message on subscribe."""
|
"""Test every subscriber receives retained message on subscribe."""
|
||||||
|
@ -493,34 +507,34 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
calls_a = mock.MagicMock()
|
calls_a = mock.MagicMock()
|
||||||
mqtt.subscribe(self.hass, 'test/state', calls_a)
|
mqtt.subscribe(self.hass, 'test/state', calls_a)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(calls_a.called)
|
assert calls_a.called
|
||||||
|
|
||||||
calls_b = mock.MagicMock()
|
calls_b = mock.MagicMock()
|
||||||
mqtt.subscribe(self.hass, 'test/state', calls_b)
|
mqtt.subscribe(self.hass, 'test/state', calls_b)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(calls_b.called)
|
assert calls_b.called
|
||||||
|
|
||||||
def test_not_calling_unsubscribe_with_active_subscribers(self):
|
def test_not_calling_unsubscribe_with_active_subscribers(self):
|
||||||
"""Test not calling unsubscribe() when other subscribers are active."""
|
"""Test not calling unsubscribe() when other subscribers are active."""
|
||||||
unsub = mqtt.subscribe(self.hass, 'test/state', None)
|
unsub = mqtt.subscribe(self.hass, 'test/state', None)
|
||||||
mqtt.subscribe(self.hass, 'test/state', None)
|
mqtt.subscribe(self.hass, 'test/state', None)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(self.hass.data['mqtt']._mqttc.subscribe.called)
|
assert self.hass.data['mqtt']._mqttc.subscribe.called
|
||||||
|
|
||||||
unsub()
|
unsub()
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertFalse(self.hass.data['mqtt']._mqttc.unsubscribe.called)
|
assert not self.hass.data['mqtt']._mqttc.unsubscribe.called
|
||||||
|
|
||||||
def test_restore_subscriptions_on_reconnect(self):
|
def test_restore_subscriptions_on_reconnect(self):
|
||||||
"""Test subscriptions are restored on reconnect."""
|
"""Test subscriptions are restored on reconnect."""
|
||||||
mqtt.subscribe(self.hass, 'test/state', None)
|
mqtt.subscribe(self.hass, 'test/state', None)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(self.hass.data['mqtt']._mqttc.subscribe.call_count, 1)
|
assert self.hass.data['mqtt']._mqttc.subscribe.call_count == 1
|
||||||
|
|
||||||
self.hass.data['mqtt']._mqtt_on_disconnect(None, None, 0)
|
self.hass.data['mqtt']._mqtt_on_disconnect(None, None, 0)
|
||||||
self.hass.data['mqtt']._mqtt_on_connect(None, None, None, 0)
|
self.hass.data['mqtt']._mqtt_on_connect(None, None, None, 0)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(self.hass.data['mqtt']._mqttc.subscribe.call_count, 2)
|
assert self.hass.data['mqtt']._mqttc.subscribe.call_count == 2
|
||||||
|
|
||||||
def test_restore_all_active_subscriptions_on_reconnect(self):
|
def test_restore_all_active_subscriptions_on_reconnect(self):
|
||||||
"""Test active subscriptions are restored correctly on reconnect."""
|
"""Test active subscriptions are restored correctly on reconnect."""
|
||||||
|
@ -538,21 +552,21 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||||
mock.call('test/state', 0),
|
mock.call('test/state', 0),
|
||||||
mock.call('test/state', 1)
|
mock.call('test/state', 1)
|
||||||
]
|
]
|
||||||
self.assertEqual(self.hass.data['mqtt']._mqttc.subscribe.mock_calls,
|
assert self.hass.data['mqtt']._mqttc.subscribe.mock_calls == \
|
||||||
expected)
|
expected
|
||||||
|
|
||||||
unsub()
|
unsub()
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(self.hass.data['mqtt']._mqttc.unsubscribe.call_count,
|
assert self.hass.data['mqtt']._mqttc.unsubscribe.call_count == \
|
||||||
0)
|
0
|
||||||
|
|
||||||
self.hass.data['mqtt']._mqtt_on_disconnect(None, None, 0)
|
self.hass.data['mqtt']._mqtt_on_disconnect(None, None, 0)
|
||||||
self.hass.data['mqtt']._mqtt_on_connect(None, None, None, 0)
|
self.hass.data['mqtt']._mqtt_on_connect(None, None, None, 0)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
expected.append(mock.call('test/state', 1))
|
expected.append(mock.call('test/state', 1))
|
||||||
self.assertEqual(self.hass.data['mqtt']._mqttc.subscribe.mock_calls,
|
assert self.hass.data['mqtt']._mqttc.subscribe.mock_calls == \
|
||||||
expected)
|
expected
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
|
|
@ -120,11 +120,10 @@ class TestApns(unittest.TestCase):
|
||||||
Mock(return_value=yaml_file)):
|
Mock(return_value=yaml_file)):
|
||||||
self._setup_notify()
|
self._setup_notify()
|
||||||
|
|
||||||
self.assertTrue(self.hass.services.call(notify.DOMAIN,
|
assert self.hass.services.call(notify.DOMAIN, 'apns_test_app', {
|
||||||
'apns_test_app',
|
'push_id': '1234',
|
||||||
{'push_id': '1234',
|
'name': 'test device'
|
||||||
'name': 'test device'},
|
}, blocking=True)
|
||||||
blocking=True))
|
|
||||||
|
|
||||||
assert len(written_devices) == 1
|
assert len(written_devices) == 1
|
||||||
assert written_devices[0].name == 'test device'
|
assert written_devices[0].name == 'test device'
|
||||||
|
@ -156,16 +155,16 @@ class TestApns(unittest.TestCase):
|
||||||
Mock(return_value=yaml_file)):
|
Mock(return_value=yaml_file)):
|
||||||
self._setup_notify()
|
self._setup_notify()
|
||||||
|
|
||||||
self.assertTrue(self.hass.services.call(notify.DOMAIN, 'apns_test_app',
|
assert self.hass.services.call(notify.DOMAIN, 'apns_test_app', {
|
||||||
{'push_id': '1234'},
|
'push_id': '1234'
|
||||||
blocking=True))
|
}, blocking=True)
|
||||||
|
|
||||||
devices = {dev.push_id: dev for dev in written_devices}
|
devices = {dev.push_id: dev for dev in written_devices}
|
||||||
|
|
||||||
test_device = devices.get('1234')
|
test_device = devices.get('1234')
|
||||||
|
|
||||||
self.assertIsNotNone(test_device)
|
assert test_device is not None
|
||||||
self.assertIsNone(test_device.name)
|
assert test_device.name is None
|
||||||
|
|
||||||
@patch('homeassistant.components.notify.apns._write_device')
|
@patch('homeassistant.components.notify.apns._write_device')
|
||||||
def test_update_existing_device(self, mock_write):
|
def test_update_existing_device(self, mock_write):
|
||||||
|
@ -192,21 +191,20 @@ class TestApns(unittest.TestCase):
|
||||||
Mock(return_value=yaml_file)):
|
Mock(return_value=yaml_file)):
|
||||||
self._setup_notify()
|
self._setup_notify()
|
||||||
|
|
||||||
self.assertTrue(self.hass.services.call(notify.DOMAIN,
|
assert self.hass.services.call(notify.DOMAIN, 'apns_test_app', {
|
||||||
'apns_test_app',
|
'push_id': '1234',
|
||||||
{'push_id': '1234',
|
'name': 'updated device 1'
|
||||||
'name': 'updated device 1'},
|
}, blocking=True)
|
||||||
blocking=True))
|
|
||||||
|
|
||||||
devices = {dev.push_id: dev for dev in written_devices}
|
devices = {dev.push_id: dev for dev in written_devices}
|
||||||
|
|
||||||
test_device_1 = devices.get('1234')
|
test_device_1 = devices.get('1234')
|
||||||
test_device_2 = devices.get('5678')
|
test_device_2 = devices.get('5678')
|
||||||
|
|
||||||
self.assertIsNotNone(test_device_1)
|
assert test_device_1 is not None
|
||||||
self.assertIsNotNone(test_device_2)
|
assert test_device_2 is not None
|
||||||
|
|
||||||
self.assertEqual('updated device 1', test_device_1.name)
|
assert 'updated device 1' == test_device_1.name
|
||||||
|
|
||||||
@patch('homeassistant.components.notify.apns._write_device')
|
@patch('homeassistant.components.notify.apns._write_device')
|
||||||
def test_update_existing_device_with_tracking_id(self, mock_write):
|
def test_update_existing_device_with_tracking_id(self, mock_write):
|
||||||
|
@ -235,24 +233,23 @@ class TestApns(unittest.TestCase):
|
||||||
Mock(return_value=yaml_file)):
|
Mock(return_value=yaml_file)):
|
||||||
self._setup_notify()
|
self._setup_notify()
|
||||||
|
|
||||||
self.assertTrue(self.hass.services.call(notify.DOMAIN,
|
assert self.hass.services.call(notify.DOMAIN, 'apns_test_app', {
|
||||||
'apns_test_app',
|
'push_id': '1234',
|
||||||
{'push_id': '1234',
|
'name': 'updated device 1'
|
||||||
'name': 'updated device 1'},
|
}, blocking=True)
|
||||||
blocking=True))
|
|
||||||
|
|
||||||
devices = {dev.push_id: dev for dev in written_devices}
|
devices = {dev.push_id: dev for dev in written_devices}
|
||||||
|
|
||||||
test_device_1 = devices.get('1234')
|
test_device_1 = devices.get('1234')
|
||||||
test_device_2 = devices.get('5678')
|
test_device_2 = devices.get('5678')
|
||||||
|
|
||||||
self.assertIsNotNone(test_device_1)
|
assert test_device_1 is not None
|
||||||
self.assertIsNotNone(test_device_2)
|
assert test_device_2 is not None
|
||||||
|
|
||||||
self.assertEqual('tracking123',
|
assert 'tracking123' == \
|
||||||
test_device_1.tracking_device_id)
|
test_device_1.tracking_device_id
|
||||||
self.assertEqual('tracking456',
|
assert 'tracking456' == \
|
||||||
test_device_2.tracking_device_id)
|
test_device_2.tracking_device_id
|
||||||
|
|
||||||
@patch('apns2.client.APNsClient')
|
@patch('apns2.client.APNsClient')
|
||||||
def test_send(self, mock_client):
|
def test_send(self, mock_client):
|
||||||
|
@ -266,25 +263,25 @@ class TestApns(unittest.TestCase):
|
||||||
Mock(return_value=yaml_file)):
|
Mock(return_value=yaml_file)):
|
||||||
self._setup_notify()
|
self._setup_notify()
|
||||||
|
|
||||||
self.assertTrue(self.hass.services.call(
|
assert self.hass.services.call(
|
||||||
'notify', 'test_app',
|
'notify', 'test_app',
|
||||||
{'message': 'Hello', 'data': {
|
{'message': 'Hello', 'data': {
|
||||||
'badge': 1,
|
'badge': 1,
|
||||||
'sound': 'test.mp3',
|
'sound': 'test.mp3',
|
||||||
'category': 'testing'}},
|
'category': 'testing'}},
|
||||||
blocking=True))
|
blocking=True)
|
||||||
|
|
||||||
self.assertTrue(send.called)
|
assert send.called
|
||||||
self.assertEqual(1, len(send.mock_calls))
|
assert 1 == len(send.mock_calls)
|
||||||
|
|
||||||
target = send.mock_calls[0][1][0]
|
target = send.mock_calls[0][1][0]
|
||||||
payload = send.mock_calls[0][1][1]
|
payload = send.mock_calls[0][1][1]
|
||||||
|
|
||||||
self.assertEqual('1234', target)
|
assert '1234' == target
|
||||||
self.assertEqual('Hello', payload.alert)
|
assert 'Hello' == payload.alert
|
||||||
self.assertEqual(1, payload.badge)
|
assert 1 == payload.badge
|
||||||
self.assertEqual('test.mp3', payload.sound)
|
assert 'test.mp3' == payload.sound
|
||||||
self.assertEqual('testing', payload.category)
|
assert 'testing' == payload.category
|
||||||
|
|
||||||
@patch('apns2.client.APNsClient')
|
@patch('apns2.client.APNsClient')
|
||||||
def test_send_when_disabled(self, mock_client):
|
def test_send_when_disabled(self, mock_client):
|
||||||
|
@ -301,15 +298,15 @@ class TestApns(unittest.TestCase):
|
||||||
Mock(return_value=yaml_file)):
|
Mock(return_value=yaml_file)):
|
||||||
self._setup_notify()
|
self._setup_notify()
|
||||||
|
|
||||||
self.assertTrue(self.hass.services.call(
|
assert self.hass.services.call(
|
||||||
'notify', 'test_app',
|
'notify', 'test_app',
|
||||||
{'message': 'Hello', 'data': {
|
{'message': 'Hello', 'data': {
|
||||||
'badge': 1,
|
'badge': 1,
|
||||||
'sound': 'test.mp3',
|
'sound': 'test.mp3',
|
||||||
'category': 'testing'}},
|
'category': 'testing'}},
|
||||||
blocking=True))
|
blocking=True)
|
||||||
|
|
||||||
self.assertFalse(send.called)
|
assert not send.called
|
||||||
|
|
||||||
@patch('apns2.client.APNsClient')
|
@patch('apns2.client.APNsClient')
|
||||||
def test_send_with_state(self, mock_client):
|
def test_send_with_state(self, mock_client):
|
||||||
|
@ -346,14 +343,14 @@ class TestApns(unittest.TestCase):
|
||||||
|
|
||||||
notify_service.send_message(message='Hello', target='home')
|
notify_service.send_message(message='Hello', target='home')
|
||||||
|
|
||||||
self.assertTrue(send.called)
|
assert send.called
|
||||||
self.assertEqual(1, len(send.mock_calls))
|
assert 1 == len(send.mock_calls)
|
||||||
|
|
||||||
target = send.mock_calls[0][1][0]
|
target = send.mock_calls[0][1][0]
|
||||||
payload = send.mock_calls[0][1][1]
|
payload = send.mock_calls[0][1][1]
|
||||||
|
|
||||||
self.assertEqual('5678', target)
|
assert '5678' == target
|
||||||
self.assertEqual('Hello', payload.alert)
|
assert 'Hello' == payload.alert
|
||||||
|
|
||||||
@patch('apns2.client.APNsClient')
|
@patch('apns2.client.APNsClient')
|
||||||
@patch('homeassistant.components.notify.apns._write_device')
|
@patch('homeassistant.components.notify.apns._write_device')
|
||||||
|
@ -386,15 +383,15 @@ class TestApns(unittest.TestCase):
|
||||||
Mock(return_value=yaml_file)):
|
Mock(return_value=yaml_file)):
|
||||||
self._setup_notify()
|
self._setup_notify()
|
||||||
|
|
||||||
self.assertTrue(self.hass.services.call('notify', 'test_app',
|
assert self.hass.services.call('notify', 'test_app',
|
||||||
{'message': 'Hello'},
|
{'message': 'Hello'},
|
||||||
blocking=True))
|
blocking=True)
|
||||||
|
|
||||||
devices = {dev.push_id: dev for dev in written_devices}
|
devices = {dev.push_id: dev for dev in written_devices}
|
||||||
|
|
||||||
test_device_1 = devices.get('1234')
|
test_device_1 = devices.get('1234')
|
||||||
self.assertIsNotNone(test_device_1)
|
assert test_device_1 is not None
|
||||||
self.assertEqual(True, test_device_1.disabled)
|
assert test_device_1.disabled is True
|
||||||
|
|
||||||
|
|
||||||
def test_write_device():
|
def test_write_device():
|
||||||
|
|
|
@ -49,39 +49,35 @@ class TestCommandLine(unittest.TestCase):
|
||||||
filename = os.path.join(tempdirname, 'message.txt')
|
filename = os.path.join(tempdirname, 'message.txt')
|
||||||
message = 'one, two, testing, testing'
|
message = 'one, two, testing, testing'
|
||||||
with assert_setup_component(1) as handle_config:
|
with assert_setup_component(1) as handle_config:
|
||||||
self.assertTrue(setup_component(self.hass, notify.DOMAIN, {
|
assert setup_component(self.hass, notify.DOMAIN, {
|
||||||
'notify': {
|
'notify': {
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'platform': 'command_line',
|
'platform': 'command_line',
|
||||||
'command': 'echo $(cat) > {}'.format(filename)
|
'command': 'echo $(cat) > {}'.format(filename)
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
assert handle_config[notify.DOMAIN]
|
assert handle_config[notify.DOMAIN]
|
||||||
|
|
||||||
self.assertTrue(
|
assert self.hass.services.call(
|
||||||
self.hass.services.call('notify', 'test', {'message': message},
|
'notify', 'test', {'message': message}, blocking=True)
|
||||||
blocking=True)
|
|
||||||
)
|
|
||||||
|
|
||||||
with open(filename) as fil:
|
with open(filename) as fil:
|
||||||
# the echo command adds a line break
|
# the echo command adds a line break
|
||||||
self.assertEqual(fil.read(), "{}\n".format(message))
|
assert fil.read() == "{}\n".format(message)
|
||||||
|
|
||||||
@patch('homeassistant.components.notify.command_line._LOGGER.error')
|
@patch('homeassistant.components.notify.command_line._LOGGER.error')
|
||||||
def test_error_for_none_zero_exit_code(self, mock_error):
|
def test_error_for_none_zero_exit_code(self, mock_error):
|
||||||
"""Test if an error is logged for non zero exit codes."""
|
"""Test if an error is logged for non zero exit codes."""
|
||||||
with assert_setup_component(1) as handle_config:
|
with assert_setup_component(1) as handle_config:
|
||||||
self.assertTrue(setup_component(self.hass, notify.DOMAIN, {
|
assert setup_component(self.hass, notify.DOMAIN, {
|
||||||
'notify': {
|
'notify': {
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'platform': 'command_line',
|
'platform': 'command_line',
|
||||||
'command': 'echo $(cat); exit 1'
|
'command': 'echo $(cat); exit 1'
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
assert handle_config[notify.DOMAIN]
|
assert handle_config[notify.DOMAIN]
|
||||||
|
|
||||||
self.assertTrue(
|
assert self.hass.services.call('notify', 'test', {'message': 'error'},
|
||||||
self.hass.services.call('notify', 'test', {'message': 'error'},
|
blocking=True)
|
||||||
blocking=True)
|
assert 1 == mock_error.call_count
|
||||||
)
|
|
||||||
self.assertEqual(1, mock_error.call_count)
|
|
||||||
|
|
|
@ -56,10 +56,9 @@ class TestNotifyDemo(unittest.TestCase):
|
||||||
self._setup_notify()
|
self._setup_notify()
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
assert mock_demo_get_service.called
|
assert mock_demo_get_service.called
|
||||||
self.assertEqual(
|
assert log_handle.output == \
|
||||||
log_handle.output,
|
|
||||||
['ERROR:homeassistant.components.notify:'
|
['ERROR:homeassistant.components.notify:'
|
||||||
'Failed to initialize notification service demo'])
|
'Failed to initialize notification service demo']
|
||||||
|
|
||||||
@patch('homeassistant.components.notify.demo.get_service', autospec=True)
|
@patch('homeassistant.components.notify.demo.get_service', autospec=True)
|
||||||
def test_discover_notify(self, mock_demo_get_service):
|
def test_discover_notify(self, mock_demo_get_service):
|
||||||
|
@ -83,7 +82,7 @@ class TestNotifyDemo(unittest.TestCase):
|
||||||
self._setup_notify()
|
self._setup_notify()
|
||||||
common.send_message(self.hass, None)
|
common.send_message(self.hass, None)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(len(self.events) == 0)
|
assert len(self.events) == 0
|
||||||
|
|
||||||
def test_sending_templated_message(self):
|
def test_sending_templated_message(self):
|
||||||
"""Send a templated message."""
|
"""Send a templated message."""
|
||||||
|
@ -93,8 +92,8 @@ class TestNotifyDemo(unittest.TestCase):
|
||||||
'{{ states.sensor.temperature.name }}')
|
'{{ states.sensor.temperature.name }}')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
last_event = self.events[-1]
|
last_event = self.events[-1]
|
||||||
self.assertEqual(last_event.data[notify.ATTR_TITLE], 'temperature')
|
assert last_event.data[notify.ATTR_TITLE] == 'temperature'
|
||||||
self.assertEqual(last_event.data[notify.ATTR_MESSAGE], '10')
|
assert last_event.data[notify.ATTR_MESSAGE] == '10'
|
||||||
|
|
||||||
def test_method_forwards_correct_data(self):
|
def test_method_forwards_correct_data(self):
|
||||||
"""Test that all data from the service gets forwarded to service."""
|
"""Test that all data from the service gets forwarded to service."""
|
||||||
|
@ -102,7 +101,7 @@ class TestNotifyDemo(unittest.TestCase):
|
||||||
common.send_message(self.hass, 'my message', 'my title',
|
common.send_message(self.hass, 'my message', 'my title',
|
||||||
{'hello': 'world'})
|
{'hello': 'world'})
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(len(self.events) == 1)
|
assert len(self.events) == 1
|
||||||
data = self.events[0].data
|
data = self.events[0].data
|
||||||
assert {
|
assert {
|
||||||
'message': 'my message',
|
'message': 'my message',
|
||||||
|
@ -128,7 +127,7 @@ class TestNotifyDemo(unittest.TestCase):
|
||||||
|
|
||||||
script.call_from_config(self.hass, conf)
|
script.call_from_config(self.hass, conf)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(len(self.events) == 1)
|
assert len(self.events) == 1
|
||||||
assert {
|
assert {
|
||||||
'message': 'Test 123 4',
|
'message': 'Test 123 4',
|
||||||
'data': {
|
'data': {
|
||||||
|
@ -158,7 +157,7 @@ class TestNotifyDemo(unittest.TestCase):
|
||||||
|
|
||||||
script.call_from_config(self.hass, conf)
|
script.call_from_config(self.hass, conf)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(len(self.events) == 1)
|
assert len(self.events) == 1
|
||||||
assert {
|
assert {
|
||||||
'message': 'Test 123 4',
|
'message': 'Test 123 4',
|
||||||
'title': 'Test',
|
'title': 'Test',
|
||||||
|
@ -171,9 +170,9 @@ class TestNotifyDemo(unittest.TestCase):
|
||||||
def test_targets_are_services(self):
|
def test_targets_are_services(self):
|
||||||
"""Test that all targets are exposed as individual services."""
|
"""Test that all targets are exposed as individual services."""
|
||||||
self._setup_notify()
|
self._setup_notify()
|
||||||
self.assertIsNotNone(self.hass.services.has_service("notify", "demo"))
|
assert self.hass.services.has_service("notify", "demo") is not None
|
||||||
service = "demo_test_target_name"
|
service = "demo_test_target_name"
|
||||||
self.assertIsNotNone(self.hass.services.has_service("notify", service))
|
assert self.hass.services.has_service("notify", service) is not None
|
||||||
|
|
||||||
def test_messages_to_targets_route(self):
|
def test_messages_to_targets_route(self):
|
||||||
"""Test message routing to specific target services."""
|
"""Test message routing to specific target services."""
|
||||||
|
|
|
@ -26,17 +26,17 @@ class TestFacebook(unittest.TestCase):
|
||||||
target = ["+15555551234"]
|
target = ["+15555551234"]
|
||||||
|
|
||||||
self.facebook.send_message(message=message, target=target)
|
self.facebook.send_message(message=message, target=target)
|
||||||
self.assertTrue(mock.called)
|
assert mock.called
|
||||||
self.assertEqual(mock.call_count, 1)
|
assert mock.call_count == 1
|
||||||
|
|
||||||
expected_body = {
|
expected_body = {
|
||||||
"recipient": {"phone_number": target[0]},
|
"recipient": {"phone_number": target[0]},
|
||||||
"message": {"text": message}
|
"message": {"text": message}
|
||||||
}
|
}
|
||||||
self.assertEqual(mock.last_request.json(), expected_body)
|
assert mock.last_request.json() == expected_body
|
||||||
|
|
||||||
expected_params = {"access_token": ["page-access-token"]}
|
expected_params = {"access_token": ["page-access-token"]}
|
||||||
self.assertEqual(mock.last_request.qs, expected_params)
|
assert mock.last_request.qs == expected_params
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_sending_multiple_messages(self, mock):
|
def test_sending_multiple_messages(self, mock):
|
||||||
|
@ -51,8 +51,8 @@ class TestFacebook(unittest.TestCase):
|
||||||
targets = ["+15555551234", "+15555551235"]
|
targets = ["+15555551234", "+15555551235"]
|
||||||
|
|
||||||
self.facebook.send_message(message=message, target=targets)
|
self.facebook.send_message(message=message, target=targets)
|
||||||
self.assertTrue(mock.called)
|
assert mock.called
|
||||||
self.assertEqual(mock.call_count, 2)
|
assert mock.call_count == 2
|
||||||
|
|
||||||
for idx, target in enumerate(targets):
|
for idx, target in enumerate(targets):
|
||||||
request = mock.request_history[idx]
|
request = mock.request_history[idx]
|
||||||
|
@ -60,10 +60,10 @@ class TestFacebook(unittest.TestCase):
|
||||||
"recipient": {"phone_number": target},
|
"recipient": {"phone_number": target},
|
||||||
"message": {"text": message}
|
"message": {"text": message}
|
||||||
}
|
}
|
||||||
self.assertEqual(request.json(), expected_body)
|
assert request.json() == expected_body
|
||||||
|
|
||||||
expected_params = {"access_token": ["page-access-token"]}
|
expected_params = {"access_token": ["page-access-token"]}
|
||||||
self.assertEqual(request.qs, expected_params)
|
assert request.qs == expected_params
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_send_message_attachment(self, mock):
|
def test_send_message_attachment(self, mock):
|
||||||
|
@ -84,17 +84,17 @@ class TestFacebook(unittest.TestCase):
|
||||||
target = ["+15555551234"]
|
target = ["+15555551234"]
|
||||||
|
|
||||||
self.facebook.send_message(message=message, data=data, target=target)
|
self.facebook.send_message(message=message, data=data, target=target)
|
||||||
self.assertTrue(mock.called)
|
assert mock.called
|
||||||
self.assertEqual(mock.call_count, 1)
|
assert mock.call_count == 1
|
||||||
|
|
||||||
expected_body = {
|
expected_body = {
|
||||||
"recipient": {"phone_number": target[0]},
|
"recipient": {"phone_number": target[0]},
|
||||||
"message": data
|
"message": data
|
||||||
}
|
}
|
||||||
self.assertEqual(mock.last_request.json(), expected_body)
|
assert mock.last_request.json() == expected_body
|
||||||
|
|
||||||
expected_params = {"access_token": ["page-access-token"]}
|
expected_params = {"access_token": ["page-access-token"]}
|
||||||
self.assertEqual(mock.last_request.qs, expected_params)
|
assert mock.last_request.qs == expected_params
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_send_targetless_message(self, mock):
|
def test_send_targetless_message(self, mock):
|
||||||
|
@ -106,7 +106,7 @@ class TestFacebook(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
self.facebook.send_message(message="goin nowhere")
|
self.facebook.send_message(message="goin nowhere")
|
||||||
self.assertFalse(mock.called)
|
assert not mock.called
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_send_message_with_400(self, mock):
|
def test_send_message_with_400(self, mock):
|
||||||
|
@ -125,5 +125,5 @@ class TestFacebook(unittest.TestCase):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.facebook.send_message(message="nope!", target=["+15555551234"])
|
self.facebook.send_message(message="nope!", target=["+15555551234"])
|
||||||
self.assertTrue(mock.called)
|
assert mock.called
|
||||||
self.assertEqual(mock.call_count, 1)
|
assert mock.call_count == 1
|
||||||
|
|
|
@ -40,14 +40,14 @@ class TestNotifyFile(unittest.TestCase):
|
||||||
filename = 'mock_file'
|
filename = 'mock_file'
|
||||||
message = 'one, two, testing, testing'
|
message = 'one, two, testing, testing'
|
||||||
with assert_setup_component(1) as handle_config:
|
with assert_setup_component(1) as handle_config:
|
||||||
self.assertTrue(setup_component(self.hass, notify.DOMAIN, {
|
assert setup_component(self.hass, notify.DOMAIN, {
|
||||||
'notify': {
|
'notify': {
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'platform': 'file',
|
'platform': 'file',
|
||||||
'filename': filename,
|
'filename': filename,
|
||||||
'timestamp': timestamp,
|
'timestamp': timestamp,
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
assert handle_config[notify.DOMAIN]
|
assert handle_config[notify.DOMAIN]
|
||||||
|
|
||||||
m_open = mock_open()
|
m_open = mock_open()
|
||||||
|
@ -68,21 +68,17 @@ class TestNotifyFile(unittest.TestCase):
|
||||||
blocking=True)
|
blocking=True)
|
||||||
|
|
||||||
full_filename = os.path.join(self.hass.config.path(), filename)
|
full_filename = os.path.join(self.hass.config.path(), filename)
|
||||||
self.assertEqual(m_open.call_count, 1)
|
assert m_open.call_count == 1
|
||||||
self.assertEqual(m_open.call_args, call(full_filename, 'a'))
|
assert m_open.call_args == call(full_filename, 'a')
|
||||||
|
|
||||||
self.assertEqual(m_open.return_value.write.call_count, 2)
|
assert m_open.return_value.write.call_count == 2
|
||||||
if not timestamp:
|
if not timestamp:
|
||||||
self.assertEqual(
|
assert m_open.return_value.write.call_args_list == \
|
||||||
m_open.return_value.write.call_args_list,
|
|
||||||
[call(title), call('{}\n'.format(message))]
|
[call(title), call('{}\n'.format(message))]
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
self.assertEqual(
|
assert m_open.return_value.write.call_args_list == \
|
||||||
m_open.return_value.write.call_args_list,
|
|
||||||
[call(title), call('{} {}\n'.format(
|
[call(title), call('{} {}\n'.format(
|
||||||
dt_util.utcnow().isoformat(), message))]
|
dt_util.utcnow().isoformat(), message))]
|
||||||
)
|
|
||||||
|
|
||||||
def test_notify_file(self):
|
def test_notify_file(self):
|
||||||
"""Test the notify file output without timestamp."""
|
"""Test the notify file output without timestamp."""
|
||||||
|
|
|
@ -68,13 +68,13 @@ class TestPushBullet(unittest.TestCase):
|
||||||
'message': 'Test Message'}
|
'message': 'Test Message'}
|
||||||
self.hass.services.call(notify.DOMAIN, 'test', data)
|
self.hass.services.call(notify.DOMAIN, 'test', data)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(mock.called)
|
assert mock.called
|
||||||
self.assertEqual(mock.call_count, 1)
|
assert mock.call_count == 1
|
||||||
|
|
||||||
expected_body = {'body': 'Test Message',
|
expected_body = {'body': 'Test Message',
|
||||||
'title': 'Test Title',
|
'title': 'Test Title',
|
||||||
'type': 'note'}
|
'type': 'note'}
|
||||||
self.assertEqual(mock.last_request.json(), expected_body)
|
assert mock.last_request.json() == expected_body
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
@patch.object(PushBullet, '_get_data',
|
@patch.object(PushBullet, '_get_data',
|
||||||
|
@ -99,14 +99,14 @@ class TestPushBullet(unittest.TestCase):
|
||||||
'target': ['device/DESKTOP']}
|
'target': ['device/DESKTOP']}
|
||||||
self.hass.services.call(notify.DOMAIN, 'test', data)
|
self.hass.services.call(notify.DOMAIN, 'test', data)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(mock.called)
|
assert mock.called
|
||||||
self.assertEqual(mock.call_count, 1)
|
assert mock.call_count == 1
|
||||||
|
|
||||||
expected_body = {'body': 'Test Message',
|
expected_body = {'body': 'Test Message',
|
||||||
'device_iden': 'identity1',
|
'device_iden': 'identity1',
|
||||||
'title': 'Test Title',
|
'title': 'Test Title',
|
||||||
'type': 'note'}
|
'type': 'note'}
|
||||||
self.assertEqual(mock.last_request.json(), expected_body)
|
assert mock.last_request.json() == expected_body
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
@patch.object(PushBullet, '_get_data',
|
@patch.object(PushBullet, '_get_data',
|
||||||
|
@ -131,20 +131,20 @@ class TestPushBullet(unittest.TestCase):
|
||||||
'target': ['device/DESKTOP', 'device/My iPhone']}
|
'target': ['device/DESKTOP', 'device/My iPhone']}
|
||||||
self.hass.services.call(notify.DOMAIN, 'test', data)
|
self.hass.services.call(notify.DOMAIN, 'test', data)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(mock.called)
|
assert mock.called
|
||||||
self.assertEqual(mock.call_count, 2)
|
assert mock.call_count == 2
|
||||||
self.assertEqual(len(mock.request_history), 2)
|
assert len(mock.request_history) == 2
|
||||||
|
|
||||||
expected_body = {'body': 'Test Message',
|
expected_body = {'body': 'Test Message',
|
||||||
'device_iden': 'identity1',
|
'device_iden': 'identity1',
|
||||||
'title': 'Test Title',
|
'title': 'Test Title',
|
||||||
'type': 'note'}
|
'type': 'note'}
|
||||||
self.assertEqual(mock.request_history[0].json(), expected_body)
|
assert mock.request_history[0].json() == expected_body
|
||||||
expected_body = {'body': 'Test Message',
|
expected_body = {'body': 'Test Message',
|
||||||
'device_iden': 'identity2',
|
'device_iden': 'identity2',
|
||||||
'title': 'Test Title',
|
'title': 'Test Title',
|
||||||
'type': 'note'}
|
'type': 'note'}
|
||||||
self.assertEqual(mock.request_history[1].json(), expected_body)
|
assert mock.request_history[1].json() == expected_body
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
@patch.object(PushBullet, '_get_data',
|
@patch.object(PushBullet, '_get_data',
|
||||||
|
@ -169,15 +169,15 @@ class TestPushBullet(unittest.TestCase):
|
||||||
'target': ['email/user@host.net']}
|
'target': ['email/user@host.net']}
|
||||||
self.hass.services.call(notify.DOMAIN, 'test', data)
|
self.hass.services.call(notify.DOMAIN, 'test', data)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(mock.called)
|
assert mock.called
|
||||||
self.assertEqual(mock.call_count, 1)
|
assert mock.call_count == 1
|
||||||
self.assertEqual(len(mock.request_history), 1)
|
assert len(mock.request_history) == 1
|
||||||
|
|
||||||
expected_body = {'body': 'Test Message',
|
expected_body = {'body': 'Test Message',
|
||||||
'email': 'user@host.net',
|
'email': 'user@host.net',
|
||||||
'title': 'Test Title',
|
'title': 'Test Title',
|
||||||
'type': 'note'}
|
'type': 'note'}
|
||||||
self.assertEqual(mock.request_history[0].json(), expected_body)
|
assert mock.request_history[0].json() == expected_body
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
@patch.object(PushBullet, '_get_data',
|
@patch.object(PushBullet, '_get_data',
|
||||||
|
@ -202,20 +202,20 @@ class TestPushBullet(unittest.TestCase):
|
||||||
'target': ['device/DESKTOP', 'email/user@host.net']}
|
'target': ['device/DESKTOP', 'email/user@host.net']}
|
||||||
self.hass.services.call(notify.DOMAIN, 'test', data)
|
self.hass.services.call(notify.DOMAIN, 'test', data)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertTrue(mock.called)
|
assert mock.called
|
||||||
self.assertEqual(mock.call_count, 2)
|
assert mock.call_count == 2
|
||||||
self.assertEqual(len(mock.request_history), 2)
|
assert len(mock.request_history) == 2
|
||||||
|
|
||||||
expected_body = {'body': 'Test Message',
|
expected_body = {'body': 'Test Message',
|
||||||
'device_iden': 'identity1',
|
'device_iden': 'identity1',
|
||||||
'title': 'Test Title',
|
'title': 'Test Title',
|
||||||
'type': 'note'}
|
'type': 'note'}
|
||||||
self.assertEqual(mock.request_history[0].json(), expected_body)
|
assert mock.request_history[0].json() == expected_body
|
||||||
expected_body = {'body': 'Test Message',
|
expected_body = {'body': 'Test Message',
|
||||||
'email': 'user@host.net',
|
'email': 'user@host.net',
|
||||||
'title': 'Test Title',
|
'title': 'Test Title',
|
||||||
'type': 'note'}
|
'type': 'note'}
|
||||||
self.assertEqual(mock.request_history[1].json(), expected_body)
|
assert mock.request_history[1].json() == expected_body
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
@patch.object(PushBullet, '_get_data',
|
@patch.object(PushBullet, '_get_data',
|
||||||
|
|
|
@ -5,6 +5,7 @@ from unittest.mock import patch
|
||||||
from homeassistant.components.notify import smtp
|
from homeassistant.components.notify import smtp
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant
|
from tests.common import get_test_home_assistant
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
class MockSMTP(smtp.MailNotificationService):
|
class MockSMTP(smtp.MailNotificationService):
|
||||||
|
@ -45,14 +46,14 @@ class TestNotifySmtp(unittest.TestCase):
|
||||||
'Message-Id: <[^@]+@[^>]+>\n'
|
'Message-Id: <[^@]+@[^>]+>\n'
|
||||||
'\n'
|
'\n'
|
||||||
'Test msg$')
|
'Test msg$')
|
||||||
self.assertRegex(msg, expected)
|
assert re.search(expected, msg)
|
||||||
|
|
||||||
@patch('email.utils.make_msgid', return_value='<mock@mock>')
|
@patch('email.utils.make_msgid', return_value='<mock@mock>')
|
||||||
def test_mixed_email(self, mock_make_msgid):
|
def test_mixed_email(self, mock_make_msgid):
|
||||||
"""Test build of mixed text email behavior."""
|
"""Test build of mixed text email behavior."""
|
||||||
msg = self.mailer.send_message('Test msg',
|
msg = self.mailer.send_message('Test msg',
|
||||||
data={'images': ['test.jpg']})
|
data={'images': ['test.jpg']})
|
||||||
self.assertTrue('Content-Type: multipart/related' in msg)
|
assert 'Content-Type: multipart/related' in msg
|
||||||
|
|
||||||
@patch('email.utils.make_msgid', return_value='<mock@mock>')
|
@patch('email.utils.make_msgid', return_value='<mock@mock>')
|
||||||
def test_html_email(self, mock_make_msgid):
|
def test_html_email(self, mock_make_msgid):
|
||||||
|
@ -73,4 +74,4 @@ class TestNotifySmtp(unittest.TestCase):
|
||||||
msg = self.mailer.send_message('Test msg',
|
msg = self.mailer.send_message('Test msg',
|
||||||
data={'html': html,
|
data={'html': html,
|
||||||
'images': ['test.jpg']})
|
'images': ['test.jpg']})
|
||||||
self.assertTrue('Content-Type: multipart/related' in msg)
|
assert 'Content-Type: multipart/related' in msg
|
||||||
|
|
|
@ -124,13 +124,13 @@ class TestRecorderPurge(unittest.TestCase):
|
||||||
# make sure we start with 7 states
|
# make sure we start with 7 states
|
||||||
with session_scope(hass=self.hass) as session:
|
with session_scope(hass=self.hass) as session:
|
||||||
states = session.query(States)
|
states = session.query(States)
|
||||||
self.assertEqual(states.count(), 7)
|
assert states.count() == 7
|
||||||
|
|
||||||
# run purge_old_data()
|
# run purge_old_data()
|
||||||
purge_old_data(self.hass.data[DATA_INSTANCE], 4, repack=False)
|
purge_old_data(self.hass.data[DATA_INSTANCE], 4, repack=False)
|
||||||
|
|
||||||
# we should only have 3 states left after purging
|
# we should only have 3 states left after purging
|
||||||
self.assertEqual(states.count(), 3)
|
assert states.count() == 3
|
||||||
|
|
||||||
def test_purge_old_events(self):
|
def test_purge_old_events(self):
|
||||||
"""Test deleting old events."""
|
"""Test deleting old events."""
|
||||||
|
@ -139,13 +139,13 @@ class TestRecorderPurge(unittest.TestCase):
|
||||||
with session_scope(hass=self.hass) as session:
|
with session_scope(hass=self.hass) as session:
|
||||||
events = session.query(Events).filter(
|
events = session.query(Events).filter(
|
||||||
Events.event_type.like("EVENT_TEST%"))
|
Events.event_type.like("EVENT_TEST%"))
|
||||||
self.assertEqual(events.count(), 7)
|
assert events.count() == 7
|
||||||
|
|
||||||
# run purge_old_data()
|
# run purge_old_data()
|
||||||
purge_old_data(self.hass.data[DATA_INSTANCE], 4, repack=False)
|
purge_old_data(self.hass.data[DATA_INSTANCE], 4, repack=False)
|
||||||
|
|
||||||
# no state to protect, now we should only have 2 events left
|
# no state to protect, now we should only have 2 events left
|
||||||
self.assertEqual(events.count(), 2)
|
assert events.count() == 2
|
||||||
|
|
||||||
def test_purge_method(self):
|
def test_purge_method(self):
|
||||||
"""Test purge method."""
|
"""Test purge method."""
|
||||||
|
@ -156,11 +156,11 @@ class TestRecorderPurge(unittest.TestCase):
|
||||||
# make sure we start with 6 states
|
# make sure we start with 6 states
|
||||||
with session_scope(hass=self.hass) as session:
|
with session_scope(hass=self.hass) as session:
|
||||||
states = session.query(States)
|
states = session.query(States)
|
||||||
self.assertEqual(states.count(), 7)
|
assert states.count() == 7
|
||||||
|
|
||||||
events = session.query(Events).filter(
|
events = session.query(Events).filter(
|
||||||
Events.event_type.like("EVENT_TEST%"))
|
Events.event_type.like("EVENT_TEST%"))
|
||||||
self.assertEqual(events.count(), 7)
|
assert events.count() == 7
|
||||||
|
|
||||||
self.hass.data[DATA_INSTANCE].block_till_done()
|
self.hass.data[DATA_INSTANCE].block_till_done()
|
||||||
|
|
||||||
|
@ -172,8 +172,8 @@ class TestRecorderPurge(unittest.TestCase):
|
||||||
self.hass.data[DATA_INSTANCE].block_till_done()
|
self.hass.data[DATA_INSTANCE].block_till_done()
|
||||||
|
|
||||||
# only purged old events
|
# only purged old events
|
||||||
self.assertEqual(states.count(), 5)
|
assert states.count() == 5
|
||||||
self.assertEqual(events.count(), 5)
|
assert events.count() == 5
|
||||||
|
|
||||||
# run purge method - correct service data
|
# run purge method - correct service data
|
||||||
self.hass.services.call('recorder', 'purge',
|
self.hass.services.call('recorder', 'purge',
|
||||||
|
@ -184,19 +184,19 @@ class TestRecorderPurge(unittest.TestCase):
|
||||||
self.hass.data[DATA_INSTANCE].block_till_done()
|
self.hass.data[DATA_INSTANCE].block_till_done()
|
||||||
|
|
||||||
# we should only have 3 states left after purging
|
# we should only have 3 states left after purging
|
||||||
self.assertEqual(states.count(), 3)
|
assert states.count() == 3
|
||||||
|
|
||||||
# the protected state is among them
|
# the protected state is among them
|
||||||
self.assertTrue('iamprotected' in (
|
assert 'iamprotected' in (
|
||||||
state.state for state in states))
|
state.state for state in states)
|
||||||
|
|
||||||
# now we should only have 3 events left
|
# now we should only have 3 events left
|
||||||
self.assertEqual(events.count(), 3)
|
assert events.count() == 3
|
||||||
|
|
||||||
# and the protected event is among them
|
# and the protected event is among them
|
||||||
self.assertTrue('EVENT_TEST_FOR_PROTECTED' in (
|
assert 'EVENT_TEST_FOR_PROTECTED' in (
|
||||||
event.event_type for event in events.all()))
|
event.event_type for event in events.all())
|
||||||
self.assertFalse('EVENT_TEST_PURGE' in (
|
assert not ('EVENT_TEST_PURGE' in (
|
||||||
event.event_type for event in events.all()))
|
event.event_type for event in events.all()))
|
||||||
|
|
||||||
# run purge method - correct service data, with repack
|
# run purge method - correct service data, with repack
|
||||||
|
@ -207,5 +207,5 @@ class TestRecorderPurge(unittest.TestCase):
|
||||||
service_data=service_data)
|
service_data=service_data)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.hass.data[DATA_INSTANCE].block_till_done()
|
self.hass.data[DATA_INSTANCE].block_till_done()
|
||||||
self.assertEqual(mock_logger.debug.mock_calls[4][1][0],
|
assert mock_logger.debug.mock_calls[4][1][0] == \
|
||||||
"Vacuuming SQLite to free space")
|
"Vacuuming SQLite to free space"
|
||||||
|
|
|
@ -19,9 +19,9 @@ class TestDemoRemote(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Set up things to be run when tests are started."""
|
"""Set up things to be run when tests are started."""
|
||||||
self.hass = get_test_home_assistant()
|
self.hass = get_test_home_assistant()
|
||||||
self.assertTrue(setup_component(self.hass, remote.DOMAIN, {'remote': {
|
assert setup_component(self.hass, remote.DOMAIN, {'remote': {
|
||||||
'platform': 'demo',
|
'platform': 'demo',
|
||||||
}}))
|
}})
|
||||||
|
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
@ -33,21 +33,20 @@ class TestDemoRemote(unittest.TestCase):
|
||||||
common.turn_on(self.hass, entity_id=ENTITY_ID)
|
common.turn_on(self.hass, entity_id=ENTITY_ID)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_ID)
|
state = self.hass.states.get(ENTITY_ID)
|
||||||
self.assertEqual(state.state, STATE_ON)
|
assert state.state == STATE_ON
|
||||||
|
|
||||||
common.turn_off(self.hass, entity_id=ENTITY_ID)
|
common.turn_off(self.hass, entity_id=ENTITY_ID)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_ID)
|
state = self.hass.states.get(ENTITY_ID)
|
||||||
self.assertEqual(state.state, STATE_OFF)
|
assert state.state == STATE_OFF
|
||||||
|
|
||||||
common.turn_on(self.hass, entity_id=ENTITY_ID)
|
common.turn_on(self.hass, entity_id=ENTITY_ID)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_ID)
|
state = self.hass.states.get(ENTITY_ID)
|
||||||
self.assertEqual(state.state, STATE_ON)
|
assert state.state == STATE_ON
|
||||||
|
|
||||||
common.send_command(self.hass, 'test', entity_id=ENTITY_ID)
|
common.send_command(self.hass, 'test', entity_id=ENTITY_ID)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
state = self.hass.states.get(ENTITY_ID)
|
state = self.hass.states.get(ENTITY_ID)
|
||||||
self.assertEqual(
|
assert state.attributes == \
|
||||||
state.attributes,
|
{'friendly_name': 'Remote One', 'last_command_sent': 'test'}
|
||||||
{'friendly_name': 'Remote One', 'last_command_sent': 'test'})
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from homeassistant.setup import setup_component
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID, STATE_ON, STATE_OFF, CONF_PLATFORM,
|
ATTR_ENTITY_ID, STATE_ON, STATE_OFF, CONF_PLATFORM,
|
||||||
SERVICE_TURN_ON, SERVICE_TURN_OFF)
|
SERVICE_TURN_ON, SERVICE_TURN_OFF)
|
||||||
|
@ -32,16 +31,16 @@ class TestRemote(unittest.TestCase):
|
||||||
def test_is_on(self):
|
def test_is_on(self):
|
||||||
"""Test is_on."""
|
"""Test is_on."""
|
||||||
self.hass.states.set('remote.test', STATE_ON)
|
self.hass.states.set('remote.test', STATE_ON)
|
||||||
self.assertTrue(remote.is_on(self.hass, 'remote.test'))
|
assert remote.is_on(self.hass, 'remote.test')
|
||||||
|
|
||||||
self.hass.states.set('remote.test', STATE_OFF)
|
self.hass.states.set('remote.test', STATE_OFF)
|
||||||
self.assertFalse(remote.is_on(self.hass, 'remote.test'))
|
assert not remote.is_on(self.hass, 'remote.test')
|
||||||
|
|
||||||
self.hass.states.set(remote.ENTITY_ID_ALL_REMOTES, STATE_ON)
|
self.hass.states.set(remote.ENTITY_ID_ALL_REMOTES, STATE_ON)
|
||||||
self.assertTrue(remote.is_on(self.hass))
|
assert remote.is_on(self.hass)
|
||||||
|
|
||||||
self.hass.states.set(remote.ENTITY_ID_ALL_REMOTES, STATE_OFF)
|
self.hass.states.set(remote.ENTITY_ID_ALL_REMOTES, STATE_OFF)
|
||||||
self.assertFalse(remote.is_on(self.hass))
|
assert not remote.is_on(self.hass)
|
||||||
|
|
||||||
def test_turn_on(self):
|
def test_turn_on(self):
|
||||||
"""Test turn_on."""
|
"""Test turn_on."""
|
||||||
|
@ -54,10 +53,10 @@ class TestRemote(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(turn_on_calls))
|
assert 1 == len(turn_on_calls)
|
||||||
call = turn_on_calls[-1]
|
call = turn_on_calls[-1]
|
||||||
|
|
||||||
self.assertEqual(remote.DOMAIN, call.domain)
|
assert remote.DOMAIN == call.domain
|
||||||
|
|
||||||
def test_turn_off(self):
|
def test_turn_off(self):
|
||||||
"""Test turn_off."""
|
"""Test turn_off."""
|
||||||
|
@ -69,12 +68,12 @@ class TestRemote(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(turn_off_calls))
|
assert 1 == len(turn_off_calls)
|
||||||
call = turn_off_calls[-1]
|
call = turn_off_calls[-1]
|
||||||
|
|
||||||
self.assertEqual(remote.DOMAIN, call.domain)
|
assert remote.DOMAIN == call.domain
|
||||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
assert SERVICE_TURN_OFF == call.service
|
||||||
self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID])
|
assert 'entity_id_val' == call.data[ATTR_ENTITY_ID]
|
||||||
|
|
||||||
def test_send_command(self):
|
def test_send_command(self):
|
||||||
"""Test send_command."""
|
"""Test send_command."""
|
||||||
|
@ -88,14 +87,9 @@ class TestRemote(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(send_command_calls))
|
assert 1 == len(send_command_calls)
|
||||||
call = send_command_calls[-1]
|
call = send_command_calls[-1]
|
||||||
|
|
||||||
self.assertEqual(remote.DOMAIN, call.domain)
|
assert remote.DOMAIN == call.domain
|
||||||
self.assertEqual(SERVICE_SEND_COMMAND, call.service)
|
assert SERVICE_SEND_COMMAND == call.service
|
||||||
self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID])
|
assert 'entity_id_val' == call.data[ATTR_ENTITY_ID]
|
||||||
|
|
||||||
def test_services(self):
|
|
||||||
"""Test the provided services."""
|
|
||||||
self.assertTrue(setup_component(self.hass, remote.DOMAIN,
|
|
||||||
TEST_PLATFORM))
|
|
||||||
|
|
|
@ -21,9 +21,9 @@ class TestScene(unittest.TestCase):
|
||||||
test_light = loader.get_component(self.hass, 'light.test')
|
test_light = loader.get_component(self.hass, 'light.test')
|
||||||
test_light.init()
|
test_light.init()
|
||||||
|
|
||||||
self.assertTrue(setup_component(self.hass, light.DOMAIN, {
|
assert setup_component(self.hass, light.DOMAIN, {
|
||||||
light.DOMAIN: {'platform': 'test'}
|
light.DOMAIN: {'platform': 'test'}
|
||||||
}))
|
})
|
||||||
|
|
||||||
self.light_1, self.light_2 = test_light.DEVICES[0:2]
|
self.light_1, self.light_2 = test_light.DEVICES[0:2]
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ class TestScene(unittest.TestCase):
|
||||||
|
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertFalse(self.light_1.is_on)
|
assert not self.light_1.is_on
|
||||||
self.assertFalse(self.light_2.is_on)
|
assert not self.light_2.is_on
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
"""Stop everything that was started."""
|
"""Stop everything that was started."""
|
||||||
|
@ -60,7 +60,7 @@ class TestScene(unittest.TestCase):
|
||||||
'state': 'on',
|
'state': 'on',
|
||||||
'brightness': 100,
|
'brightness': 100,
|
||||||
}
|
}
|
||||||
self.assertTrue(setup_component(self.hass, scene.DOMAIN, {
|
assert setup_component(self.hass, scene.DOMAIN, {
|
||||||
'scene': [{
|
'scene': [{
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'entities': {
|
'entities': {
|
||||||
|
@ -68,17 +68,15 @@ class TestScene(unittest.TestCase):
|
||||||
self.light_2.entity_id: entity_state,
|
self.light_2.entity_id: entity_state,
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}))
|
})
|
||||||
|
|
||||||
common.activate(self.hass, 'scene.test')
|
common.activate(self.hass, 'scene.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertTrue(self.light_1.is_on)
|
assert self.light_1.is_on
|
||||||
self.assertTrue(self.light_2.is_on)
|
assert self.light_2.is_on
|
||||||
self.assertEqual(
|
assert 100 == self.light_1.last_call('turn_on')[1].get('brightness')
|
||||||
100, self.light_1.last_call('turn_on')[1].get('brightness'))
|
assert 100 == self.light_2.last_call('turn_on')[1].get('brightness')
|
||||||
self.assertEqual(
|
|
||||||
100, self.light_2.last_call('turn_on')[1].get('brightness'))
|
|
||||||
|
|
||||||
def test_config_yaml_bool(self):
|
def test_config_yaml_bool(self):
|
||||||
"""Test parsing of booleans in yaml config."""
|
"""Test parsing of booleans in yaml config."""
|
||||||
|
@ -95,18 +93,17 @@ class TestScene(unittest.TestCase):
|
||||||
with io.StringIO(config) as file:
|
with io.StringIO(config) as file:
|
||||||
doc = yaml.yaml.safe_load(file)
|
doc = yaml.yaml.safe_load(file)
|
||||||
|
|
||||||
self.assertTrue(setup_component(self.hass, scene.DOMAIN, doc))
|
assert setup_component(self.hass, scene.DOMAIN, doc)
|
||||||
common.activate(self.hass, 'scene.test')
|
common.activate(self.hass, 'scene.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertTrue(self.light_1.is_on)
|
assert self.light_1.is_on
|
||||||
self.assertTrue(self.light_2.is_on)
|
assert self.light_2.is_on
|
||||||
self.assertEqual(
|
assert 100 == self.light_2.last_call('turn_on')[1].get('brightness')
|
||||||
100, self.light_2.last_call('turn_on')[1].get('brightness'))
|
|
||||||
|
|
||||||
def test_activate_scene(self):
|
def test_activate_scene(self):
|
||||||
"""Test active scene."""
|
"""Test active scene."""
|
||||||
self.assertTrue(setup_component(self.hass, scene.DOMAIN, {
|
assert setup_component(self.hass, scene.DOMAIN, {
|
||||||
'scene': [{
|
'scene': [{
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'entities': {
|
'entities': {
|
||||||
|
@ -117,12 +114,11 @@ class TestScene(unittest.TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}))
|
})
|
||||||
|
|
||||||
common.activate(self.hass, 'scene.test')
|
common.activate(self.hass, 'scene.test')
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
self.assertTrue(self.light_1.is_on)
|
assert self.light_1.is_on
|
||||||
self.assertTrue(self.light_2.is_on)
|
assert self.light_2.is_on
|
||||||
self.assertEqual(
|
assert 100 == self.light_2.last_call('turn_on')[1].get('brightness')
|
||||||
100, self.light_2.last_call('turn_on')[1].get('brightness'))
|
|
||||||
|
|
|
@ -71,8 +71,8 @@ class TestBOMWeatherSensor(unittest.TestCase):
|
||||||
def test_setup(self, mock_get):
|
def test_setup(self, mock_get):
|
||||||
"""Test the setup with custom settings."""
|
"""Test the setup with custom settings."""
|
||||||
with assert_setup_component(1, sensor.DOMAIN):
|
with assert_setup_component(1, sensor.DOMAIN):
|
||||||
self.assertTrue(setup_component(self.hass, sensor.DOMAIN, {
|
assert setup_component(self.hass, sensor.DOMAIN, {
|
||||||
'sensor': VALID_CONFIG}))
|
'sensor': VALID_CONFIG})
|
||||||
|
|
||||||
fake_entities = [
|
fake_entities = [
|
||||||
'bom_fake_feels_like_c',
|
'bom_fake_feels_like_c',
|
||||||
|
@ -81,19 +81,19 @@ class TestBOMWeatherSensor(unittest.TestCase):
|
||||||
|
|
||||||
for entity_id in fake_entities:
|
for entity_id in fake_entities:
|
||||||
state = self.hass.states.get('sensor.{}'.format(entity_id))
|
state = self.hass.states.get('sensor.{}'.format(entity_id))
|
||||||
self.assertIsNotNone(state)
|
assert state is not None
|
||||||
|
|
||||||
@patch('requests.get', side_effect=mocked_requests)
|
@patch('requests.get', side_effect=mocked_requests)
|
||||||
def test_sensor_values(self, mock_get):
|
def test_sensor_values(self, mock_get):
|
||||||
"""Test retrieval of sensor values."""
|
"""Test retrieval of sensor values."""
|
||||||
self.assertTrue(setup_component(
|
assert setup_component(
|
||||||
self.hass, sensor.DOMAIN, {'sensor': VALID_CONFIG}))
|
self.hass, sensor.DOMAIN, {'sensor': VALID_CONFIG})
|
||||||
|
|
||||||
weather = self.hass.states.get('sensor.bom_fake_weather').state
|
weather = self.hass.states.get('sensor.bom_fake_weather').state
|
||||||
self.assertEqual('Fine', weather)
|
assert 'Fine' == weather
|
||||||
|
|
||||||
pressure = self.hass.states.get('sensor.bom_fake_pressure_mb').state
|
pressure = self.hass.states.get('sensor.bom_fake_pressure_mb').state
|
||||||
self.assertEqual('1021.7', pressure)
|
assert '1021.7' == pressure
|
||||||
|
|
||||||
feels_like = self.hass.states.get('sensor.bom_fake_feels_like_c').state
|
feels_like = self.hass.states.get('sensor.bom_fake_feels_like_c').state
|
||||||
self.assertEqual('25.0', feels_like)
|
assert '25.0' == feels_like
|
||||||
|
|
|
@ -53,7 +53,7 @@ class TestCanarySensorSetup(unittest.TestCase):
|
||||||
|
|
||||||
canary.setup_platform(self.hass, self.config, self.add_entities, None)
|
canary.setup_platform(self.hass, self.config, self.add_entities, None)
|
||||||
|
|
||||||
self.assertEqual(6, len(self.DEVICES))
|
assert 6 == len(self.DEVICES)
|
||||||
|
|
||||||
def test_temperature_sensor(self):
|
def test_temperature_sensor(self):
|
||||||
"""Test temperature sensor with fahrenheit."""
|
"""Test temperature sensor with fahrenheit."""
|
||||||
|
@ -66,10 +66,10 @@ class TestCanarySensorSetup(unittest.TestCase):
|
||||||
sensor = CanarySensor(data, SENSOR_TYPES[0], location, device)
|
sensor = CanarySensor(data, SENSOR_TYPES[0], location, device)
|
||||||
sensor.update()
|
sensor.update()
|
||||||
|
|
||||||
self.assertEqual("Home Family Room Temperature", sensor.name)
|
assert "Home Family Room Temperature" == sensor.name
|
||||||
self.assertEqual("°C", sensor.unit_of_measurement)
|
assert "°C" == sensor.unit_of_measurement
|
||||||
self.assertEqual(21.12, sensor.state)
|
assert 21.12 == sensor.state
|
||||||
self.assertEqual("mdi:thermometer", sensor.icon)
|
assert "mdi:thermometer" == sensor.icon
|
||||||
|
|
||||||
def test_temperature_sensor_with_none_sensor_value(self):
|
def test_temperature_sensor_with_none_sensor_value(self):
|
||||||
"""Test temperature sensor with fahrenheit."""
|
"""Test temperature sensor with fahrenheit."""
|
||||||
|
@ -82,7 +82,7 @@ class TestCanarySensorSetup(unittest.TestCase):
|
||||||
sensor = CanarySensor(data, SENSOR_TYPES[0], location, device)
|
sensor = CanarySensor(data, SENSOR_TYPES[0], location, device)
|
||||||
sensor.update()
|
sensor.update()
|
||||||
|
|
||||||
self.assertEqual(None, sensor.state)
|
assert sensor.state is None
|
||||||
|
|
||||||
def test_humidity_sensor(self):
|
def test_humidity_sensor(self):
|
||||||
"""Test humidity sensor."""
|
"""Test humidity sensor."""
|
||||||
|
@ -95,10 +95,10 @@ class TestCanarySensorSetup(unittest.TestCase):
|
||||||
sensor = CanarySensor(data, SENSOR_TYPES[1], location, device)
|
sensor = CanarySensor(data, SENSOR_TYPES[1], location, device)
|
||||||
sensor.update()
|
sensor.update()
|
||||||
|
|
||||||
self.assertEqual("Home Family Room Humidity", sensor.name)
|
assert "Home Family Room Humidity" == sensor.name
|
||||||
self.assertEqual("%", sensor.unit_of_measurement)
|
assert "%" == sensor.unit_of_measurement
|
||||||
self.assertEqual(50.46, sensor.state)
|
assert 50.46 == sensor.state
|
||||||
self.assertEqual("mdi:water-percent", sensor.icon)
|
assert "mdi:water-percent" == sensor.icon
|
||||||
|
|
||||||
def test_air_quality_sensor_with_very_abnormal_reading(self):
|
def test_air_quality_sensor_with_very_abnormal_reading(self):
|
||||||
"""Test air quality sensor."""
|
"""Test air quality sensor."""
|
||||||
|
@ -111,13 +111,13 @@ class TestCanarySensorSetup(unittest.TestCase):
|
||||||
sensor = CanarySensor(data, SENSOR_TYPES[2], location, device)
|
sensor = CanarySensor(data, SENSOR_TYPES[2], location, device)
|
||||||
sensor.update()
|
sensor.update()
|
||||||
|
|
||||||
self.assertEqual("Home Family Room Air Quality", sensor.name)
|
assert "Home Family Room Air Quality" == sensor.name
|
||||||
self.assertEqual(None, sensor.unit_of_measurement)
|
assert sensor.unit_of_measurement is None
|
||||||
self.assertEqual(0.4, sensor.state)
|
assert 0.4 == sensor.state
|
||||||
self.assertEqual("mdi:weather-windy", sensor.icon)
|
assert "mdi:weather-windy" == sensor.icon
|
||||||
|
|
||||||
air_quality = sensor.device_state_attributes[ATTR_AIR_QUALITY]
|
air_quality = sensor.device_state_attributes[ATTR_AIR_QUALITY]
|
||||||
self.assertEqual(STATE_AIR_QUALITY_VERY_ABNORMAL, air_quality)
|
assert STATE_AIR_QUALITY_VERY_ABNORMAL == air_quality
|
||||||
|
|
||||||
def test_air_quality_sensor_with_abnormal_reading(self):
|
def test_air_quality_sensor_with_abnormal_reading(self):
|
||||||
"""Test air quality sensor."""
|
"""Test air quality sensor."""
|
||||||
|
@ -130,13 +130,13 @@ class TestCanarySensorSetup(unittest.TestCase):
|
||||||
sensor = CanarySensor(data, SENSOR_TYPES[2], location, device)
|
sensor = CanarySensor(data, SENSOR_TYPES[2], location, device)
|
||||||
sensor.update()
|
sensor.update()
|
||||||
|
|
||||||
self.assertEqual("Home Family Room Air Quality", sensor.name)
|
assert "Home Family Room Air Quality" == sensor.name
|
||||||
self.assertEqual(None, sensor.unit_of_measurement)
|
assert sensor.unit_of_measurement is None
|
||||||
self.assertEqual(0.59, sensor.state)
|
assert 0.59 == sensor.state
|
||||||
self.assertEqual("mdi:weather-windy", sensor.icon)
|
assert "mdi:weather-windy" == sensor.icon
|
||||||
|
|
||||||
air_quality = sensor.device_state_attributes[ATTR_AIR_QUALITY]
|
air_quality = sensor.device_state_attributes[ATTR_AIR_QUALITY]
|
||||||
self.assertEqual(STATE_AIR_QUALITY_ABNORMAL, air_quality)
|
assert STATE_AIR_QUALITY_ABNORMAL == air_quality
|
||||||
|
|
||||||
def test_air_quality_sensor_with_normal_reading(self):
|
def test_air_quality_sensor_with_normal_reading(self):
|
||||||
"""Test air quality sensor."""
|
"""Test air quality sensor."""
|
||||||
|
@ -149,13 +149,13 @@ class TestCanarySensorSetup(unittest.TestCase):
|
||||||
sensor = CanarySensor(data, SENSOR_TYPES[2], location, device)
|
sensor = CanarySensor(data, SENSOR_TYPES[2], location, device)
|
||||||
sensor.update()
|
sensor.update()
|
||||||
|
|
||||||
self.assertEqual("Home Family Room Air Quality", sensor.name)
|
assert "Home Family Room Air Quality" == sensor.name
|
||||||
self.assertEqual(None, sensor.unit_of_measurement)
|
assert sensor.unit_of_measurement is None
|
||||||
self.assertEqual(1.0, sensor.state)
|
assert 1.0 == sensor.state
|
||||||
self.assertEqual("mdi:weather-windy", sensor.icon)
|
assert "mdi:weather-windy" == sensor.icon
|
||||||
|
|
||||||
air_quality = sensor.device_state_attributes[ATTR_AIR_QUALITY]
|
air_quality = sensor.device_state_attributes[ATTR_AIR_QUALITY]
|
||||||
self.assertEqual(STATE_AIR_QUALITY_NORMAL, air_quality)
|
assert STATE_AIR_QUALITY_NORMAL == air_quality
|
||||||
|
|
||||||
def test_air_quality_sensor_with_none_sensor_value(self):
|
def test_air_quality_sensor_with_none_sensor_value(self):
|
||||||
"""Test air quality sensor."""
|
"""Test air quality sensor."""
|
||||||
|
@ -168,8 +168,8 @@ class TestCanarySensorSetup(unittest.TestCase):
|
||||||
sensor = CanarySensor(data, SENSOR_TYPES[2], location, device)
|
sensor = CanarySensor(data, SENSOR_TYPES[2], location, device)
|
||||||
sensor.update()
|
sensor.update()
|
||||||
|
|
||||||
self.assertEqual(None, sensor.state)
|
assert sensor.state is None
|
||||||
self.assertEqual(None, sensor.device_state_attributes)
|
assert sensor.device_state_attributes is None
|
||||||
|
|
||||||
def test_battery_sensor(self):
|
def test_battery_sensor(self):
|
||||||
"""Test battery sensor."""
|
"""Test battery sensor."""
|
||||||
|
@ -182,10 +182,10 @@ class TestCanarySensorSetup(unittest.TestCase):
|
||||||
sensor = CanarySensor(data, SENSOR_TYPES[4], location, device)
|
sensor = CanarySensor(data, SENSOR_TYPES[4], location, device)
|
||||||
sensor.update()
|
sensor.update()
|
||||||
|
|
||||||
self.assertEqual("Home Family Room Battery", sensor.name)
|
assert "Home Family Room Battery" == sensor.name
|
||||||
self.assertEqual("%", sensor.unit_of_measurement)
|
assert "%" == sensor.unit_of_measurement
|
||||||
self.assertEqual(70.46, sensor.state)
|
assert 70.46 == sensor.state
|
||||||
self.assertEqual("mdi:battery-70", sensor.icon)
|
assert "mdi:battery-70" == sensor.icon
|
||||||
|
|
||||||
def test_wifi_sensor(self):
|
def test_wifi_sensor(self):
|
||||||
"""Test battery sensor."""
|
"""Test battery sensor."""
|
||||||
|
@ -198,7 +198,7 @@ class TestCanarySensorSetup(unittest.TestCase):
|
||||||
sensor = CanarySensor(data, SENSOR_TYPES[3], location, device)
|
sensor = CanarySensor(data, SENSOR_TYPES[3], location, device)
|
||||||
sensor.update()
|
sensor.update()
|
||||||
|
|
||||||
self.assertEqual("Home Family Room Wifi", sensor.name)
|
assert "Home Family Room Wifi" == sensor.name
|
||||||
self.assertEqual("dBm", sensor.unit_of_measurement)
|
assert "dBm" == sensor.unit_of_measurement
|
||||||
self.assertEqual(-57, sensor.state)
|
assert -57 == sensor.state
|
||||||
self.assertEqual("mdi:wifi", sensor.icon)
|
assert "mdi:wifi" == sensor.icon
|
||||||
|
|
|
@ -38,12 +38,12 @@ class TestCommandSensorSensor(unittest.TestCase):
|
||||||
|
|
||||||
command_line.setup_platform(self.hass, config, add_dev_callback)
|
command_line.setup_platform(self.hass, config, add_dev_callback)
|
||||||
|
|
||||||
self.assertEqual(1, len(devices))
|
assert 1 == len(devices)
|
||||||
entity = devices[0]
|
entity = devices[0]
|
||||||
entity.update()
|
entity.update()
|
||||||
self.assertEqual('Test', entity.name)
|
assert 'Test' == entity.name
|
||||||
self.assertEqual('in', entity.unit_of_measurement)
|
assert 'in' == entity.unit_of_measurement
|
||||||
self.assertEqual('5', entity.state)
|
assert '5' == entity.state
|
||||||
|
|
||||||
def test_template(self):
|
def test_template(self):
|
||||||
"""Test command sensor with template."""
|
"""Test command sensor with template."""
|
||||||
|
@ -54,7 +54,7 @@ class TestCommandSensorSensor(unittest.TestCase):
|
||||||
Template('{{ value | multiply(0.1) }}', self.hass), [])
|
Template('{{ value | multiply(0.1) }}', self.hass), [])
|
||||||
|
|
||||||
entity.update()
|
entity.update()
|
||||||
self.assertEqual(5, float(entity.state))
|
assert 5 == float(entity.state)
|
||||||
|
|
||||||
def test_template_render(self):
|
def test_template_render(self):
|
||||||
"""Ensure command with templates get rendered properly."""
|
"""Ensure command with templates get rendered properly."""
|
||||||
|
@ -65,14 +65,14 @@ class TestCommandSensorSensor(unittest.TestCase):
|
||||||
)
|
)
|
||||||
data.update()
|
data.update()
|
||||||
|
|
||||||
self.assertEqual("Works", data.value)
|
assert "Works" == data.value
|
||||||
|
|
||||||
def test_bad_command(self):
|
def test_bad_command(self):
|
||||||
"""Test bad command."""
|
"""Test bad command."""
|
||||||
data = command_line.CommandSensorData(self.hass, 'asdfasdf', 15)
|
data = command_line.CommandSensorData(self.hass, 'asdfasdf', 15)
|
||||||
data.update()
|
data.update()
|
||||||
|
|
||||||
self.assertEqual(None, data.value)
|
assert data.value is None
|
||||||
|
|
||||||
def test_update_with_json_attrs(self):
|
def test_update_with_json_attrs(self):
|
||||||
"""Test attributes get extracted from a JSON result."""
|
"""Test attributes get extracted from a JSON result."""
|
||||||
|
@ -88,12 +88,12 @@ class TestCommandSensorSensor(unittest.TestCase):
|
||||||
'another_key',
|
'another_key',
|
||||||
'key_three'])
|
'key_three'])
|
||||||
self.sensor.update()
|
self.sensor.update()
|
||||||
self.assertEqual('some_json_value',
|
assert 'some_json_value' == \
|
||||||
self.sensor.device_state_attributes['key'])
|
self.sensor.device_state_attributes['key']
|
||||||
self.assertEqual('another_json_value',
|
assert 'another_json_value' == \
|
||||||
self.sensor.device_state_attributes['another_key'])
|
self.sensor.device_state_attributes['another_key']
|
||||||
self.assertEqual('value_three',
|
assert 'value_three' == \
|
||||||
self.sensor.device_state_attributes['key_three'])
|
self.sensor.device_state_attributes['key_three']
|
||||||
|
|
||||||
@patch('homeassistant.components.sensor.command_line._LOGGER')
|
@patch('homeassistant.components.sensor.command_line._LOGGER')
|
||||||
def test_update_with_json_attrs_no_data(self, mock_logger):
|
def test_update_with_json_attrs_no_data(self, mock_logger):
|
||||||
|
@ -105,8 +105,8 @@ class TestCommandSensorSensor(unittest.TestCase):
|
||||||
self.sensor = command_line.CommandSensor(self.hass, data, 'test',
|
self.sensor = command_line.CommandSensor(self.hass, data, 'test',
|
||||||
None, None, ['key'])
|
None, None, ['key'])
|
||||||
self.sensor.update()
|
self.sensor.update()
|
||||||
self.assertEqual({}, self.sensor.device_state_attributes)
|
assert {} == self.sensor.device_state_attributes
|
||||||
self.assertTrue(mock_logger.warning.called)
|
assert mock_logger.warning.called
|
||||||
|
|
||||||
@patch('homeassistant.components.sensor.command_line._LOGGER')
|
@patch('homeassistant.components.sensor.command_line._LOGGER')
|
||||||
def test_update_with_json_attrs_not_dict(self, mock_logger):
|
def test_update_with_json_attrs_not_dict(self, mock_logger):
|
||||||
|
@ -118,8 +118,8 @@ class TestCommandSensorSensor(unittest.TestCase):
|
||||||
self.sensor = command_line.CommandSensor(self.hass, data, 'test',
|
self.sensor = command_line.CommandSensor(self.hass, data, 'test',
|
||||||
None, None, ['key'])
|
None, None, ['key'])
|
||||||
self.sensor.update()
|
self.sensor.update()
|
||||||
self.assertEqual({}, self.sensor.device_state_attributes)
|
assert {} == self.sensor.device_state_attributes
|
||||||
self.assertTrue(mock_logger.warning.called)
|
assert mock_logger.warning.called
|
||||||
|
|
||||||
@patch('homeassistant.components.sensor.command_line._LOGGER')
|
@patch('homeassistant.components.sensor.command_line._LOGGER')
|
||||||
def test_update_with_json_attrs_bad_JSON(self, mock_logger):
|
def test_update_with_json_attrs_bad_JSON(self, mock_logger):
|
||||||
|
@ -131,8 +131,8 @@ class TestCommandSensorSensor(unittest.TestCase):
|
||||||
self.sensor = command_line.CommandSensor(self.hass, data, 'test',
|
self.sensor = command_line.CommandSensor(self.hass, data, 'test',
|
||||||
None, None, ['key'])
|
None, None, ['key'])
|
||||||
self.sensor.update()
|
self.sensor.update()
|
||||||
self.assertEqual({}, self.sensor.device_state_attributes)
|
assert {} == self.sensor.device_state_attributes
|
||||||
self.assertTrue(mock_logger.warning.called)
|
assert mock_logger.warning.called
|
||||||
|
|
||||||
def test_update_with_missing_json_attrs(self):
|
def test_update_with_missing_json_attrs(self):
|
||||||
"""Test attributes get extracted from a JSON result."""
|
"""Test attributes get extracted from a JSON result."""
|
||||||
|
@ -149,13 +149,13 @@ class TestCommandSensorSensor(unittest.TestCase):
|
||||||
'key_three',
|
'key_three',
|
||||||
'special_key'])
|
'special_key'])
|
||||||
self.sensor.update()
|
self.sensor.update()
|
||||||
self.assertEqual('some_json_value',
|
assert 'some_json_value' == \
|
||||||
self.sensor.device_state_attributes['key'])
|
self.sensor.device_state_attributes['key']
|
||||||
self.assertEqual('another_json_value',
|
assert 'another_json_value' == \
|
||||||
self.sensor.device_state_attributes['another_key'])
|
self.sensor.device_state_attributes['another_key']
|
||||||
self.assertEqual('value_three',
|
assert 'value_three' == \
|
||||||
self.sensor.device_state_attributes['key_three'])
|
self.sensor.device_state_attributes['key_three']
|
||||||
self.assertFalse('special_key' in self.sensor.device_state_attributes)
|
assert not ('special_key' in self.sensor.device_state_attributes)
|
||||||
|
|
||||||
def test_update_with_unnecessary_json_attrs(self):
|
def test_update_with_unnecessary_json_attrs(self):
|
||||||
"""Test attributes get extracted from a JSON result."""
|
"""Test attributes get extracted from a JSON result."""
|
||||||
|
@ -170,8 +170,8 @@ class TestCommandSensorSensor(unittest.TestCase):
|
||||||
None, None, ['key',
|
None, None, ['key',
|
||||||
'another_key'])
|
'another_key'])
|
||||||
self.sensor.update()
|
self.sensor.update()
|
||||||
self.assertEqual('some_json_value',
|
assert 'some_json_value' == \
|
||||||
self.sensor.device_state_attributes['key'])
|
self.sensor.device_state_attributes['key']
|
||||||
self.assertEqual('another_json_value',
|
assert 'another_json_value' == \
|
||||||
self.sensor.device_state_attributes['another_key'])
|
self.sensor.device_state_attributes['another_key']
|
||||||
self.assertFalse('key_three' in self.sensor.device_state_attributes)
|
assert not ('key_three' in self.sensor.device_state_attributes)
|
||||||
|
|
|
@ -140,7 +140,7 @@ class TestDarkSkySetup(unittest.TestCase):
|
||||||
|
|
||||||
response = darksky.setup_platform(self.hass, VALID_CONFIG_MINIMAL,
|
response = darksky.setup_platform(self.hass, VALID_CONFIG_MINIMAL,
|
||||||
MagicMock())
|
MagicMock())
|
||||||
self.assertFalse(response)
|
assert not response
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
@patch('forecastio.api.get_forecast', wraps=forecastio.api.get_forecast)
|
@patch('forecastio.api.get_forecast', wraps=forecastio.api.get_forecast)
|
||||||
|
@ -152,12 +152,12 @@ class TestDarkSkySetup(unittest.TestCase):
|
||||||
|
|
||||||
assert setup_component(self.hass, 'sensor', VALID_CONFIG_MINIMAL)
|
assert setup_component(self.hass, 'sensor', VALID_CONFIG_MINIMAL)
|
||||||
|
|
||||||
self.assertTrue(mock_get_forecast.called)
|
assert mock_get_forecast.called
|
||||||
self.assertEqual(mock_get_forecast.call_count, 1)
|
assert mock_get_forecast.call_count == 1
|
||||||
self.assertEqual(len(self.hass.states.entity_ids()), 7)
|
assert len(self.hass.states.entity_ids()) == 7
|
||||||
|
|
||||||
state = self.hass.states.get('sensor.dark_sky_summary')
|
state = self.hass.states.get('sensor.dark_sky_summary')
|
||||||
assert state is not None
|
assert state is not None
|
||||||
self.assertEqual(state.state, 'Clear')
|
assert state.state == 'Clear'
|
||||||
self.assertEqual(state.attributes.get('friendly_name'),
|
assert state.attributes.get('friendly_name') == \
|
||||||
'Dark Sky Summary')
|
'Dark Sky Summary'
|
||||||
|
|
|
@ -27,9 +27,8 @@ class TestDteEnergyBridgeSetup(unittest.TestCase):
|
||||||
|
|
||||||
def test_setup_with_config(self):
|
def test_setup_with_config(self):
|
||||||
"""Test the platform setup with configuration."""
|
"""Test the platform setup with configuration."""
|
||||||
self.assertTrue(
|
assert setup_component(self.hass, 'sensor',
|
||||||
setup_component(self.hass, 'sensor',
|
{'dte_energy_bridge': DTE_ENERGY_BRIDGE_CONFIG})
|
||||||
{'dte_energy_bridge': DTE_ENERGY_BRIDGE_CONFIG}))
|
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_setup_correct_reading(self, mock_req):
|
def test_setup_correct_reading(self, mock_req):
|
||||||
|
@ -39,9 +38,9 @@ class TestDteEnergyBridgeSetup(unittest.TestCase):
|
||||||
text='.411 kW')
|
text='.411 kW')
|
||||||
assert setup_component(self.hass, 'sensor', {
|
assert setup_component(self.hass, 'sensor', {
|
||||||
'sensor': DTE_ENERGY_BRIDGE_CONFIG})
|
'sensor': DTE_ENERGY_BRIDGE_CONFIG})
|
||||||
self.assertEqual('0.411',
|
assert '0.411' == \
|
||||||
self.hass.states
|
self.hass.states \
|
||||||
.get('sensor.current_energy_usage').state)
|
.get('sensor.current_energy_usage').state
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_setup_incorrect_units_reading(self, mock_req):
|
def test_setup_incorrect_units_reading(self, mock_req):
|
||||||
|
@ -51,9 +50,9 @@ class TestDteEnergyBridgeSetup(unittest.TestCase):
|
||||||
text='411 kW')
|
text='411 kW')
|
||||||
assert setup_component(self.hass, 'sensor', {
|
assert setup_component(self.hass, 'sensor', {
|
||||||
'sensor': DTE_ENERGY_BRIDGE_CONFIG})
|
'sensor': DTE_ENERGY_BRIDGE_CONFIG})
|
||||||
self.assertEqual('0.411',
|
assert '0.411' == \
|
||||||
self.hass.states
|
self.hass.states \
|
||||||
.get('sensor.current_energy_usage').state)
|
.get('sensor.current_energy_usage').state
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_setup_bad_format_reading(self, mock_req):
|
def test_setup_bad_format_reading(self, mock_req):
|
||||||
|
@ -63,6 +62,6 @@ class TestDteEnergyBridgeSetup(unittest.TestCase):
|
||||||
text='411')
|
text='411')
|
||||||
assert setup_component(self.hass, 'sensor', {
|
assert setup_component(self.hass, 'sensor', {
|
||||||
'sensor': DTE_ENERGY_BRIDGE_CONFIG})
|
'sensor': DTE_ENERGY_BRIDGE_CONFIG})
|
||||||
self.assertEqual('unknown',
|
assert 'unknown' == \
|
||||||
self.hass.states
|
self.hass.states \
|
||||||
.get('sensor.current_energy_usage').state)
|
.get('sensor.current_energy_usage').state
|
||||||
|
|
|
@ -86,11 +86,11 @@ class DysonTest(unittest.TestCase):
|
||||||
sensor = dyson.DysonFilterLifeSensor(_get_device_without_state())
|
sensor = dyson.DysonFilterLifeSensor(_get_device_without_state())
|
||||||
sensor.hass = self.hass
|
sensor.hass = self.hass
|
||||||
sensor.entity_id = "sensor.dyson_1"
|
sensor.entity_id = "sensor.dyson_1"
|
||||||
self.assertFalse(sensor.should_poll)
|
assert not sensor.should_poll
|
||||||
self.assertIsNone(sensor.state)
|
assert sensor.state is None
|
||||||
self.assertEqual(sensor.unit_of_measurement, "hours")
|
assert sensor.unit_of_measurement == "hours"
|
||||||
self.assertEqual(sensor.name, "Device_name Filter Life")
|
assert sensor.name == "Device_name Filter Life"
|
||||||
self.assertEqual(sensor.entity_id, "sensor.dyson_1")
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
sensor.on_message('message')
|
sensor.on_message('message')
|
||||||
|
|
||||||
def test_dyson_filter_life_sensor_with_values(self):
|
def test_dyson_filter_life_sensor_with_values(self):
|
||||||
|
@ -98,11 +98,11 @@ class DysonTest(unittest.TestCase):
|
||||||
sensor = dyson.DysonFilterLifeSensor(_get_with_state())
|
sensor = dyson.DysonFilterLifeSensor(_get_with_state())
|
||||||
sensor.hass = self.hass
|
sensor.hass = self.hass
|
||||||
sensor.entity_id = "sensor.dyson_1"
|
sensor.entity_id = "sensor.dyson_1"
|
||||||
self.assertFalse(sensor.should_poll)
|
assert not sensor.should_poll
|
||||||
self.assertEqual(sensor.state, 100)
|
assert sensor.state == 100
|
||||||
self.assertEqual(sensor.unit_of_measurement, "hours")
|
assert sensor.unit_of_measurement == "hours"
|
||||||
self.assertEqual(sensor.name, "Device_name Filter Life")
|
assert sensor.name == "Device_name Filter Life"
|
||||||
self.assertEqual(sensor.entity_id, "sensor.dyson_1")
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
sensor.on_message('message')
|
sensor.on_message('message')
|
||||||
|
|
||||||
def test_dyson_dust_sensor(self):
|
def test_dyson_dust_sensor(self):
|
||||||
|
@ -110,55 +110,55 @@ class DysonTest(unittest.TestCase):
|
||||||
sensor = dyson.DysonDustSensor(_get_device_without_state())
|
sensor = dyson.DysonDustSensor(_get_device_without_state())
|
||||||
sensor.hass = self.hass
|
sensor.hass = self.hass
|
||||||
sensor.entity_id = "sensor.dyson_1"
|
sensor.entity_id = "sensor.dyson_1"
|
||||||
self.assertFalse(sensor.should_poll)
|
assert not sensor.should_poll
|
||||||
self.assertIsNone(sensor.state)
|
assert sensor.state is None
|
||||||
self.assertEqual(sensor.unit_of_measurement, None)
|
assert sensor.unit_of_measurement is None
|
||||||
self.assertEqual(sensor.name, "Device_name Dust")
|
assert sensor.name == "Device_name Dust"
|
||||||
self.assertEqual(sensor.entity_id, "sensor.dyson_1")
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
|
|
||||||
def test_dyson_dust_sensor_with_values(self):
|
def test_dyson_dust_sensor_with_values(self):
|
||||||
"""Test dust sensor with values."""
|
"""Test dust sensor with values."""
|
||||||
sensor = dyson.DysonDustSensor(_get_with_state())
|
sensor = dyson.DysonDustSensor(_get_with_state())
|
||||||
sensor.hass = self.hass
|
sensor.hass = self.hass
|
||||||
sensor.entity_id = "sensor.dyson_1"
|
sensor.entity_id = "sensor.dyson_1"
|
||||||
self.assertFalse(sensor.should_poll)
|
assert not sensor.should_poll
|
||||||
self.assertEqual(sensor.state, 5)
|
assert sensor.state == 5
|
||||||
self.assertEqual(sensor.unit_of_measurement, None)
|
assert sensor.unit_of_measurement is None
|
||||||
self.assertEqual(sensor.name, "Device_name Dust")
|
assert sensor.name == "Device_name Dust"
|
||||||
self.assertEqual(sensor.entity_id, "sensor.dyson_1")
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
|
|
||||||
def test_dyson_humidity_sensor(self):
|
def test_dyson_humidity_sensor(self):
|
||||||
"""Test humidity sensor with no value."""
|
"""Test humidity sensor with no value."""
|
||||||
sensor = dyson.DysonHumiditySensor(_get_device_without_state())
|
sensor = dyson.DysonHumiditySensor(_get_device_without_state())
|
||||||
sensor.hass = self.hass
|
sensor.hass = self.hass
|
||||||
sensor.entity_id = "sensor.dyson_1"
|
sensor.entity_id = "sensor.dyson_1"
|
||||||
self.assertFalse(sensor.should_poll)
|
assert not sensor.should_poll
|
||||||
self.assertIsNone(sensor.state)
|
assert sensor.state is None
|
||||||
self.assertEqual(sensor.unit_of_measurement, '%')
|
assert sensor.unit_of_measurement == '%'
|
||||||
self.assertEqual(sensor.name, "Device_name Humidity")
|
assert sensor.name == "Device_name Humidity"
|
||||||
self.assertEqual(sensor.entity_id, "sensor.dyson_1")
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
|
|
||||||
def test_dyson_humidity_sensor_with_values(self):
|
def test_dyson_humidity_sensor_with_values(self):
|
||||||
"""Test humidity sensor with values."""
|
"""Test humidity sensor with values."""
|
||||||
sensor = dyson.DysonHumiditySensor(_get_with_state())
|
sensor = dyson.DysonHumiditySensor(_get_with_state())
|
||||||
sensor.hass = self.hass
|
sensor.hass = self.hass
|
||||||
sensor.entity_id = "sensor.dyson_1"
|
sensor.entity_id = "sensor.dyson_1"
|
||||||
self.assertFalse(sensor.should_poll)
|
assert not sensor.should_poll
|
||||||
self.assertEqual(sensor.state, 45)
|
assert sensor.state == 45
|
||||||
self.assertEqual(sensor.unit_of_measurement, '%')
|
assert sensor.unit_of_measurement == '%'
|
||||||
self.assertEqual(sensor.name, "Device_name Humidity")
|
assert sensor.name == "Device_name Humidity"
|
||||||
self.assertEqual(sensor.entity_id, "sensor.dyson_1")
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
|
|
||||||
def test_dyson_humidity_standby_monitoring(self):
|
def test_dyson_humidity_standby_monitoring(self):
|
||||||
"""Test humidity sensor while device is in standby monitoring."""
|
"""Test humidity sensor while device is in standby monitoring."""
|
||||||
sensor = dyson.DysonHumiditySensor(_get_with_standby_monitoring())
|
sensor = dyson.DysonHumiditySensor(_get_with_standby_monitoring())
|
||||||
sensor.hass = self.hass
|
sensor.hass = self.hass
|
||||||
sensor.entity_id = "sensor.dyson_1"
|
sensor.entity_id = "sensor.dyson_1"
|
||||||
self.assertFalse(sensor.should_poll)
|
assert not sensor.should_poll
|
||||||
self.assertEqual(sensor.state, STATE_OFF)
|
assert sensor.state == STATE_OFF
|
||||||
self.assertEqual(sensor.unit_of_measurement, '%')
|
assert sensor.unit_of_measurement == '%'
|
||||||
self.assertEqual(sensor.name, "Device_name Humidity")
|
assert sensor.name == "Device_name Humidity"
|
||||||
self.assertEqual(sensor.entity_id, "sensor.dyson_1")
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
|
|
||||||
def test_dyson_temperature_sensor(self):
|
def test_dyson_temperature_sensor(self):
|
||||||
"""Test temperature sensor with no value."""
|
"""Test temperature sensor with no value."""
|
||||||
|
@ -166,11 +166,11 @@ class DysonTest(unittest.TestCase):
|
||||||
TEMP_CELSIUS)
|
TEMP_CELSIUS)
|
||||||
sensor.hass = self.hass
|
sensor.hass = self.hass
|
||||||
sensor.entity_id = "sensor.dyson_1"
|
sensor.entity_id = "sensor.dyson_1"
|
||||||
self.assertFalse(sensor.should_poll)
|
assert not sensor.should_poll
|
||||||
self.assertIsNone(sensor.state)
|
assert sensor.state is None
|
||||||
self.assertEqual(sensor.unit_of_measurement, '°C')
|
assert sensor.unit_of_measurement == '°C'
|
||||||
self.assertEqual(sensor.name, "Device_name Temperature")
|
assert sensor.name == "Device_name Temperature"
|
||||||
self.assertEqual(sensor.entity_id, "sensor.dyson_1")
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
|
|
||||||
def test_dyson_temperature_sensor_with_values(self):
|
def test_dyson_temperature_sensor_with_values(self):
|
||||||
"""Test temperature sensor with values."""
|
"""Test temperature sensor with values."""
|
||||||
|
@ -178,21 +178,21 @@ class DysonTest(unittest.TestCase):
|
||||||
TEMP_CELSIUS)
|
TEMP_CELSIUS)
|
||||||
sensor.hass = self.hass
|
sensor.hass = self.hass
|
||||||
sensor.entity_id = "sensor.dyson_1"
|
sensor.entity_id = "sensor.dyson_1"
|
||||||
self.assertFalse(sensor.should_poll)
|
assert not sensor.should_poll
|
||||||
self.assertEqual(sensor.state, 21.9)
|
assert sensor.state == 21.9
|
||||||
self.assertEqual(sensor.unit_of_measurement, '°C')
|
assert sensor.unit_of_measurement == '°C'
|
||||||
self.assertEqual(sensor.name, "Device_name Temperature")
|
assert sensor.name == "Device_name Temperature"
|
||||||
self.assertEqual(sensor.entity_id, "sensor.dyson_1")
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
|
|
||||||
sensor = dyson.DysonTemperatureSensor(_get_with_state(),
|
sensor = dyson.DysonTemperatureSensor(_get_with_state(),
|
||||||
TEMP_FAHRENHEIT)
|
TEMP_FAHRENHEIT)
|
||||||
sensor.hass = self.hass
|
sensor.hass = self.hass
|
||||||
sensor.entity_id = "sensor.dyson_1"
|
sensor.entity_id = "sensor.dyson_1"
|
||||||
self.assertFalse(sensor.should_poll)
|
assert not sensor.should_poll
|
||||||
self.assertEqual(sensor.state, 71.3)
|
assert sensor.state == 71.3
|
||||||
self.assertEqual(sensor.unit_of_measurement, '°F')
|
assert sensor.unit_of_measurement == '°F'
|
||||||
self.assertEqual(sensor.name, "Device_name Temperature")
|
assert sensor.name == "Device_name Temperature"
|
||||||
self.assertEqual(sensor.entity_id, "sensor.dyson_1")
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
|
|
||||||
def test_dyson_temperature_standby_monitoring(self):
|
def test_dyson_temperature_standby_monitoring(self):
|
||||||
"""Test temperature sensor while device is in standby monitoring."""
|
"""Test temperature sensor while device is in standby monitoring."""
|
||||||
|
@ -200,30 +200,30 @@ class DysonTest(unittest.TestCase):
|
||||||
TEMP_CELSIUS)
|
TEMP_CELSIUS)
|
||||||
sensor.hass = self.hass
|
sensor.hass = self.hass
|
||||||
sensor.entity_id = "sensor.dyson_1"
|
sensor.entity_id = "sensor.dyson_1"
|
||||||
self.assertFalse(sensor.should_poll)
|
assert not sensor.should_poll
|
||||||
self.assertEqual(sensor.state, STATE_OFF)
|
assert sensor.state == STATE_OFF
|
||||||
self.assertEqual(sensor.unit_of_measurement, '°C')
|
assert sensor.unit_of_measurement == '°C'
|
||||||
self.assertEqual(sensor.name, "Device_name Temperature")
|
assert sensor.name == "Device_name Temperature"
|
||||||
self.assertEqual(sensor.entity_id, "sensor.dyson_1")
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
|
|
||||||
def test_dyson_air_quality_sensor(self):
|
def test_dyson_air_quality_sensor(self):
|
||||||
"""Test air quality sensor with no value."""
|
"""Test air quality sensor with no value."""
|
||||||
sensor = dyson.DysonAirQualitySensor(_get_device_without_state())
|
sensor = dyson.DysonAirQualitySensor(_get_device_without_state())
|
||||||
sensor.hass = self.hass
|
sensor.hass = self.hass
|
||||||
sensor.entity_id = "sensor.dyson_1"
|
sensor.entity_id = "sensor.dyson_1"
|
||||||
self.assertFalse(sensor.should_poll)
|
assert not sensor.should_poll
|
||||||
self.assertIsNone(sensor.state)
|
assert sensor.state is None
|
||||||
self.assertEqual(sensor.unit_of_measurement, None)
|
assert sensor.unit_of_measurement is None
|
||||||
self.assertEqual(sensor.name, "Device_name AQI")
|
assert sensor.name == "Device_name AQI"
|
||||||
self.assertEqual(sensor.entity_id, "sensor.dyson_1")
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
|
|
||||||
def test_dyson_air_quality_sensor_with_values(self):
|
def test_dyson_air_quality_sensor_with_values(self):
|
||||||
"""Test air quality sensor with values."""
|
"""Test air quality sensor with values."""
|
||||||
sensor = dyson.DysonAirQualitySensor(_get_with_state())
|
sensor = dyson.DysonAirQualitySensor(_get_with_state())
|
||||||
sensor.hass = self.hass
|
sensor.hass = self.hass
|
||||||
sensor.entity_id = "sensor.dyson_1"
|
sensor.entity_id = "sensor.dyson_1"
|
||||||
self.assertFalse(sensor.should_poll)
|
assert not sensor.should_poll
|
||||||
self.assertEqual(sensor.state, 2)
|
assert sensor.state == 2
|
||||||
self.assertEqual(sensor.unit_of_measurement, None)
|
assert sensor.unit_of_measurement is None
|
||||||
self.assertEqual(sensor.name, "Device_name AQI")
|
assert sensor.name == "Device_name AQI"
|
||||||
self.assertEqual(sensor.entity_id, "sensor.dyson_1")
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
|
|
|
@ -85,16 +85,11 @@ class TestEfergySensor(unittest.TestCase):
|
||||||
'sensor': ONE_SENSOR_CONFIG,
|
'sensor': ONE_SENSOR_CONFIG,
|
||||||
})
|
})
|
||||||
|
|
||||||
self.assertEqual(
|
assert '38.21' == self.hass.states.get('sensor.energy_consumed').state
|
||||||
'38.21', self.hass.states.get('sensor.energy_consumed').state)
|
assert '1580' == self.hass.states.get('sensor.energy_usage').state
|
||||||
self.assertEqual(
|
assert 'ok' == self.hass.states.get('sensor.energy_budget').state
|
||||||
'1580', self.hass.states.get('sensor.energy_usage').state)
|
assert '5.27' == self.hass.states.get('sensor.energy_cost').state
|
||||||
self.assertEqual(
|
assert '1628' == self.hass.states.get('sensor.efergy_728386').state
|
||||||
'ok', self.hass.states.get('sensor.energy_budget').state)
|
|
||||||
self.assertEqual(
|
|
||||||
'5.27', self.hass.states.get('sensor.energy_cost').state)
|
|
||||||
self.assertEqual(
|
|
||||||
'1628', self.hass.states.get('sensor.efergy_728386').state)
|
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_multi_sensor_readings(self, mock):
|
def test_multi_sensor_readings(self, mock):
|
||||||
|
@ -104,9 +99,6 @@ class TestEfergySensor(unittest.TestCase):
|
||||||
'sensor': MULTI_SENSOR_CONFIG,
|
'sensor': MULTI_SENSOR_CONFIG,
|
||||||
})
|
})
|
||||||
|
|
||||||
self.assertEqual(
|
assert '218' == self.hass.states.get('sensor.efergy_728386').state
|
||||||
'218', self.hass.states.get('sensor.efergy_728386').state)
|
assert '1808' == self.hass.states.get('sensor.efergy_0').state
|
||||||
self.assertEqual(
|
assert '312' == self.hass.states.get('sensor.efergy_728387').state
|
||||||
'1808', self.hass.states.get('sensor.efergy_0').state)
|
|
||||||
self.assertEqual(
|
|
||||||
'312', self.hass.states.get('sensor.efergy_728387').state)
|
|
||||||
|
|
|
@ -101,120 +101,99 @@ class TestBanSensor(unittest.TestCase):
|
||||||
"""Test that log is parsed correctly for single ban."""
|
"""Test that log is parsed correctly for single ban."""
|
||||||
log_parser = BanLogParser(timedelta(seconds=-1), '/tmp')
|
log_parser = BanLogParser(timedelta(seconds=-1), '/tmp')
|
||||||
sensor = BanSensor('fail2ban', 'jail_one', log_parser)
|
sensor = BanSensor('fail2ban', 'jail_one', log_parser)
|
||||||
self.assertEqual(sensor.name, 'fail2ban jail_one')
|
assert sensor.name == 'fail2ban jail_one'
|
||||||
mock_fh = MockOpen(read_data=fake_log('single_ban'))
|
mock_fh = MockOpen(read_data=fake_log('single_ban'))
|
||||||
with patch('homeassistant.components.sensor.fail2ban.open', mock_fh,
|
with patch('homeassistant.components.sensor.fail2ban.open', mock_fh,
|
||||||
create=True):
|
create=True):
|
||||||
sensor.update()
|
sensor.update()
|
||||||
|
|
||||||
self.assertEqual(sensor.state, '111.111.111.111')
|
assert sensor.state == '111.111.111.111'
|
||||||
self.assertEqual(
|
assert \
|
||||||
sensor.state_attributes[STATE_CURRENT_BANS], ['111.111.111.111']
|
sensor.state_attributes[STATE_CURRENT_BANS] == ['111.111.111.111']
|
||||||
)
|
assert \
|
||||||
self.assertEqual(
|
sensor.state_attributes[STATE_ALL_BANS] == ['111.111.111.111']
|
||||||
sensor.state_attributes[STATE_ALL_BANS], ['111.111.111.111']
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_multiple_ban(self):
|
def test_multiple_ban(self):
|
||||||
"""Test that log is parsed correctly for multiple ban."""
|
"""Test that log is parsed correctly for multiple ban."""
|
||||||
log_parser = BanLogParser(timedelta(seconds=-1), '/tmp')
|
log_parser = BanLogParser(timedelta(seconds=-1), '/tmp')
|
||||||
sensor = BanSensor('fail2ban', 'jail_one', log_parser)
|
sensor = BanSensor('fail2ban', 'jail_one', log_parser)
|
||||||
self.assertEqual(sensor.name, 'fail2ban jail_one')
|
assert sensor.name == 'fail2ban jail_one'
|
||||||
mock_fh = MockOpen(read_data=fake_log('multi_ban'))
|
mock_fh = MockOpen(read_data=fake_log('multi_ban'))
|
||||||
with patch('homeassistant.components.sensor.fail2ban.open', mock_fh,
|
with patch('homeassistant.components.sensor.fail2ban.open', mock_fh,
|
||||||
create=True):
|
create=True):
|
||||||
sensor.update()
|
sensor.update()
|
||||||
|
|
||||||
self.assertEqual(sensor.state, '222.222.222.222')
|
assert sensor.state == '222.222.222.222'
|
||||||
self.assertEqual(
|
assert sensor.state_attributes[STATE_CURRENT_BANS] == \
|
||||||
sensor.state_attributes[STATE_CURRENT_BANS],
|
|
||||||
['111.111.111.111', '222.222.222.222']
|
['111.111.111.111', '222.222.222.222']
|
||||||
)
|
assert sensor.state_attributes[STATE_ALL_BANS] == \
|
||||||
self.assertEqual(
|
|
||||||
sensor.state_attributes[STATE_ALL_BANS],
|
|
||||||
['111.111.111.111', '222.222.222.222']
|
['111.111.111.111', '222.222.222.222']
|
||||||
)
|
|
||||||
|
|
||||||
def test_unban_all(self):
|
def test_unban_all(self):
|
||||||
"""Test that log is parsed correctly when unbanning."""
|
"""Test that log is parsed correctly when unbanning."""
|
||||||
log_parser = BanLogParser(timedelta(seconds=-1), '/tmp')
|
log_parser = BanLogParser(timedelta(seconds=-1), '/tmp')
|
||||||
sensor = BanSensor('fail2ban', 'jail_one', log_parser)
|
sensor = BanSensor('fail2ban', 'jail_one', log_parser)
|
||||||
self.assertEqual(sensor.name, 'fail2ban jail_one')
|
assert sensor.name == 'fail2ban jail_one'
|
||||||
mock_fh = MockOpen(read_data=fake_log('unban_all'))
|
mock_fh = MockOpen(read_data=fake_log('unban_all'))
|
||||||
with patch('homeassistant.components.sensor.fail2ban.open', mock_fh,
|
with patch('homeassistant.components.sensor.fail2ban.open', mock_fh,
|
||||||
create=True):
|
create=True):
|
||||||
sensor.update()
|
sensor.update()
|
||||||
|
|
||||||
self.assertEqual(sensor.state, 'None')
|
assert sensor.state == 'None'
|
||||||
self.assertEqual(sensor.state_attributes[STATE_CURRENT_BANS], [])
|
assert sensor.state_attributes[STATE_CURRENT_BANS] == []
|
||||||
self.assertEqual(
|
assert sensor.state_attributes[STATE_ALL_BANS] == \
|
||||||
sensor.state_attributes[STATE_ALL_BANS],
|
|
||||||
['111.111.111.111', '222.222.222.222']
|
['111.111.111.111', '222.222.222.222']
|
||||||
)
|
|
||||||
|
|
||||||
def test_unban_one(self):
|
def test_unban_one(self):
|
||||||
"""Test that log is parsed correctly when unbanning one ip."""
|
"""Test that log is parsed correctly when unbanning one ip."""
|
||||||
log_parser = BanLogParser(timedelta(seconds=-1), '/tmp')
|
log_parser = BanLogParser(timedelta(seconds=-1), '/tmp')
|
||||||
sensor = BanSensor('fail2ban', 'jail_one', log_parser)
|
sensor = BanSensor('fail2ban', 'jail_one', log_parser)
|
||||||
self.assertEqual(sensor.name, 'fail2ban jail_one')
|
assert sensor.name == 'fail2ban jail_one'
|
||||||
mock_fh = MockOpen(read_data=fake_log('unban_one'))
|
mock_fh = MockOpen(read_data=fake_log('unban_one'))
|
||||||
with patch('homeassistant.components.sensor.fail2ban.open', mock_fh,
|
with patch('homeassistant.components.sensor.fail2ban.open', mock_fh,
|
||||||
create=True):
|
create=True):
|
||||||
sensor.update()
|
sensor.update()
|
||||||
|
|
||||||
self.assertEqual(sensor.state, '222.222.222.222')
|
assert sensor.state == '222.222.222.222'
|
||||||
self.assertEqual(
|
assert sensor.state_attributes[STATE_CURRENT_BANS] == \
|
||||||
sensor.state_attributes[STATE_CURRENT_BANS],
|
|
||||||
['222.222.222.222']
|
['222.222.222.222']
|
||||||
)
|
assert sensor.state_attributes[STATE_ALL_BANS] == \
|
||||||
self.assertEqual(
|
|
||||||
sensor.state_attributes[STATE_ALL_BANS],
|
|
||||||
['111.111.111.111', '222.222.222.222']
|
['111.111.111.111', '222.222.222.222']
|
||||||
)
|
|
||||||
|
|
||||||
def test_multi_jail(self):
|
def test_multi_jail(self):
|
||||||
"""Test that log is parsed correctly when using multiple jails."""
|
"""Test that log is parsed correctly when using multiple jails."""
|
||||||
log_parser = BanLogParser(timedelta(seconds=-1), '/tmp')
|
log_parser = BanLogParser(timedelta(seconds=-1), '/tmp')
|
||||||
sensor1 = BanSensor('fail2ban', 'jail_one', log_parser)
|
sensor1 = BanSensor('fail2ban', 'jail_one', log_parser)
|
||||||
sensor2 = BanSensor('fail2ban', 'jail_two', log_parser)
|
sensor2 = BanSensor('fail2ban', 'jail_two', log_parser)
|
||||||
self.assertEqual(sensor1.name, 'fail2ban jail_one')
|
assert sensor1.name == 'fail2ban jail_one'
|
||||||
self.assertEqual(sensor2.name, 'fail2ban jail_two')
|
assert sensor2.name == 'fail2ban jail_two'
|
||||||
mock_fh = MockOpen(read_data=fake_log('multi_jail'))
|
mock_fh = MockOpen(read_data=fake_log('multi_jail'))
|
||||||
with patch('homeassistant.components.sensor.fail2ban.open', mock_fh,
|
with patch('homeassistant.components.sensor.fail2ban.open', mock_fh,
|
||||||
create=True):
|
create=True):
|
||||||
sensor1.update()
|
sensor1.update()
|
||||||
sensor2.update()
|
sensor2.update()
|
||||||
|
|
||||||
self.assertEqual(sensor1.state, '111.111.111.111')
|
assert sensor1.state == '111.111.111.111'
|
||||||
self.assertEqual(
|
assert \
|
||||||
sensor1.state_attributes[STATE_CURRENT_BANS], ['111.111.111.111']
|
sensor1.state_attributes[STATE_CURRENT_BANS] == ['111.111.111.111']
|
||||||
)
|
assert sensor1.state_attributes[STATE_ALL_BANS] == ['111.111.111.111']
|
||||||
self.assertEqual(
|
assert sensor2.state == '222.222.222.222'
|
||||||
sensor1.state_attributes[STATE_ALL_BANS], ['111.111.111.111']
|
assert \
|
||||||
)
|
sensor2.state_attributes[STATE_CURRENT_BANS] == ['222.222.222.222']
|
||||||
self.assertEqual(sensor2.state, '222.222.222.222')
|
assert sensor2.state_attributes[STATE_ALL_BANS] == ['222.222.222.222']
|
||||||
self.assertEqual(
|
|
||||||
sensor2.state_attributes[STATE_CURRENT_BANS], ['222.222.222.222']
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
sensor2.state_attributes[STATE_ALL_BANS], ['222.222.222.222']
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_ban_active_after_update(self):
|
def test_ban_active_after_update(self):
|
||||||
"""Test that ban persists after subsequent update."""
|
"""Test that ban persists after subsequent update."""
|
||||||
log_parser = BanLogParser(timedelta(seconds=-1), '/tmp')
|
log_parser = BanLogParser(timedelta(seconds=-1), '/tmp')
|
||||||
sensor = BanSensor('fail2ban', 'jail_one', log_parser)
|
sensor = BanSensor('fail2ban', 'jail_one', log_parser)
|
||||||
self.assertEqual(sensor.name, 'fail2ban jail_one')
|
assert sensor.name == 'fail2ban jail_one'
|
||||||
mock_fh = MockOpen(read_data=fake_log('single_ban'))
|
mock_fh = MockOpen(read_data=fake_log('single_ban'))
|
||||||
with patch('homeassistant.components.sensor.fail2ban.open', mock_fh,
|
with patch('homeassistant.components.sensor.fail2ban.open', mock_fh,
|
||||||
create=True):
|
create=True):
|
||||||
sensor.update()
|
sensor.update()
|
||||||
self.assertEqual(sensor.state, '111.111.111.111')
|
assert sensor.state == '111.111.111.111'
|
||||||
sensor.update()
|
sensor.update()
|
||||||
self.assertEqual(sensor.state, '111.111.111.111')
|
assert sensor.state == '111.111.111.111'
|
||||||
self.assertEqual(
|
assert \
|
||||||
sensor.state_attributes[STATE_CURRENT_BANS], ['111.111.111.111']
|
sensor.state_attributes[STATE_CURRENT_BANS] == ['111.111.111.111']
|
||||||
)
|
assert sensor.state_attributes[STATE_ALL_BANS] == ['111.111.111.111']
|
||||||
self.assertEqual(
|
|
||||||
sensor.state_attributes[STATE_ALL_BANS], ['111.111.111.111']
|
|
||||||
)
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue