mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 02:07:54 +00:00
parent
357631d659
commit
a89c7f8feb
@ -53,14 +53,13 @@ async def test_update_state_via_state_topic(hass, mqtt_mock):
|
||||
|
||||
entity_id = 'alarm_control_panel.test'
|
||||
|
||||
assert STATE_UNKNOWN == \
|
||||
hass.states.get(entity_id).state
|
||||
assert hass.states.get(entity_id).state == STATE_UNKNOWN
|
||||
|
||||
for state in (STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME,
|
||||
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_NIGHT,
|
||||
STATE_ALARM_PENDING, STATE_ALARM_TRIGGERED):
|
||||
async_fire_mqtt_message(hass, 'alarm/state', state)
|
||||
assert state == hass.states.get(entity_id).state
|
||||
assert hass.states.get(entity_id).state == state
|
||||
|
||||
|
||||
async def test_ignore_update_state_if_unknown_via_state_topic(hass, mqtt_mock):
|
||||
@ -76,11 +75,10 @@ async def test_ignore_update_state_if_unknown_via_state_topic(hass, mqtt_mock):
|
||||
|
||||
entity_id = 'alarm_control_panel.test'
|
||||
|
||||
assert STATE_UNKNOWN == \
|
||||
hass.states.get(entity_id).state
|
||||
assert hass.states.get(entity_id).state == STATE_UNKNOWN
|
||||
|
||||
async_fire_mqtt_message(hass, 'alarm/state', 'unsupported state')
|
||||
assert STATE_UNKNOWN == hass.states.get(entity_id).state
|
||||
assert hass.states.get(entity_id).state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_arm_home_publishes_mqtt(hass, mqtt_mock):
|
||||
@ -120,7 +118,7 @@ async def test_arm_home_not_publishes_mqtt_with_invalid_code_when_req(
|
||||
call_count = mqtt_mock.async_publish.call_count
|
||||
common.async_alarm_arm_home(hass, 'abcd')
|
||||
await hass.async_block_till_done()
|
||||
assert call_count == mqtt_mock.async_publish.call_count
|
||||
assert mqtt_mock.async_publish.call_count == call_count
|
||||
|
||||
|
||||
async def test_arm_home_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
|
||||
@ -182,7 +180,7 @@ async def test_arm_away_not_publishes_mqtt_with_invalid_code_when_req(
|
||||
call_count = mqtt_mock.async_publish.call_count
|
||||
common.async_alarm_arm_away(hass, 'abcd')
|
||||
await hass.async_block_till_done()
|
||||
assert call_count == mqtt_mock.async_publish.call_count
|
||||
assert mqtt_mock.async_publish.call_count == call_count
|
||||
|
||||
|
||||
async def test_arm_away_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
|
||||
@ -244,7 +242,7 @@ async def test_arm_night_not_publishes_mqtt_with_invalid_code_when_req(
|
||||
call_count = mqtt_mock.async_publish.call_count
|
||||
common.async_alarm_arm_night(hass, 'abcd')
|
||||
await hass.async_block_till_done()
|
||||
assert call_count == mqtt_mock.async_publish.call_count
|
||||
assert mqtt_mock.async_publish.call_count == call_count
|
||||
|
||||
|
||||
async def test_arm_night_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
|
||||
@ -353,7 +351,7 @@ async def test_disarm_not_publishes_mqtt_with_invalid_code_when_req(
|
||||
call_count = mqtt_mock.async_publish.call_count
|
||||
common.async_alarm_disarm(hass, 'abcd')
|
||||
await hass.async_block_till_done()
|
||||
assert call_count == mqtt_mock.async_publish.call_count
|
||||
assert mqtt_mock.async_publish.call_count == call_count
|
||||
|
||||
|
||||
async def test_default_availability_payload(hass, mqtt_mock):
|
||||
@ -370,17 +368,17 @@ async def test_default_availability_payload(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('alarm_control_panel.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'online')
|
||||
|
||||
state = hass.states.get('alarm_control_panel.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'offline')
|
||||
|
||||
state = hass.states.get('alarm_control_panel.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
@ -399,17 +397,17 @@ async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('alarm_control_panel.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'good')
|
||||
|
||||
state = hass.states.get('alarm_control_panel.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'nogood')
|
||||
|
||||
state = hass.states.get('alarm_control_panel.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
@ -427,7 +425,7 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '{ "val": "100" }')
|
||||
state = hass.states.get('alarm_control_panel.test')
|
||||
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
|
||||
async def test_update_state_via_state_topic_template(hass, mqtt_mock):
|
||||
@ -448,12 +446,12 @@ async def test_update_state_via_state_topic_template(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('alarm_control_panel.test')
|
||||
assert STATE_UNKNOWN == state.state
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', '100')
|
||||
|
||||
state = hass.states.get('alarm_control_panel.test')
|
||||
assert STATE_ALARM_ARMED_AWAY == state.state
|
||||
assert state.state == STATE_ALARM_ARMED_AWAY
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
@ -513,7 +511,7 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
await hass.async_block_till_done()
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
|
||||
state = hass.states.get('alarm_control_panel.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Change json_attributes_topic
|
||||
async_fire_mqtt_message(
|
||||
@ -523,12 +521,12 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
# Verify we are no longer subscribing to the old topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
|
||||
state = hass.states.get('alarm_control_panel.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Verify we are subscribing to the new topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
|
||||
state = hass.states.get('alarm_control_panel.beer')
|
||||
assert '75' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '75'
|
||||
|
||||
|
||||
async def test_unique_id(hass):
|
||||
|
@ -29,15 +29,15 @@ async def test_setting_sensor_value_via_mqtt_message(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', 'ON')
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', 'OFF')
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_setting_sensor_value_via_mqtt_message_and_template(
|
||||
@ -56,15 +56,15 @@ async def test_setting_sensor_value_via_mqtt_message_and_template(
|
||||
})
|
||||
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', '')
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', '')
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_valid_device_class(hass, mqtt_mock):
|
||||
@ -79,7 +79,7 @@ async def test_valid_device_class(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert 'motion' == state.attributes.get('device_class')
|
||||
assert state.attributes.get('device_class') == 'motion'
|
||||
|
||||
|
||||
async def test_invalid_device_class(hass, mqtt_mock):
|
||||
@ -108,7 +108,7 @@ async def test_availability_without_topic(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_availability_by_defaults(hass, mqtt_mock):
|
||||
@ -123,17 +123,17 @@ async def test_availability_by_defaults(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'online')
|
||||
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'offline')
|
||||
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_availability_by_custom_payload(hass, mqtt_mock):
|
||||
@ -150,17 +150,17 @@ async def test_availability_by_custom_payload(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'good')
|
||||
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'nogood')
|
||||
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_force_update_disabled(hass, mqtt_mock):
|
||||
@ -186,11 +186,11 @@ async def test_force_update_disabled(hass, mqtt_mock):
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', 'ON')
|
||||
await hass.async_block_till_done()
|
||||
assert 1 == len(events)
|
||||
assert len(events) == 1
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', 'ON')
|
||||
await hass.async_block_till_done()
|
||||
assert 1 == len(events)
|
||||
assert len(events) == 1
|
||||
|
||||
|
||||
async def test_force_update_enabled(hass, mqtt_mock):
|
||||
@ -217,11 +217,11 @@ async def test_force_update_enabled(hass, mqtt_mock):
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', 'ON')
|
||||
await hass.async_block_till_done()
|
||||
assert 1 == len(events)
|
||||
assert len(events) == 1
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', 'ON')
|
||||
await hass.async_block_till_done()
|
||||
assert 2 == len(events)
|
||||
assert len(events) == 2
|
||||
|
||||
|
||||
async def test_off_delay(hass, mqtt_mock):
|
||||
@ -250,20 +250,20 @@ async def test_off_delay(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'test-topic', 'ON')
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 1 == len(events)
|
||||
assert state.state == STATE_ON
|
||||
assert len(events) == 1
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', 'ON')
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 2 == len(events)
|
||||
assert state.state == STATE_ON
|
||||
assert len(events) == 2
|
||||
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=30))
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert 3 == len(events)
|
||||
assert state.state == STATE_OFF
|
||||
assert len(events) == 3
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
@ -280,7 +280,7 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '{ "val": "100" }')
|
||||
state = hass.states.get('binary_sensor.test')
|
||||
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
@ -338,7 +338,7 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
await hass.async_block_till_done()
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
|
||||
state = hass.states.get('binary_sensor.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Change json_attributes_topic
|
||||
async_fire_mqtt_message(hass, 'homeassistant/binary_sensor/bla/config',
|
||||
@ -348,12 +348,12 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
# Verify we are no longer subscribing to the old topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
|
||||
state = hass.states.get('binary_sensor.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Verify we are subscribing to the new topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
|
||||
state = hass.states.get('binary_sensor.beer')
|
||||
assert '75' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '75'
|
||||
|
||||
|
||||
async def test_unique_id(hass):
|
||||
|
@ -45,12 +45,12 @@ async def test_setup_params(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 21 == state.attributes.get('temperature')
|
||||
assert "low" == state.attributes.get('fan_mode')
|
||||
assert "off" == state.attributes.get('swing_mode')
|
||||
assert "off" == state.attributes.get('operation_mode')
|
||||
assert DEFAULT_MIN_TEMP == state.attributes.get('min_temp')
|
||||
assert DEFAULT_MAX_TEMP == state.attributes.get('max_temp')
|
||||
assert state.attributes.get('temperature') == 21
|
||||
assert state.attributes.get('fan_mode') == 'low'
|
||||
assert state.attributes.get('swing_mode') == 'off'
|
||||
assert state.attributes.get('operation_mode') == 'off'
|
||||
assert state.attributes.get('min_temp') == DEFAULT_MIN_TEMP
|
||||
assert state.attributes.get('max_temp') == DEFAULT_MAX_TEMP
|
||||
|
||||
|
||||
async def test_supported_features(hass, mqtt_mock):
|
||||
@ -87,16 +87,16 @@ async def test_set_operation_bad_attr_and_state(hass, mqtt_mock, caplog):
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "off" == state.attributes.get('operation_mode')
|
||||
assert "off" == state.state
|
||||
assert state.attributes.get('operation_mode') == 'off'
|
||||
assert state.state == 'off'
|
||||
common.async_set_operation_mode(hass, None, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
assert ("string value is None for dictionary value @ "
|
||||
"data['operation_mode']")\
|
||||
in caplog.text
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "off" == state.attributes.get('operation_mode')
|
||||
assert "off" == state.state
|
||||
assert state.attributes.get('operation_mode') == 'off'
|
||||
assert state.state == 'off'
|
||||
|
||||
|
||||
async def test_set_operation(hass, mqtt_mock):
|
||||
@ -104,13 +104,13 @@ async def test_set_operation(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "off" == state.attributes.get('operation_mode')
|
||||
assert "off" == state.state
|
||||
common.async_set_operation_mode(hass, "cool", ENTITY_CLIMATE)
|
||||
assert state.attributes.get('operation_mode') == 'off'
|
||||
assert state.state == 'off'
|
||||
common.async_set_operation_mode(hass, 'cool', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "cool" == state.attributes.get('operation_mode')
|
||||
assert "cool" == state.state
|
||||
assert state.attributes.get('operation_mode') == 'cool'
|
||||
assert state.state == 'cool'
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'mode-topic', 'cool', 0, False)
|
||||
|
||||
@ -123,23 +123,23 @@ async def test_set_operation_pessimistic(hass, mqtt_mock):
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('operation_mode') is None
|
||||
assert "unknown" == state.state
|
||||
assert state.state == 'unknown'
|
||||
|
||||
common.async_set_operation_mode(hass, "cool", ENTITY_CLIMATE)
|
||||
common.async_set_operation_mode(hass, 'cool', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('operation_mode') is None
|
||||
assert "unknown" == state.state
|
||||
assert state.state == 'unknown'
|
||||
|
||||
async_fire_mqtt_message(hass, 'mode-state', 'cool')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "cool" == state.attributes.get('operation_mode')
|
||||
assert "cool" == state.state
|
||||
assert state.attributes.get('operation_mode') == 'cool'
|
||||
assert state.state == 'cool'
|
||||
|
||||
async_fire_mqtt_message(hass, 'mode-state', 'bogus mode')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "cool" == state.attributes.get('operation_mode')
|
||||
assert "cool" == state.state
|
||||
assert state.attributes.get('operation_mode') == 'cool'
|
||||
assert state.state == 'cool'
|
||||
|
||||
|
||||
async def test_set_operation_with_power_command(hass, mqtt_mock):
|
||||
@ -149,24 +149,24 @@ async def test_set_operation_with_power_command(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "off" == state.attributes.get('operation_mode')
|
||||
assert "off" == state.state
|
||||
common.async_set_operation_mode(hass, "on", ENTITY_CLIMATE)
|
||||
assert state.attributes.get('operation_mode') == 'off'
|
||||
assert state.state == 'off'
|
||||
common.async_set_operation_mode(hass, 'on', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "on" == state.attributes.get('operation_mode')
|
||||
assert "on" == state.state
|
||||
assert state.attributes.get('operation_mode') == 'on'
|
||||
assert state.state == 'on'
|
||||
mqtt_mock.async_publish.assert_has_calls([
|
||||
unittest.mock.call('power-command', 'ON', 0, False),
|
||||
unittest.mock.call('mode-topic', 'on', 0, False)
|
||||
])
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.async_set_operation_mode(hass, "off", ENTITY_CLIMATE)
|
||||
common.async_set_operation_mode(hass, 'off', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "off" == state.attributes.get('operation_mode')
|
||||
assert "off" == state.state
|
||||
assert state.attributes.get('operation_mode') == 'off'
|
||||
assert state.state == 'off'
|
||||
mqtt_mock.async_publish.assert_has_calls([
|
||||
unittest.mock.call('power-command', 'OFF', 0, False),
|
||||
unittest.mock.call('mode-topic', 'off', 0, False)
|
||||
@ -179,13 +179,13 @@ async def test_set_fan_mode_bad_attr(hass, mqtt_mock, caplog):
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "low" == state.attributes.get('fan_mode')
|
||||
assert state.attributes.get('fan_mode') == 'low'
|
||||
common.async_set_fan_mode(hass, None, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
assert "string value is None for dictionary value @ data['fan_mode']"\
|
||||
in caplog.text
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "low" == state.attributes.get('fan_mode')
|
||||
assert state.attributes.get('fan_mode') == 'low'
|
||||
|
||||
|
||||
async def test_set_fan_mode_pessimistic(hass, mqtt_mock):
|
||||
@ -204,11 +204,11 @@ async def test_set_fan_mode_pessimistic(hass, mqtt_mock):
|
||||
|
||||
async_fire_mqtt_message(hass, 'fan-state', 'high')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'high' == state.attributes.get('fan_mode')
|
||||
assert state.attributes.get('fan_mode') == 'high'
|
||||
|
||||
async_fire_mqtt_message(hass, 'fan-state', 'bogus mode')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'high' == state.attributes.get('fan_mode')
|
||||
assert state.attributes.get('fan_mode') == 'high'
|
||||
|
||||
|
||||
async def test_set_fan_mode(hass, mqtt_mock):
|
||||
@ -216,13 +216,13 @@ async def test_set_fan_mode(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "low" == state.attributes.get('fan_mode')
|
||||
assert state.attributes.get('fan_mode') == 'low'
|
||||
common.async_set_fan_mode(hass, 'high', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'fan-mode-topic', 'high', 0, False)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'high' == state.attributes.get('fan_mode')
|
||||
assert state.attributes.get('fan_mode') == 'high'
|
||||
|
||||
|
||||
async def test_set_swing_mode_bad_attr(hass, mqtt_mock, caplog):
|
||||
@ -230,13 +230,13 @@ async def test_set_swing_mode_bad_attr(hass, mqtt_mock, caplog):
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "off" == state.attributes.get('swing_mode')
|
||||
assert state.attributes.get('swing_mode') == 'off'
|
||||
common.async_set_swing_mode(hass, None, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
assert "string value is None for dictionary value @ data['swing_mode']"\
|
||||
in caplog.text
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "off" == state.attributes.get('swing_mode')
|
||||
assert state.attributes.get('swing_mode') == 'off'
|
||||
|
||||
|
||||
async def test_set_swing_pessimistic(hass, mqtt_mock):
|
||||
@ -255,11 +255,11 @@ async def test_set_swing_pessimistic(hass, mqtt_mock):
|
||||
|
||||
async_fire_mqtt_message(hass, 'swing-state', 'on')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "on" == state.attributes.get('swing_mode')
|
||||
assert state.attributes.get('swing_mode') == 'on'
|
||||
|
||||
async_fire_mqtt_message(hass, 'swing-state', 'bogus state')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "on" == state.attributes.get('swing_mode')
|
||||
assert state.attributes.get('swing_mode') == 'on'
|
||||
|
||||
|
||||
async def test_set_swing(hass, mqtt_mock):
|
||||
@ -267,13 +267,13 @@ async def test_set_swing(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "off" == state.attributes.get('swing_mode')
|
||||
assert state.attributes.get('swing_mode') == 'off'
|
||||
common.async_set_swing_mode(hass, 'on', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'swing-mode-topic', 'on', 0, False)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "on" == state.attributes.get('swing_mode')
|
||||
assert state.attributes.get('swing_mode') == 'on'
|
||||
|
||||
|
||||
async def test_set_target_temperature(hass, mqtt_mock):
|
||||
@ -281,11 +281,11 @@ async def test_set_target_temperature(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 21 == state.attributes.get('temperature')
|
||||
assert state.attributes.get('temperature') == 21
|
||||
common.async_set_operation_mode(hass, 'heat', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'heat' == state.attributes.get('operation_mode')
|
||||
assert state.attributes.get('operation_mode') == 'heat'
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'mode-topic', 'heat', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@ -293,19 +293,19 @@ async def test_set_target_temperature(hass, mqtt_mock):
|
||||
entity_id=ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 47 == state.attributes.get('temperature')
|
||||
assert state.attributes.get('temperature') == 47
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'temperature-topic', 47, 0, False)
|
||||
|
||||
# also test directly supplying the operation mode to set_temperature
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
common.async_set_temperature(hass, temperature=21,
|
||||
operation_mode="cool",
|
||||
operation_mode='cool',
|
||||
entity_id=ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'cool' == state.attributes.get('operation_mode')
|
||||
assert 21 == state.attributes.get('temperature')
|
||||
assert state.attributes.get('operation_mode') == 'cool'
|
||||
assert state.attributes.get('temperature') == 21
|
||||
mqtt_mock.async_publish.assert_has_calls([
|
||||
unittest.mock.call('mode-topic', 'cool', 0, False),
|
||||
unittest.mock.call('temperature-topic', 21, 0, False)
|
||||
@ -331,11 +331,11 @@ async def test_set_target_temperature_pessimistic(hass, mqtt_mock):
|
||||
|
||||
async_fire_mqtt_message(hass, 'temperature-state', '1701')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 1701 == state.attributes.get('temperature')
|
||||
assert state.attributes.get('temperature') == 1701
|
||||
|
||||
async_fire_mqtt_message(hass, 'temperature-state', 'not a number')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 1701 == state.attributes.get('temperature')
|
||||
assert state.attributes.get('temperature') == 1701
|
||||
|
||||
|
||||
async def test_set_target_temperature_low_high(hass, mqtt_mock):
|
||||
@ -347,9 +347,8 @@ async def test_set_target_temperature_low_high(hass, mqtt_mock):
|
||||
entity_id=ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
print(state.attributes)
|
||||
assert 20 == state.attributes.get('target_temp_low')
|
||||
assert 23 == state.attributes.get('target_temp_high')
|
||||
assert state.attributes.get('target_temp_low') == 20
|
||||
assert state.attributes.get('target_temp_high') == 23
|
||||
mqtt_mock.async_publish.assert_any_call(
|
||||
'temperature-low-topic', 20, 0, False)
|
||||
mqtt_mock.async_publish.assert_any_call(
|
||||
@ -378,21 +377,21 @@ async def test_set_target_temperature_low_highpessimistic(hass, mqtt_mock):
|
||||
|
||||
async_fire_mqtt_message(hass, 'temperature-low-state', '1701')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 1701 == state.attributes.get('target_temp_low')
|
||||
assert state.attributes.get('target_temp_low') == 1701
|
||||
assert state.attributes.get('target_temp_high') is None
|
||||
|
||||
async_fire_mqtt_message(hass, 'temperature-high-state', '1703')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 1701 == state.attributes.get('target_temp_low')
|
||||
assert 1703 == state.attributes.get('target_temp_high')
|
||||
assert state.attributes.get('target_temp_low') == 1701
|
||||
assert state.attributes.get('target_temp_high') == 1703
|
||||
|
||||
async_fire_mqtt_message(hass, 'temperature-low-state', 'not a number')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 1701 == state.attributes.get('target_temp_low')
|
||||
assert state.attributes.get('target_temp_low') == 1701
|
||||
|
||||
async_fire_mqtt_message(hass, 'temperature-high-state', 'not a number')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 1703 == state.attributes.get('target_temp_high')
|
||||
assert state.attributes.get('target_temp_high') == 1703
|
||||
|
||||
|
||||
async def test_receive_mqtt_temperature(hass, mqtt_mock):
|
||||
@ -403,7 +402,7 @@ async def test_receive_mqtt_temperature(hass, mqtt_mock):
|
||||
|
||||
async_fire_mqtt_message(hass, 'current_temperature', '47')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 47 == state.attributes.get('current_temperature')
|
||||
assert state.attributes.get('current_temperature') == 47
|
||||
|
||||
|
||||
async def test_set_away_mode_pessimistic(hass, mqtt_mock):
|
||||
@ -413,24 +412,24 @@ async def test_set_away_mode_pessimistic(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('away_mode')
|
||||
assert state.attributes.get('away_mode') == 'off'
|
||||
|
||||
common.async_set_away_mode(hass, True, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('away_mode')
|
||||
assert state.attributes.get('away_mode') == 'off'
|
||||
|
||||
async_fire_mqtt_message(hass, 'away-state', 'ON')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'on' == state.attributes.get('away_mode')
|
||||
assert state.attributes.get('away_mode') == 'on'
|
||||
|
||||
async_fire_mqtt_message(hass, 'away-state', 'OFF')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('away_mode')
|
||||
assert state.attributes.get('away_mode') == 'off'
|
||||
|
||||
async_fire_mqtt_message(hass, 'away-state', 'nonsense')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('away_mode')
|
||||
assert state.attributes.get('away_mode') == 'off'
|
||||
|
||||
|
||||
async def test_set_away_mode(hass, mqtt_mock):
|
||||
@ -442,21 +441,21 @@ async def test_set_away_mode(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('away_mode')
|
||||
assert state.attributes.get('away_mode') == 'off'
|
||||
common.async_set_away_mode(hass, True, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'away-mode-topic', 'AN', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'on' == state.attributes.get('away_mode')
|
||||
assert state.attributes.get('away_mode') == 'on'
|
||||
|
||||
common.async_set_away_mode(hass, False, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'away-mode-topic', 'AUS', 0, False)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('away_mode')
|
||||
assert state.attributes.get('away_mode') == 'off'
|
||||
|
||||
|
||||
async def test_set_hold_pessimistic(hass, mqtt_mock):
|
||||
@ -475,11 +474,11 @@ async def test_set_hold_pessimistic(hass, mqtt_mock):
|
||||
|
||||
async_fire_mqtt_message(hass, 'hold-state', 'on')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'on' == state.attributes.get('hold_mode')
|
||||
assert state.attributes.get('hold_mode') == 'on'
|
||||
|
||||
async_fire_mqtt_message(hass, 'hold-state', 'off')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('hold_mode')
|
||||
assert state.attributes.get('hold_mode') == 'off'
|
||||
|
||||
|
||||
async def test_set_hold(hass, mqtt_mock):
|
||||
@ -494,14 +493,14 @@ async def test_set_hold(hass, mqtt_mock):
|
||||
'hold-topic', 'on', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'on' == state.attributes.get('hold_mode')
|
||||
assert state.attributes.get('hold_mode') == 'on'
|
||||
|
||||
common.async_set_hold_mode(hass, 'off', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'hold-topic', 'off', 0, False)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('hold_mode')
|
||||
assert state.attributes.get('hold_mode') == 'off'
|
||||
|
||||
|
||||
async def test_set_aux_pessimistic(hass, mqtt_mock):
|
||||
@ -511,24 +510,24 @@ async def test_set_aux_pessimistic(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('aux_heat')
|
||||
assert state.attributes.get('aux_heat') == 'off'
|
||||
|
||||
common.async_set_aux_heat(hass, True, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('aux_heat')
|
||||
assert state.attributes.get('aux_heat') == 'off'
|
||||
|
||||
async_fire_mqtt_message(hass, 'aux-state', 'ON')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'on' == state.attributes.get('aux_heat')
|
||||
assert state.attributes.get('aux_heat') == 'on'
|
||||
|
||||
async_fire_mqtt_message(hass, 'aux-state', 'OFF')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('aux_heat')
|
||||
assert state.attributes.get('aux_heat') == 'off'
|
||||
|
||||
async_fire_mqtt_message(hass, 'aux-state', 'nonsense')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('aux_heat')
|
||||
assert state.attributes.get('aux_heat') == 'off'
|
||||
|
||||
|
||||
async def test_set_aux(hass, mqtt_mock):
|
||||
@ -536,21 +535,21 @@ async def test_set_aux(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('aux_heat')
|
||||
assert state.attributes.get('aux_heat') == 'off'
|
||||
common.async_set_aux_heat(hass, True, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'aux-topic', 'ON', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'on' == state.attributes.get('aux_heat')
|
||||
assert state.attributes.get('aux_heat') == 'on'
|
||||
|
||||
common.async_set_aux_heat(hass, False, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'aux-topic', 'OFF', 0, False)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('aux_heat')
|
||||
assert state.attributes.get('aux_heat') == 'off'
|
||||
|
||||
|
||||
async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
@ -563,17 +562,17 @@ async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
||||
|
||||
state = hass.states.get('climate.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'good')
|
||||
|
||||
state = hass.states.get('climate.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'nogood')
|
||||
|
||||
state = hass.states.get('climate.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_set_with_templates(hass, mqtt_mock, caplog):
|
||||
@ -604,25 +603,25 @@ async def test_set_with_templates(hass, mqtt_mock, caplog):
|
||||
assert state.attributes.get('operation_mode') is None
|
||||
async_fire_mqtt_message(hass, 'mode-state', '"cool"')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "cool" == state.attributes.get('operation_mode')
|
||||
assert state.attributes.get('operation_mode') == 'cool'
|
||||
|
||||
# Fan Mode
|
||||
assert state.attributes.get('fan_mode') is None
|
||||
async_fire_mqtt_message(hass, 'fan-state', '"high"')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'high' == state.attributes.get('fan_mode')
|
||||
assert state.attributes.get('fan_mode') == 'high'
|
||||
|
||||
# Swing Mode
|
||||
assert state.attributes.get('swing_mode') is None
|
||||
async_fire_mqtt_message(hass, 'swing-state', '"on"')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert "on" == state.attributes.get('swing_mode')
|
||||
assert state.attributes.get('swing_mode') == 'on'
|
||||
|
||||
# Temperature - with valid value
|
||||
assert state.attributes.get('temperature') is None
|
||||
async_fire_mqtt_message(hass, 'temperature-state', '"1031"')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 1031 == state.attributes.get('temperature')
|
||||
assert state.attributes.get('temperature') == 1031
|
||||
|
||||
# Temperature - with invalid value
|
||||
async_fire_mqtt_message(hass, 'temperature-state', '"-INVALID-"')
|
||||
@ -630,22 +629,22 @@ async def test_set_with_templates(hass, mqtt_mock, caplog):
|
||||
# make sure, the invalid value gets logged...
|
||||
assert "Could not parse temperature from -INVALID-" in caplog.text
|
||||
# ... but the actual value stays unchanged.
|
||||
assert 1031 == state.attributes.get('temperature')
|
||||
assert state.attributes.get('temperature') == 1031
|
||||
|
||||
# Away Mode
|
||||
assert 'off' == state.attributes.get('away_mode')
|
||||
assert state.attributes.get('away_mode') == 'off'
|
||||
async_fire_mqtt_message(hass, 'away-state', '"ON"')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'on' == state.attributes.get('away_mode')
|
||||
assert state.attributes.get('away_mode') == 'on'
|
||||
|
||||
# Away Mode with JSON values
|
||||
async_fire_mqtt_message(hass, 'away-state', 'false')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('away_mode')
|
||||
assert state.attributes.get('away_mode') == 'off'
|
||||
|
||||
async_fire_mqtt_message(hass, 'away-state', 'true')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'on' == state.attributes.get('away_mode')
|
||||
assert state.attributes.get('away_mode') == 'on'
|
||||
|
||||
# Hold Mode
|
||||
assert state.attributes.get('hold_mode') is None
|
||||
@ -653,23 +652,23 @@ async def test_set_with_templates(hass, mqtt_mock, caplog):
|
||||
{ "attribute": "somemode" }
|
||||
""")
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'somemode' == state.attributes.get('hold_mode')
|
||||
assert state.attributes.get('hold_mode') == 'somemode'
|
||||
|
||||
# Aux mode
|
||||
assert 'off' == state.attributes.get('aux_heat')
|
||||
assert state.attributes.get('aux_heat') == 'off'
|
||||
async_fire_mqtt_message(hass, 'aux-state', 'switchmeon')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'on' == state.attributes.get('aux_heat')
|
||||
assert state.attributes.get('aux_heat') == 'on'
|
||||
|
||||
# anything other than 'switchmeon' should turn Aux mode off
|
||||
async_fire_mqtt_message(hass, 'aux-state', 'somerandomstring')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 'off' == state.attributes.get('aux_heat')
|
||||
assert state.attributes.get('aux_heat') == 'off'
|
||||
|
||||
# Current temperature
|
||||
async_fire_mqtt_message(hass, 'current-temperature', '"74656"')
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert 74656 == state.attributes.get('current_temperature')
|
||||
assert state.attributes.get('current_temperature') == 74656
|
||||
|
||||
|
||||
async def test_min_temp_custom(hass, mqtt_mock):
|
||||
@ -683,7 +682,7 @@ async def test_min_temp_custom(hass, mqtt_mock):
|
||||
min_temp = state.attributes.get('min_temp')
|
||||
|
||||
assert isinstance(min_temp, float)
|
||||
assert 26 == state.attributes.get('min_temp')
|
||||
assert state.attributes.get('min_temp') == 26
|
||||
|
||||
|
||||
async def test_max_temp_custom(hass, mqtt_mock):
|
||||
@ -697,7 +696,7 @@ async def test_max_temp_custom(hass, mqtt_mock):
|
||||
max_temp = state.attributes.get('max_temp')
|
||||
|
||||
assert isinstance(max_temp, float)
|
||||
assert 60 == max_temp
|
||||
assert max_temp == 60
|
||||
|
||||
|
||||
async def test_temp_step_custom(hass, mqtt_mock):
|
||||
@ -711,7 +710,7 @@ async def test_temp_step_custom(hass, mqtt_mock):
|
||||
temp_step = state.attributes.get('target_temp_step')
|
||||
|
||||
assert isinstance(temp_step, float)
|
||||
assert 0.01 == temp_step
|
||||
assert temp_step == 0.01
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
@ -729,7 +728,7 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '{ "val": "100" }')
|
||||
state = hass.states.get('climate.test')
|
||||
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
@ -791,7 +790,7 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
await hass.async_block_till_done()
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
|
||||
state = hass.states.get('climate.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Change json_attributes_topic
|
||||
async_fire_mqtt_message(hass, 'homeassistant/climate/bla/config',
|
||||
@ -801,12 +800,12 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
# Verify we are no longer subscribing to the old topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
|
||||
state = hass.states.get('climate.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Verify we are subscribing to the new topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
|
||||
state = hass.states.get('climate.beer')
|
||||
assert '75' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '75'
|
||||
|
||||
|
||||
async def test_unique_id(hass):
|
||||
|
@ -35,18 +35,18 @@ async def test_state_via_state_topic(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNKNOWN == state.state
|
||||
assert state.state == STATE_UNKNOWN
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
async_fire_mqtt_message(hass, 'state-topic', STATE_CLOSED)
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_CLOSED == state.state
|
||||
assert state.state == STATE_CLOSED
|
||||
|
||||
async_fire_mqtt_message(hass, 'state-topic', STATE_OPEN)
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_OPEN == state.state
|
||||
assert state.state == STATE_OPEN
|
||||
|
||||
|
||||
async def test_position_via_position_topic(hass, mqtt_mock):
|
||||
@ -67,18 +67,18 @@ async def test_position_via_position_topic(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNKNOWN == state.state
|
||||
assert state.state == STATE_UNKNOWN
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
async_fire_mqtt_message(hass, 'get-position-topic', '0')
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_CLOSED == state.state
|
||||
assert state.state == STATE_CLOSED
|
||||
|
||||
async_fire_mqtt_message(hass, 'get-position-topic', '100')
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_OPEN == state.state
|
||||
assert state.state == STATE_OPEN
|
||||
|
||||
|
||||
async def test_state_via_template(hass, mqtt_mock):
|
||||
@ -100,17 +100,17 @@ async def test_state_via_template(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNKNOWN == state.state
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
async_fire_mqtt_message(hass, 'state-topic', '10000')
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_OPEN == state.state
|
||||
assert state.state == STATE_OPEN
|
||||
|
||||
async_fire_mqtt_message(hass, 'state-topic', '99')
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_CLOSED == state.state
|
||||
assert state.state == STATE_CLOSED
|
||||
|
||||
|
||||
async def test_position_via_template(hass, mqtt_mock):
|
||||
@ -127,22 +127,22 @@ async def test_position_via_template(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNKNOWN == state.state
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
async_fire_mqtt_message(hass, 'get-position-topic', '10000')
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_OPEN == state.state
|
||||
assert state.state == STATE_OPEN
|
||||
|
||||
async_fire_mqtt_message(hass, 'get-position-topic', '5000')
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_OPEN == state.state
|
||||
assert state.state == STATE_OPEN
|
||||
|
||||
async_fire_mqtt_message(hass, 'get-position-topic', '99')
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_CLOSED == state.state
|
||||
assert state.state == STATE_CLOSED
|
||||
|
||||
|
||||
async def test_optimistic_state_change(hass, mqtt_mock):
|
||||
@ -157,31 +157,27 @@ async def test_optimistic_state_change(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNKNOWN == state.state
|
||||
assert state.state == STATE_UNKNOWN
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_OPEN_COVER,
|
||||
{ATTR_ENTITY_ID: 'cover.test'}))
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: 'cover.test'},
|
||||
blocking=True)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'command-topic', 'OPEN', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_OPEN == state.state
|
||||
assert state.state == STATE_OPEN
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_CLOSE_COVER,
|
||||
{ATTR_ENTITY_ID: 'cover.test'}))
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: 'cover.test'},
|
||||
blocking=True)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'command-topic', 'CLOSE', 0, False)
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_CLOSED == state.state
|
||||
assert state.state == STATE_CLOSED
|
||||
|
||||
|
||||
async def test_send_open_cover_command(hass, mqtt_mock):
|
||||
@ -197,18 +193,16 @@ async def test_send_open_cover_command(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNKNOWN == state.state
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_OPEN_COVER,
|
||||
{ATTR_ENTITY_ID: 'cover.test'}))
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: 'cover.test'},
|
||||
blocking=True)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'command-topic', 'OPEN', 2, False)
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNKNOWN == state.state
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_send_close_cover_command(hass, mqtt_mock):
|
||||
@ -224,18 +218,16 @@ async def test_send_close_cover_command(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNKNOWN == state.state
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_CLOSE_COVER,
|
||||
{ATTR_ENTITY_ID: 'cover.test'}))
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: 'cover.test'},
|
||||
blocking=True)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'command-topic', 'CLOSE', 2, False)
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNKNOWN == state.state
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_send_stop__cover_command(hass, mqtt_mock):
|
||||
@ -251,18 +243,16 @@ async def test_send_stop__cover_command(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNKNOWN == state.state
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_STOP_COVER,
|
||||
{ATTR_ENTITY_ID: 'cover.test'}))
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_STOP_COVER, {ATTR_ENTITY_ID: 'cover.test'},
|
||||
blocking=True)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'command-topic', 'STOP', 2, False)
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNKNOWN == state.state
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_current_cover_position(hass, mqtt_mock):
|
||||
@ -291,22 +281,22 @@ async def test_current_cover_position(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'get-position-topic', '0')
|
||||
current_cover_position = hass.states.get(
|
||||
'cover.test').attributes['current_position']
|
||||
assert 0 == current_cover_position
|
||||
assert current_cover_position == 0
|
||||
|
||||
async_fire_mqtt_message(hass, 'get-position-topic', '50')
|
||||
current_cover_position = hass.states.get(
|
||||
'cover.test').attributes['current_position']
|
||||
assert 50 == current_cover_position
|
||||
assert current_cover_position == 50
|
||||
|
||||
async_fire_mqtt_message(hass, 'get-position-topic', 'non-numeric')
|
||||
current_cover_position = hass.states.get(
|
||||
'cover.test').attributes['current_position']
|
||||
assert 50 == current_cover_position
|
||||
assert current_cover_position == 50
|
||||
|
||||
async_fire_mqtt_message(hass, 'get-position-topic', '101')
|
||||
current_cover_position = hass.states.get(
|
||||
'cover.test').attributes['current_position']
|
||||
assert 100 == current_cover_position
|
||||
assert current_cover_position == 100
|
||||
|
||||
|
||||
async def test_current_cover_position_inverted(hass, mqtt_mock):
|
||||
@ -335,37 +325,32 @@ async def test_current_cover_position_inverted(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'get-position-topic', '100')
|
||||
current_percentage_cover_position = hass.states.get(
|
||||
'cover.test').attributes['current_position']
|
||||
assert 0 == current_percentage_cover_position
|
||||
assert STATE_CLOSED == hass.states.get(
|
||||
'cover.test').state
|
||||
assert current_percentage_cover_position == 0
|
||||
assert hass.states.get('cover.test').state == STATE_CLOSED
|
||||
|
||||
async_fire_mqtt_message(hass, 'get-position-topic', '0')
|
||||
current_percentage_cover_position = hass.states.get(
|
||||
'cover.test').attributes['current_position']
|
||||
assert 100 == current_percentage_cover_position
|
||||
assert STATE_OPEN == hass.states.get(
|
||||
'cover.test').state
|
||||
assert current_percentage_cover_position == 100
|
||||
assert hass.states.get('cover.test').state == STATE_OPEN
|
||||
|
||||
async_fire_mqtt_message(hass, 'get-position-topic', '50')
|
||||
current_percentage_cover_position = hass.states.get(
|
||||
'cover.test').attributes['current_position']
|
||||
assert 50 == current_percentage_cover_position
|
||||
assert STATE_OPEN == hass.states.get(
|
||||
'cover.test').state
|
||||
assert current_percentage_cover_position == 50
|
||||
assert hass.states.get('cover.test').state == STATE_OPEN
|
||||
|
||||
async_fire_mqtt_message(hass, 'get-position-topic', 'non-numeric')
|
||||
current_percentage_cover_position = hass.states.get(
|
||||
'cover.test').attributes['current_position']
|
||||
assert 50 == current_percentage_cover_position
|
||||
assert STATE_OPEN == hass.states.get(
|
||||
'cover.test').state
|
||||
assert current_percentage_cover_position == 50
|
||||
assert hass.states.get('cover.test').state == STATE_OPEN
|
||||
|
||||
async_fire_mqtt_message(hass, 'get-position-topic', '101')
|
||||
current_percentage_cover_position = hass.states.get(
|
||||
'cover.test').attributes['current_position']
|
||||
assert 0 == current_percentage_cover_position
|
||||
assert STATE_CLOSED == hass.states.get(
|
||||
'cover.test').state
|
||||
assert current_percentage_cover_position == 0
|
||||
assert hass.states.get('cover.test').state == STATE_CLOSED
|
||||
|
||||
|
||||
async def test_set_cover_position(hass, mqtt_mock):
|
||||
@ -399,7 +384,7 @@ async def test_set_cover_position(hass, mqtt_mock):
|
||||
assert not ('current_tilt_position' in state_attributes_dict)
|
||||
current_cover_position = hass.states.get(
|
||||
'cover.test').attributes['current_position']
|
||||
assert 22 == current_cover_position
|
||||
assert current_cover_position == 22
|
||||
|
||||
|
||||
async def test_set_position_templated(hass, mqtt_mock):
|
||||
@ -420,11 +405,10 @@ async def test_set_position_templated(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_SET_COVER_POSITION,
|
||||
{ATTR_ENTITY_ID: 'cover.test', ATTR_POSITION: 100}))
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_SET_COVER_POSITION,
|
||||
{ATTR_ENTITY_ID: 'cover.test', ATTR_POSITION: 100},
|
||||
blocking=True)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'set-position-topic', '38', 0, False)
|
||||
@ -445,11 +429,10 @@ async def test_set_position_untemplated(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_SET_COVER_POSITION,
|
||||
{ATTR_ENTITY_ID: 'cover.test', ATTR_POSITION: 62}))
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_SET_COVER_POSITION,
|
||||
{ATTR_ENTITY_ID: 'cover.test', ATTR_POSITION: 62},
|
||||
blocking=True)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'position-topic', 62, 0, False)
|
||||
@ -470,8 +453,8 @@ async def test_no_command_topic(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
assert 240 == hass.states.get(
|
||||
'cover.test').attributes['supported_features']
|
||||
assert hass.states.get(
|
||||
'cover.test').attributes['supported_features'] == 240
|
||||
|
||||
|
||||
async def test_with_command_topic_and_tilt(hass, mqtt_mock):
|
||||
@ -490,8 +473,8 @@ async def test_with_command_topic_and_tilt(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
assert 251 == hass.states.get(
|
||||
'cover.test').attributes['supported_features']
|
||||
assert hass.states.get(
|
||||
'cover.test').attributes['supported_features'] == 251
|
||||
|
||||
|
||||
async def test_tilt_defaults(hass, mqtt_mock):
|
||||
@ -517,7 +500,7 @@ async def test_tilt_defaults(hass, mqtt_mock):
|
||||
|
||||
current_cover_position = hass.states.get(
|
||||
'cover.test').attributes['current_tilt_position']
|
||||
assert STATE_UNKNOWN == current_cover_position
|
||||
assert current_cover_position == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_tilt_via_invocation_defaults(hass, mqtt_mock):
|
||||
@ -537,21 +520,17 @@ async def test_tilt_via_invocation_defaults(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_OPEN_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: 'cover.test'}))
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_OPEN_COVER_TILT, {ATTR_ENTITY_ID: 'cover.test'},
|
||||
blocking=True)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'tilt-command-topic', 100, 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_CLOSE_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: 'cover.test'}))
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_CLOSE_COVER_TILT, {ATTR_ENTITY_ID: 'cover.test'},
|
||||
blocking=True)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'tilt-command-topic', 0, 0, False)
|
||||
@ -576,21 +555,17 @@ async def test_tilt_given_value(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_OPEN_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: 'cover.test'}))
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_OPEN_COVER_TILT, {ATTR_ENTITY_ID: 'cover.test'},
|
||||
blocking=True)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'tilt-command-topic', 400, 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_CLOSE_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: 'cover.test'}))
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_CLOSE_COVER_TILT, {ATTR_ENTITY_ID: 'cover.test'},
|
||||
blocking=True)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'tilt-command-topic', 125, 0, False)
|
||||
@ -619,13 +594,13 @@ async def test_tilt_via_topic(hass, mqtt_mock):
|
||||
|
||||
current_cover_tilt_position = hass.states.get(
|
||||
'cover.test').attributes['current_tilt_position']
|
||||
assert 0 == current_cover_tilt_position
|
||||
assert current_cover_tilt_position == 0
|
||||
|
||||
async_fire_mqtt_message(hass, 'tilt-status-topic', '50')
|
||||
|
||||
current_cover_tilt_position = hass.states.get(
|
||||
'cover.test').attributes['current_tilt_position']
|
||||
assert 50 == current_cover_tilt_position
|
||||
assert current_cover_tilt_position == 50
|
||||
|
||||
|
||||
async def test_tilt_via_topic_altered_range(hass, mqtt_mock):
|
||||
@ -653,19 +628,19 @@ async def test_tilt_via_topic_altered_range(hass, mqtt_mock):
|
||||
|
||||
current_cover_tilt_position = hass.states.get(
|
||||
'cover.test').attributes['current_tilt_position']
|
||||
assert 0 == current_cover_tilt_position
|
||||
assert current_cover_tilt_position == 0
|
||||
|
||||
async_fire_mqtt_message(hass, 'tilt-status-topic', '50')
|
||||
|
||||
current_cover_tilt_position = hass.states.get(
|
||||
'cover.test').attributes['current_tilt_position']
|
||||
assert 100 == current_cover_tilt_position
|
||||
assert current_cover_tilt_position == 100
|
||||
|
||||
async_fire_mqtt_message(hass, 'tilt-status-topic', '25')
|
||||
|
||||
current_cover_tilt_position = hass.states.get(
|
||||
'cover.test').attributes['current_tilt_position']
|
||||
assert 50 == current_cover_tilt_position
|
||||
assert current_cover_tilt_position == 50
|
||||
|
||||
|
||||
async def test_tilt_position(hass, mqtt_mock):
|
||||
@ -687,12 +662,10 @@ async def test_tilt_position(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_SET_COVER_TILT_POSITION,
|
||||
{ATTR_ENTITY_ID: 'cover.test', ATTR_TILT_POSITION: 50},
|
||||
blocking=True))
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_SET_COVER_TILT_POSITION,
|
||||
{ATTR_ENTITY_ID: 'cover.test', ATTR_TILT_POSITION: 50},
|
||||
blocking=True)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'tilt-command-topic', 50, 0, False)
|
||||
@ -719,12 +692,10 @@ async def test_tilt_position_altered_range(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_SET_COVER_TILT_POSITION,
|
||||
{ATTR_ENTITY_ID: 'cover.test', ATTR_TILT_POSITION: 50},
|
||||
blocking=True))
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN, SERVICE_SET_COVER_TILT_POSITION,
|
||||
{ATTR_ENTITY_ID: 'cover.test', ATTR_TILT_POSITION: 50},
|
||||
blocking=True)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'tilt-command-topic', 25, 0, False)
|
||||
@ -758,8 +729,8 @@ async def test_find_percentage_in_range_defaults(hass, mqtt_mock):
|
||||
None,
|
||||
None)
|
||||
|
||||
assert 44 == mqtt_cover.find_percentage_in_range(44)
|
||||
assert 44 == mqtt_cover.find_percentage_in_range(44, 'cover')
|
||||
assert mqtt_cover.find_percentage_in_range(44) == 44
|
||||
assert mqtt_cover.find_percentage_in_range(44, 'cover') == 44
|
||||
|
||||
|
||||
async def test_find_percentage_in_range_altered(hass, mqtt_mock):
|
||||
@ -790,8 +761,8 @@ async def test_find_percentage_in_range_altered(hass, mqtt_mock):
|
||||
None,
|
||||
None)
|
||||
|
||||
assert 40 == mqtt_cover.find_percentage_in_range(120)
|
||||
assert 40 == mqtt_cover.find_percentage_in_range(120, 'cover')
|
||||
assert mqtt_cover.find_percentage_in_range(120) == 40
|
||||
assert mqtt_cover.find_percentage_in_range(120, 'cover') == 40
|
||||
|
||||
|
||||
async def test_find_percentage_in_range_defaults_inverted(hass, mqtt_mock):
|
||||
@ -822,8 +793,8 @@ async def test_find_percentage_in_range_defaults_inverted(hass, mqtt_mock):
|
||||
None,
|
||||
None)
|
||||
|
||||
assert 56 == mqtt_cover.find_percentage_in_range(44)
|
||||
assert 56 == mqtt_cover.find_percentage_in_range(44, 'cover')
|
||||
assert mqtt_cover.find_percentage_in_range(44) == 56
|
||||
assert mqtt_cover.find_percentage_in_range(44, 'cover') == 56
|
||||
|
||||
|
||||
async def test_find_percentage_in_range_altered_inverted(hass, mqtt_mock):
|
||||
@ -854,8 +825,8 @@ async def test_find_percentage_in_range_altered_inverted(hass, mqtt_mock):
|
||||
None,
|
||||
None)
|
||||
|
||||
assert 60 == mqtt_cover.find_percentage_in_range(120)
|
||||
assert 60 == mqtt_cover.find_percentage_in_range(120, 'cover')
|
||||
assert mqtt_cover.find_percentage_in_range(120) == 60
|
||||
assert mqtt_cover.find_percentage_in_range(120, 'cover') == 60
|
||||
|
||||
|
||||
async def test_find_in_range_defaults(hass, mqtt_mock):
|
||||
@ -886,8 +857,8 @@ async def test_find_in_range_defaults(hass, mqtt_mock):
|
||||
None,
|
||||
None)
|
||||
|
||||
assert 44 == mqtt_cover.find_in_range_from_percent(44)
|
||||
assert 44 == mqtt_cover.find_in_range_from_percent(44, 'cover')
|
||||
assert mqtt_cover.find_in_range_from_percent(44) == 44
|
||||
assert mqtt_cover.find_in_range_from_percent(44, 'cover') == 44
|
||||
|
||||
|
||||
async def test_find_in_range_altered(hass, mqtt_mock):
|
||||
@ -918,8 +889,8 @@ async def test_find_in_range_altered(hass, mqtt_mock):
|
||||
None,
|
||||
None)
|
||||
|
||||
assert 120 == mqtt_cover.find_in_range_from_percent(40)
|
||||
assert 120 == mqtt_cover.find_in_range_from_percent(40, 'cover')
|
||||
assert mqtt_cover.find_in_range_from_percent(40) == 120
|
||||
assert mqtt_cover.find_in_range_from_percent(40, 'cover') == 120
|
||||
|
||||
|
||||
async def test_find_in_range_defaults_inverted(hass, mqtt_mock):
|
||||
@ -950,8 +921,8 @@ async def test_find_in_range_defaults_inverted(hass, mqtt_mock):
|
||||
None,
|
||||
None)
|
||||
|
||||
assert 44 == mqtt_cover.find_in_range_from_percent(56)
|
||||
assert 44 == mqtt_cover.find_in_range_from_percent(56, 'cover')
|
||||
assert mqtt_cover.find_in_range_from_percent(56) == 44
|
||||
assert mqtt_cover.find_in_range_from_percent(56, 'cover') == 44
|
||||
|
||||
|
||||
async def test_find_in_range_altered_inverted(hass, mqtt_mock):
|
||||
@ -982,8 +953,8 @@ async def test_find_in_range_altered_inverted(hass, mqtt_mock):
|
||||
None,
|
||||
None)
|
||||
|
||||
assert 120 == mqtt_cover.find_in_range_from_percent(60)
|
||||
assert 120 == mqtt_cover.find_in_range_from_percent(60, 'cover')
|
||||
assert mqtt_cover.find_in_range_from_percent(60) == 120
|
||||
assert mqtt_cover.find_in_range_from_percent(60, 'cover') == 120
|
||||
|
||||
|
||||
async def test_availability_without_topic(hass, mqtt_mock):
|
||||
@ -998,7 +969,7 @@ async def test_availability_without_topic(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_availability_by_defaults(hass, mqtt_mock):
|
||||
@ -1014,19 +985,19 @@ async def test_availability_by_defaults(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'online')
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'offline')
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_availability_by_custom_payload(hass, mqtt_mock):
|
||||
@ -1044,19 +1015,19 @@ async def test_availability_by_custom_payload(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'good')
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'nogood')
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_valid_device_class(hass, mqtt_mock):
|
||||
@ -1071,7 +1042,7 @@ async def test_valid_device_class(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('cover.test')
|
||||
assert 'garage' == state.attributes.get('device_class')
|
||||
assert state.attributes.get('device_class') == 'garage'
|
||||
|
||||
|
||||
async def test_invalid_device_class(hass, mqtt_mock):
|
||||
@ -1103,7 +1074,7 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '{ "val": "100" }')
|
||||
state = hass.states.get('cover.test')
|
||||
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
@ -1161,7 +1132,7 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
await hass.async_block_till_done()
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
|
||||
state = hass.states.get('cover.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Change json_attributes_topic
|
||||
async_fire_mqtt_message(hass, 'homeassistant/cover/bla/config',
|
||||
@ -1171,12 +1142,12 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
# Verify we are no longer subscribing to the old topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
|
||||
state = hass.states.get('cover.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Verify we are subscribing to the new topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
|
||||
state = hass.states.get('cover.beer')
|
||||
assert '75' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '75'
|
||||
|
||||
|
||||
async def test_discovery_removal_cover(hass, mqtt_mock, caplog):
|
||||
|
@ -69,23 +69,23 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
|
||||
state = hass.states.get('fan.test')
|
||||
assert state.attributes.get('oscillating') is False
|
||||
|
||||
assert fan.SPEED_OFF == state.attributes.get('speed')
|
||||
assert state.attributes.get('speed') == fan.SPEED_OFF
|
||||
|
||||
async_fire_mqtt_message(hass, 'speed-state-topic', 'speed_lOw')
|
||||
state = hass.states.get('fan.test')
|
||||
assert fan.SPEED_LOW == state.attributes.get('speed')
|
||||
assert state.attributes.get('speed') == fan.SPEED_LOW
|
||||
|
||||
async_fire_mqtt_message(hass, 'speed-state-topic', 'speed_mEdium')
|
||||
state = hass.states.get('fan.test')
|
||||
assert fan.SPEED_MEDIUM == state.attributes.get('speed')
|
||||
assert state.attributes.get('speed') == fan.SPEED_MEDIUM
|
||||
|
||||
async_fire_mqtt_message(hass, 'speed-state-topic', 'speed_High')
|
||||
state = hass.states.get('fan.test')
|
||||
assert fan.SPEED_HIGH == state.attributes.get('speed')
|
||||
assert state.attributes.get('speed') == fan.SPEED_HIGH
|
||||
|
||||
async_fire_mqtt_message(hass, 'speed-state-topic', 'speed_OfF')
|
||||
state = hass.states.get('fan.test')
|
||||
assert fan.SPEED_OFF == state.attributes.get('speed')
|
||||
assert state.attributes.get('speed') == fan.SPEED_OFF
|
||||
|
||||
|
||||
async def test_controlling_state_via_topic_and_json_message(hass, mqtt_mock):
|
||||
@ -129,23 +129,23 @@ async def test_controlling_state_via_topic_and_json_message(hass, mqtt_mock):
|
||||
state = hass.states.get('fan.test')
|
||||
assert state.attributes.get('oscillating') is False
|
||||
|
||||
assert fan.SPEED_OFF == state.attributes.get('speed')
|
||||
assert state.attributes.get('speed') == fan.SPEED_OFF
|
||||
|
||||
async_fire_mqtt_message(hass, 'speed-state-topic', '{"val":"low"}')
|
||||
state = hass.states.get('fan.test')
|
||||
assert fan.SPEED_LOW == state.attributes.get('speed')
|
||||
assert state.attributes.get('speed') == fan.SPEED_LOW
|
||||
|
||||
async_fire_mqtt_message(hass, 'speed-state-topic', '{"val":"medium"}')
|
||||
state = hass.states.get('fan.test')
|
||||
assert fan.SPEED_MEDIUM == state.attributes.get('speed')
|
||||
assert state.attributes.get('speed') == fan.SPEED_MEDIUM
|
||||
|
||||
async_fire_mqtt_message(hass, 'speed-state-topic', '{"val":"high"}')
|
||||
state = hass.states.get('fan.test')
|
||||
assert fan.SPEED_HIGH == state.attributes.get('speed')
|
||||
assert state.attributes.get('speed') == fan.SPEED_HIGH
|
||||
|
||||
async_fire_mqtt_message(hass, 'speed-state-topic', '{"val":"off"}')
|
||||
state = hass.states.get('fan.test')
|
||||
assert fan.SPEED_OFF == state.attributes.get('speed')
|
||||
assert state.attributes.get('speed') == fan.SPEED_OFF
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
@ -511,7 +511,7 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '{ "val": "100" }')
|
||||
state = hass.states.get('fan.test')
|
||||
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
@ -569,7 +569,7 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
await hass.async_block_till_done()
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
|
||||
state = hass.states.get('fan.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Change json_attributes_topic
|
||||
async_fire_mqtt_message(hass, 'homeassistant/fan/bla/config',
|
||||
@ -579,12 +579,12 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
# Verify we are no longer subscribing to the old topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
|
||||
state = hass.states.get('fan.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Verify we are subscribing to the new topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
|
||||
state = hass.states.get('fan.beer')
|
||||
assert '75' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '75'
|
||||
|
||||
|
||||
async def test_unique_id(hass):
|
||||
|
@ -82,11 +82,11 @@ class TestMQTTComponent(unittest.TestCase):
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert 1 == len(self.calls)
|
||||
assert 'test-topic' == \
|
||||
self.calls[0][0].data['service_data'][mqtt.ATTR_TOPIC]
|
||||
assert 'test-payload' == \
|
||||
self.calls[0][0].data['service_data'][mqtt.ATTR_PAYLOAD]
|
||||
assert len(self.calls) == 1
|
||||
assert self.calls[0][0].data['service_data'][mqtt.ATTR_TOPIC] == \
|
||||
'test-topic'
|
||||
assert self.calls[0][0].data['service_data'][mqtt.ATTR_PAYLOAD] == \
|
||||
'test-payload'
|
||||
|
||||
def test_service_call_without_topic_does_not_publish(self):
|
||||
"""Test the service call if topic is missing."""
|
||||
@ -105,7 +105,7 @@ class TestMQTTComponent(unittest.TestCase):
|
||||
mqtt.publish_template(self.hass, "test/topic", "{{ 1+1 }}")
|
||||
self.hass.block_till_done()
|
||||
assert self.hass.data['mqtt'].async_publish.called
|
||||
assert self.hass.data['mqtt'].async_publish.call_args[0][1] == "2"
|
||||
assert self.hass.data['mqtt'].async_publish.call_args[0][1] == '2'
|
||||
|
||||
def test_service_call_with_payload_doesnt_render_template(self):
|
||||
"""Test the service call with unrendered template.
|
||||
@ -307,7 +307,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, 'test-topic', '°C')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 1 == len(self.calls)
|
||||
assert len(self.calls) == 1
|
||||
|
||||
def test_subscribe_topic(self):
|
||||
"""Test the subscription of a topic."""
|
||||
@ -316,16 +316,16 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, 'test-topic', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 1 == len(self.calls)
|
||||
assert 'test-topic' == self.calls[0][0].topic
|
||||
assert 'test-payload' == self.calls[0][0].payload
|
||||
assert len(self.calls) == 1
|
||||
assert self.calls[0][0].topic == 'test-topic'
|
||||
assert self.calls[0][0].payload == 'test-payload'
|
||||
|
||||
unsub()
|
||||
|
||||
fire_mqtt_message(self.hass, 'test-topic', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 1 == len(self.calls)
|
||||
assert len(self.calls) == 1
|
||||
|
||||
def test_subscribe_topic_not_match(self):
|
||||
"""Test if subscribed topic is not a match."""
|
||||
@ -334,7 +334,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, 'another-test-topic', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 0 == len(self.calls)
|
||||
assert len(self.calls) == 0
|
||||
|
||||
def test_subscribe_topic_level_wildcard(self):
|
||||
"""Test the subscription of wildcard topics."""
|
||||
@ -343,9 +343,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, 'test-topic/bier/on', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 1 == len(self.calls)
|
||||
assert 'test-topic/bier/on' == self.calls[0][0].topic
|
||||
assert 'test-payload' == self.calls[0][0].payload
|
||||
assert len(self.calls) == 1
|
||||
assert self.calls[0][0].topic == 'test-topic/bier/on'
|
||||
assert self.calls[0][0].payload == 'test-payload'
|
||||
|
||||
def test_subscribe_topic_level_wildcard_no_subtree_match(self):
|
||||
"""Test the subscription of wildcard topics."""
|
||||
@ -354,7 +354,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, 'test-topic/bier', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 0 == len(self.calls)
|
||||
assert len(self.calls) == 0
|
||||
|
||||
def test_subscribe_topic_level_wildcard_root_topic_no_subtree_match(self):
|
||||
"""Test the subscription of wildcard topics."""
|
||||
@ -363,7 +363,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, 'test-topic-123', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 0 == len(self.calls)
|
||||
assert len(self.calls) == 0
|
||||
|
||||
def test_subscribe_topic_subtree_wildcard_subtree_topic(self):
|
||||
"""Test the subscription of wildcard topics."""
|
||||
@ -372,9 +372,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, 'test-topic/bier/on', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 1 == len(self.calls)
|
||||
assert 'test-topic/bier/on' == self.calls[0][0].topic
|
||||
assert 'test-payload' == self.calls[0][0].payload
|
||||
assert len(self.calls) == 1
|
||||
assert self.calls[0][0].topic == 'test-topic/bier/on'
|
||||
assert self.calls[0][0].payload == 'test-payload'
|
||||
|
||||
def test_subscribe_topic_subtree_wildcard_root_topic(self):
|
||||
"""Test the subscription of wildcard topics."""
|
||||
@ -383,9 +383,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, 'test-topic', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 1 == len(self.calls)
|
||||
assert 'test-topic' == self.calls[0][0].topic
|
||||
assert 'test-payload' == self.calls[0][0].payload
|
||||
assert len(self.calls) == 1
|
||||
assert self.calls[0][0].topic == 'test-topic'
|
||||
assert self.calls[0][0].payload == 'test-payload'
|
||||
|
||||
def test_subscribe_topic_subtree_wildcard_no_match(self):
|
||||
"""Test the subscription of wildcard topics."""
|
||||
@ -394,7 +394,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, 'another-test-topic', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 0 == len(self.calls)
|
||||
assert len(self.calls) == 0
|
||||
|
||||
def test_subscribe_topic_level_wildcard_and_wildcard_root_topic(self):
|
||||
"""Test the subscription of wildcard topics."""
|
||||
@ -403,9 +403,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, 'hi/test-topic', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 1 == len(self.calls)
|
||||
assert 'hi/test-topic' == self.calls[0][0].topic
|
||||
assert 'test-payload' == self.calls[0][0].payload
|
||||
assert len(self.calls) == 1
|
||||
assert self.calls[0][0].topic == 'hi/test-topic'
|
||||
assert self.calls[0][0].payload == 'test-payload'
|
||||
|
||||
def test_subscribe_topic_level_wildcard_and_wildcard_subtree_topic(self):
|
||||
"""Test the subscription of wildcard topics."""
|
||||
@ -414,9 +414,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, 'hi/test-topic/here-iam', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 1 == len(self.calls)
|
||||
assert 'hi/test-topic/here-iam' == self.calls[0][0].topic
|
||||
assert 'test-payload' == self.calls[0][0].payload
|
||||
assert len(self.calls) == 1
|
||||
assert self.calls[0][0].topic == 'hi/test-topic/here-iam'
|
||||
assert self.calls[0][0].payload == 'test-payload'
|
||||
|
||||
def test_subscribe_topic_level_wildcard_and_wildcard_level_no_match(self):
|
||||
"""Test the subscription of wildcard topics."""
|
||||
@ -425,7 +425,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, 'hi/here-iam/test-topic', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 0 == len(self.calls)
|
||||
assert len(self.calls) == 0
|
||||
|
||||
def test_subscribe_topic_level_wildcard_and_wildcard_no_match(self):
|
||||
"""Test the subscription of wildcard topics."""
|
||||
@ -434,7 +434,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, 'hi/another-test-topic', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 0 == len(self.calls)
|
||||
assert len(self.calls) == 0
|
||||
|
||||
def test_subscribe_topic_sys_root(self):
|
||||
"""Test the subscription of $ root topics."""
|
||||
@ -443,9 +443,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, '$test-topic/subtree/on', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 1 == len(self.calls)
|
||||
assert '$test-topic/subtree/on' == self.calls[0][0].topic
|
||||
assert 'test-payload' == self.calls[0][0].payload
|
||||
assert len(self.calls) == 1
|
||||
assert self.calls[0][0].topic == '$test-topic/subtree/on'
|
||||
assert self.calls[0][0].payload == 'test-payload'
|
||||
|
||||
def test_subscribe_topic_sys_root_and_wildcard_topic(self):
|
||||
"""Test the subscription of $ root and wildcard topics."""
|
||||
@ -454,9 +454,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
fire_mqtt_message(self.hass, '$test-topic/some-topic', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 1 == len(self.calls)
|
||||
assert '$test-topic/some-topic' == self.calls[0][0].topic
|
||||
assert 'test-payload' == self.calls[0][0].payload
|
||||
assert len(self.calls) == 1
|
||||
assert self.calls[0][0].topic == '$test-topic/some-topic'
|
||||
assert self.calls[0][0].payload == 'test-payload'
|
||||
|
||||
def test_subscribe_topic_sys_root_and_wildcard_subtree_topic(self):
|
||||
"""Test the subscription of $ root and wildcard subtree topics."""
|
||||
@ -466,9 +466,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
assert 1 == len(self.calls)
|
||||
assert '$test-topic/subtree/some-topic' == self.calls[0][0].topic
|
||||
assert 'test-payload' == self.calls[0][0].payload
|
||||
assert len(self.calls) == 1
|
||||
assert self.calls[0][0].topic == '$test-topic/subtree/some-topic'
|
||||
assert self.calls[0][0].payload == 'test-payload'
|
||||
|
||||
def test_subscribe_special_characters(self):
|
||||
"""Test the subscription to topics with special characters."""
|
||||
@ -479,9 +479,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
|
||||
fire_mqtt_message(self.hass, topic, payload)
|
||||
self.hass.block_till_done()
|
||||
assert 1 == len(self.calls)
|
||||
assert topic == self.calls[0][0].topic
|
||||
assert payload == self.calls[0][0].payload
|
||||
assert len(self.calls) == 1
|
||||
assert self.calls[0][0].topic == topic
|
||||
assert self.calls[0][0].payload == payload
|
||||
|
||||
def test_mqtt_failed_connection_results_in_disconnect(self):
|
||||
"""Test if connection failure leads to disconnect."""
|
||||
@ -507,9 +507,8 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
self.hass.data['mqtt']._mqttc.reconnect.side_effect = [1, 1, 1, 0]
|
||||
self.hass.data['mqtt']._mqtt_on_disconnect(None, None, 1)
|
||||
assert self.hass.data['mqtt']._mqttc.reconnect.called
|
||||
assert 4 == len(self.hass.data['mqtt']._mqttc.reconnect.mock_calls)
|
||||
assert [1, 2, 4] == \
|
||||
[call[1][0] for call in mock_sleep.mock_calls]
|
||||
assert len(self.hass.data['mqtt']._mqttc.reconnect.mock_calls) == 4
|
||||
assert [call[1][0] for call in mock_sleep.mock_calls] == [1, 2, 4]
|
||||
|
||||
def test_retained_message_on_subscribe_received(self):
|
||||
"""Test every subscriber receives retained message on subscribe."""
|
||||
@ -567,21 +566,18 @@ class TestMQTTCallbacks(unittest.TestCase):
|
||||
mock.call('test/state', 0),
|
||||
mock.call('test/state', 1)
|
||||
]
|
||||
assert self.hass.data['mqtt']._mqttc.subscribe.mock_calls == \
|
||||
expected
|
||||
assert self.hass.data['mqtt']._mqttc.subscribe.mock_calls == expected
|
||||
|
||||
unsub()
|
||||
self.hass.block_till_done()
|
||||
assert self.hass.data['mqtt']._mqttc.unsubscribe.call_count == \
|
||||
0
|
||||
assert self.hass.data['mqtt']._mqttc.unsubscribe.call_count == 0
|
||||
|
||||
self.hass.data['mqtt']._mqtt_on_disconnect(None, None, 0)
|
||||
self.hass.data['mqtt']._mqtt_on_connect(None, None, None, 0)
|
||||
self.hass.block_till_done()
|
||||
|
||||
expected.append(mock.call('test/state', 1))
|
||||
assert self.hass.data['mqtt']._mqttc.subscribe.mock_calls == \
|
||||
expected
|
||||
assert self.hass.data['mqtt']._mqttc.subscribe.mock_calls == expected
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
|
@ -194,7 +194,7 @@ async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('color_temp') is None
|
||||
@ -205,7 +205,7 @@ async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/status', 'ON')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('color_temp') is None
|
||||
@ -243,7 +243,7 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('color_temp') is None
|
||||
@ -256,42 +256,40 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/status', '1')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
assert 150 == state.attributes.get('color_temp')
|
||||
assert 'none' == state.attributes.get('effect')
|
||||
assert (0, 0) == state.attributes.get('hs_color')
|
||||
assert 255 == state.attributes.get('white_value')
|
||||
assert (0.323, 0.329) == state.attributes.get('xy_color')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('rgb_color') == (255, 255, 255)
|
||||
assert state.attributes.get('brightness') == 255
|
||||
assert state.attributes.get('color_temp') == 150
|
||||
assert state.attributes.get('effect') == 'none'
|
||||
assert state.attributes.get('hs_color') == (0, 0)
|
||||
assert state.attributes.get('white_value') == 255
|
||||
assert state.attributes.get('xy_color') == (0.323, 0.329)
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/status', '0')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/status', '1')
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/brightness/status', '100')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert 100 == \
|
||||
light_state.attributes['brightness']
|
||||
assert light_state.attributes['brightness'] == 100
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/color_temp/status', '300')
|
||||
light_state = hass.states.get('light.test')
|
||||
assert 300 == light_state.attributes['color_temp']
|
||||
assert light_state.attributes['color_temp'] == 300
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/effect/status', 'rainbow')
|
||||
light_state = hass.states.get('light.test')
|
||||
assert 'rainbow' == light_state.attributes['effect']
|
||||
assert light_state.attributes['effect'] == 'rainbow'
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/white_value/status',
|
||||
'100')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert 100 == \
|
||||
light_state.attributes['white_value']
|
||||
assert light_state.attributes['white_value'] == 100
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/status', '1')
|
||||
|
||||
@ -299,22 +297,19 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
|
||||
'125,125,125')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert (255, 255, 255) == \
|
||||
light_state.attributes.get('rgb_color')
|
||||
assert light_state.attributes.get('rgb_color') == (255, 255, 255)
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/hs/status',
|
||||
'200,50')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert (200, 50) == \
|
||||
light_state.attributes.get('hs_color')
|
||||
assert light_state.attributes.get('hs_color') == (200, 50)
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/xy/status',
|
||||
'0.675,0.322')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert (0.672, 0.324) == \
|
||||
light_state.attributes.get('xy_color')
|
||||
assert light_state.attributes.get('xy_color') == (0.672, 0.324)
|
||||
|
||||
|
||||
async def test_brightness_controlling_scale(hass, mqtt_mock):
|
||||
@ -336,28 +331,27 @@ async def test_brightness_controlling_scale(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_scale/status', 'on')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('brightness') == 255
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_scale/status', 'off')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_scale/status', 'on')
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_scale/brightness/status', '99')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert 255 == \
|
||||
light_state.attributes['brightness']
|
||||
assert light_state.attributes['brightness'] == 255
|
||||
|
||||
|
||||
async def test_brightness_from_rgb_controlling_scale(hass, mqtt_mock):
|
||||
@ -378,7 +372,7 @@ async def test_brightness_from_rgb_controlling_scale(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
@ -386,12 +380,12 @@ async def test_brightness_from_rgb_controlling_scale(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'test_scale_rgb/rgb/status', '255,0,0')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
assert state.attributes.get('brightness') == 255
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_scale_rgb/rgb/status', '127,0,0')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert 127 == state.attributes.get('brightness')
|
||||
assert state.attributes.get('brightness') == 127
|
||||
|
||||
|
||||
async def test_white_value_controlling_scale(hass, mqtt_mock):
|
||||
@ -413,28 +407,27 @@ async def test_white_value_controlling_scale(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('white_value') is None
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_scale/status', 'on')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 255 == state.attributes.get('white_value')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('white_value') == 255
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_scale/status', 'off')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_scale/status', 'on')
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_scale/white_value/status', '99')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert 255 == \
|
||||
light_state.attributes['white_value']
|
||||
assert light_state.attributes['white_value'] == 255
|
||||
|
||||
|
||||
async def test_controlling_state_via_topic_with_templates(hass, mqtt_mock):
|
||||
@ -471,7 +464,7 @@ async def test_controlling_state_via_topic_with_templates(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
|
||||
@ -489,24 +482,24 @@ async def test_controlling_state_via_topic_with_templates(hass, mqtt_mock):
|
||||
'{"hello": "75"}')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 50 == state.attributes.get('brightness')
|
||||
assert (84, 169, 255) == state.attributes.get('rgb_color')
|
||||
assert 300 == state.attributes.get('color_temp')
|
||||
assert 'rainbow' == state.attributes.get('effect')
|
||||
assert 75 == state.attributes.get('white_value')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('brightness') == 50
|
||||
assert state.attributes.get('rgb_color') == (84, 169, 255)
|
||||
assert state.attributes.get('color_temp') == 300
|
||||
assert state.attributes.get('effect') == 'rainbow'
|
||||
assert state.attributes.get('white_value') == 75
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/hs/status',
|
||||
'{"hello": [100,50]}')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert (100, 50) == state.attributes.get('hs_color')
|
||||
assert state.attributes.get('hs_color') == (100, 50)
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/xy/status',
|
||||
'{"hello": [0.123,0.123]}')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert (0.14, 0.131) == state.attributes.get('xy_color')
|
||||
assert state.attributes.get('xy_color') == (0.14, 0.131)
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
@ -539,12 +532,12 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 95 == state.attributes.get('brightness')
|
||||
assert (100, 100) == state.attributes.get('hs_color')
|
||||
assert 'random' == state.attributes.get('effect')
|
||||
assert 100 == state.attributes.get('color_temp')
|
||||
assert 50 == state.attributes.get('white_value')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('brightness') == 95
|
||||
assert state.attributes.get('hs_color') == (100, 100)
|
||||
assert state.attributes.get('effect') == 'random'
|
||||
assert state.attributes.get('color_temp') == 100
|
||||
assert state.attributes.get('white_value') == 50
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_turn_on(hass, 'light.test')
|
||||
@ -554,7 +547,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
'test_light_rgb/set', 'on', 2, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
common.async_turn_off(hass, 'light.test')
|
||||
await hass.async_block_till_done()
|
||||
@ -563,7 +556,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
'test_light_rgb/set', 'off', 2, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
mqtt_mock.reset_mock()
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
@ -584,12 +577,12 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
], any_order=True)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert (255, 128, 0) == state.attributes['rgb_color']
|
||||
assert 50 == state.attributes['brightness']
|
||||
assert (30.118, 100) == state.attributes['hs_color']
|
||||
assert 80 == state.attributes['white_value']
|
||||
assert (0.611, 0.375) == state.attributes['xy_color']
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes['rgb_color'] == (255, 128, 0)
|
||||
assert state.attributes['brightness'] == 50
|
||||
assert state.attributes['hs_color'] == (30.118, 100)
|
||||
assert state.attributes['white_value'] == 80
|
||||
assert state.attributes['xy_color'] == (0.611, 0.375)
|
||||
|
||||
|
||||
async def test_sending_mqtt_rgb_command_with_template(hass, mqtt_mock):
|
||||
@ -609,7 +602,7 @@ async def test_sending_mqtt_rgb_command_with_template(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 64])
|
||||
await hass.async_block_till_done()
|
||||
@ -620,8 +613,8 @@ async def test_sending_mqtt_rgb_command_with_template(hass, mqtt_mock):
|
||||
], any_order=True)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert (255, 128, 63) == state.attributes['rgb_color']
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes['rgb_color'] == (255, 128, 63)
|
||||
|
||||
|
||||
async def test_sending_mqtt_color_temp_command_with_template(hass, mqtt_mock):
|
||||
@ -640,7 +633,7 @@ async def test_sending_mqtt_color_temp_command_with_template(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test', color_temp=100)
|
||||
await hass.async_block_till_done()
|
||||
@ -651,8 +644,8 @@ async def test_sending_mqtt_color_temp_command_with_template(hass, mqtt_mock):
|
||||
], any_order=True)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 100 == state.attributes['color_temp']
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes['color_temp'] == 100
|
||||
|
||||
|
||||
async def test_show_brightness_if_only_command_topic(hass, mqtt_mock):
|
||||
@ -668,14 +661,14 @@ async def test_show_brightness_if_only_command_topic(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/status', 'ON')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('brightness') == 255
|
||||
|
||||
|
||||
async def test_show_color_temp_only_if_command_topic(hass, mqtt_mock):
|
||||
@ -691,14 +684,14 @@ async def test_show_color_temp_only_if_command_topic(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('color_temp') is None
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/status', 'ON')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 150 == state.attributes.get('color_temp')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('color_temp') == 150
|
||||
|
||||
|
||||
async def test_show_effect_only_if_command_topic(hass, mqtt_mock):
|
||||
@ -714,14 +707,14 @@ async def test_show_effect_only_if_command_topic(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('effect') is None
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/status', 'ON')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 'none' == state.attributes.get('effect')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('effect') == 'none'
|
||||
|
||||
|
||||
async def test_show_hs_if_only_command_topic(hass, mqtt_mock):
|
||||
@ -737,14 +730,14 @@ async def test_show_hs_if_only_command_topic(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('hs_color') is None
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/status', 'ON')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert (0, 0) == state.attributes.get('hs_color')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('hs_color') == (0, 0)
|
||||
|
||||
|
||||
async def test_show_white_value_if_only_command_topic(hass, mqtt_mock):
|
||||
@ -760,14 +753,14 @@ async def test_show_white_value_if_only_command_topic(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('white_value') is None
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/status', 'ON')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 255 == state.attributes.get('white_value')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('white_value') == 255
|
||||
|
||||
|
||||
async def test_show_xy_if_only_command_topic(hass, mqtt_mock):
|
||||
@ -783,14 +776,14 @@ async def test_show_xy_if_only_command_topic(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('xy_color') is None
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb/status', 'ON')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert (0.323, 0.329) == state.attributes.get('xy_color')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('xy_color') == (0.323, 0.329)
|
||||
|
||||
|
||||
async def test_on_command_first(hass, mqtt_mock):
|
||||
@ -806,7 +799,7 @@ async def test_on_command_first(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test', brightness=50)
|
||||
await hass.async_block_till_done()
|
||||
@ -839,7 +832,7 @@ async def test_on_command_last(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test', brightness=50)
|
||||
await hass.async_block_till_done()
|
||||
@ -874,7 +867,7 @@ async def test_on_command_brightness(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
# Turn on w/ no brightness - should set to max
|
||||
common.async_turn_on(hass, 'light.test')
|
||||
@ -927,7 +920,7 @@ async def test_on_command_rgb(hass, mqtt_mock):
|
||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test', brightness=127)
|
||||
await hass.async_block_till_done()
|
||||
@ -962,17 +955,17 @@ async def test_default_availability_payload(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'online')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'offline')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
@ -991,17 +984,17 @@ async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'good')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'nogood')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
@ -1018,7 +1011,7 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '{ "val": "100" }')
|
||||
state = hass.states.get('light.test')
|
||||
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
@ -1076,7 +1069,7 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
await hass.async_block_till_done()
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
|
||||
state = hass.states.get('light.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Change json_attributes_topic
|
||||
async_fire_mqtt_message(hass, 'homeassistant/light/bla/config',
|
||||
@ -1086,12 +1079,12 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
# Verify we are no longer subscribing to the old topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
|
||||
state = hass.states.get('light.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Verify we are subscribing to the new topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
|
||||
state = hass.states.get('light.beer')
|
||||
assert '75' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '75'
|
||||
|
||||
|
||||
async def test_unique_id(hass):
|
||||
|
@ -143,8 +143,8 @@ async def test_no_color_brightness_color_temp_white_val_if_no_topics(
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert 40 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 40
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('color_temp') is None
|
||||
@ -156,7 +156,7 @@ async def test_no_color_brightness_color_temp_white_val_if_no_topics(
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', '{"state":"ON"}')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('color_temp') is None
|
||||
@ -187,8 +187,8 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert 191 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 191
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('color_temp') is None
|
||||
@ -208,68 +208,64 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
|
||||
'"white_value":150}')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
assert 155 == state.attributes.get('color_temp')
|
||||
assert 'colorloop' == state.attributes.get('effect')
|
||||
assert 150 == state.attributes.get('white_value')
|
||||
assert (0.323, 0.329) == state.attributes.get('xy_color')
|
||||
assert (0.0, 0.0) == state.attributes.get('hs_color')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('rgb_color') == (255, 255, 255)
|
||||
assert state.attributes.get('brightness') == 255
|
||||
assert state.attributes.get('color_temp') == 155
|
||||
assert state.attributes.get('effect') == 'colorloop'
|
||||
assert state.attributes.get('white_value') == 150
|
||||
assert state.attributes.get('xy_color') == (0.323, 0.329)
|
||||
assert state.attributes.get('hs_color') == (0.0, 0.0)
|
||||
|
||||
# Turn the light off
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', '{"state":"OFF"}')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb',
|
||||
'{"state":"ON", "brightness":100}')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
|
||||
assert 100 == \
|
||||
light_state.attributes['brightness']
|
||||
assert light_state.attributes['brightness'] == 100
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb',
|
||||
'{"state":"ON", '
|
||||
'"color":{"r":125,"g":125,"b":125}}')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert (255, 255, 255) == \
|
||||
light_state.attributes.get('rgb_color')
|
||||
assert light_state.attributes.get('rgb_color') == (255, 255, 255)
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb',
|
||||
'{"state":"ON", "color":{"x":0.135,"y":0.135}}')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert (0.141, 0.14) == \
|
||||
light_state.attributes.get('xy_color')
|
||||
assert light_state.attributes.get('xy_color') == (0.141, 0.14)
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb',
|
||||
'{"state":"ON", "color":{"h":180,"s":50}}')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert (180.0, 50.0) == \
|
||||
light_state.attributes.get('hs_color')
|
||||
assert light_state.attributes.get('hs_color') == (180.0, 50.0)
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb',
|
||||
'{"state":"ON", "color_temp":155}')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert 155 == light_state.attributes.get('color_temp')
|
||||
assert light_state.attributes.get('color_temp') == 155
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb',
|
||||
'{"state":"ON", "effect":"colorloop"}')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert 'colorloop' == light_state.attributes.get('effect')
|
||||
assert light_state.attributes.get('effect') == 'colorloop'
|
||||
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb',
|
||||
'{"state":"ON", "white_value":155}')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert 155 == light_state.attributes.get('white_value')
|
||||
assert light_state.attributes.get('white_value') == 155
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
@ -301,13 +297,13 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 95 == state.attributes.get('brightness')
|
||||
assert (100, 100) == state.attributes.get('hs_color')
|
||||
assert 'random' == state.attributes.get('effect')
|
||||
assert 100 == state.attributes.get('color_temp')
|
||||
assert 50 == state.attributes.get('white_value')
|
||||
assert 191 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('brightness') == 95
|
||||
assert state.attributes.get('hs_color') == (100, 100)
|
||||
assert state.attributes.get('effect') == 'random'
|
||||
assert state.attributes.get('color_temp') == 100
|
||||
assert state.attributes.get('white_value') == 50
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 191
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_turn_on(hass, 'light.test')
|
||||
@ -317,7 +313,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
'test_light_rgb/set', '{"state": "ON"}', 2, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
common.async_turn_off(hass, 'light.test')
|
||||
await hass.async_block_till_done()
|
||||
@ -326,7 +322,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
'test_light_rgb/set', '{"state": "OFF"}', 2, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
mqtt_mock.reset_mock()
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
@ -362,12 +358,12 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
], any_order=True)
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert (255, 128, 0) == state.attributes['rgb_color']
|
||||
assert 50 == state.attributes['brightness']
|
||||
assert (30.118, 100) == state.attributes['hs_color']
|
||||
assert 80 == state.attributes['white_value']
|
||||
assert (0.611, 0.375) == state.attributes['xy_color']
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes['rgb_color'] == (255, 128, 0)
|
||||
assert state.attributes['brightness'] == 50
|
||||
assert state.attributes['hs_color'] == (30.118, 100)
|
||||
assert state.attributes['white_value'] == 80
|
||||
assert state.attributes['xy_color'] == (0.611, 0.375)
|
||||
|
||||
|
||||
async def test_sending_hs_color(hass, mqtt_mock):
|
||||
@ -384,7 +380,7 @@ async def test_sending_hs_color(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
mqtt_mock.reset_mock()
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
@ -430,7 +426,7 @@ async def test_sending_rgb_color_no_brightness(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
@ -473,7 +469,7 @@ async def test_sending_rgb_color_with_brightness(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
@ -519,7 +515,7 @@ async def test_sending_xy_color(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
@ -566,8 +562,8 @@ async def test_flash_short_and_long(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert 40 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 40
|
||||
|
||||
common.async_turn_on(hass, 'light.test', flash='short')
|
||||
await hass.async_block_till_done()
|
||||
@ -577,7 +573,7 @@ async def test_flash_short_and_long(hass, mqtt_mock):
|
||||
'{"state": "ON", "flash": 5}'), 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
common.async_turn_on(hass, 'light.test', flash='long')
|
||||
await hass.async_block_till_done()
|
||||
@ -587,7 +583,7 @@ async def test_flash_short_and_long(hass, mqtt_mock):
|
||||
'{"state": "ON", "flash": 15}'), 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
|
||||
async def test_transition(hass, mqtt_mock):
|
||||
@ -603,8 +599,8 @@ async def test_transition(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert 40 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 40
|
||||
|
||||
common.async_turn_on(hass, 'light.test', transition=15)
|
||||
await hass.async_block_till_done()
|
||||
@ -614,7 +610,7 @@ async def test_transition(hass, mqtt_mock):
|
||||
'{"state": "ON", "transition": 15}'), 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
common.async_turn_off(hass, 'light.test', transition=30)
|
||||
await hass.async_block_till_done()
|
||||
@ -624,7 +620,7 @@ async def test_transition(hass, mqtt_mock):
|
||||
'{"state": "OFF", "transition": 30}'), 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_brightness_scale(hass, mqtt_mock):
|
||||
@ -642,7 +638,7 @@ async def test_brightness_scale(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
@ -650,16 +646,16 @@ async def test_brightness_scale(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'test_light_bright_scale', '{"state":"ON"}')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('brightness') == 255
|
||||
|
||||
# Turn on the light with brightness
|
||||
async_fire_mqtt_message(hass, 'test_light_bright_scale',
|
||||
'{"state":"ON", "brightness": 99}')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('brightness') == 255
|
||||
|
||||
|
||||
async def test_invalid_color_brightness_and_white_values(hass, mqtt_mock):
|
||||
@ -679,8 +675,8 @@ async def test_invalid_color_brightness_and_white_values(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert 185 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 185
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('white_value') is None
|
||||
@ -694,10 +690,10 @@ async def test_invalid_color_brightness_and_white_values(hass, mqtt_mock):
|
||||
'"white_value": 255}')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
assert 255 == state.attributes.get('white_value')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('rgb_color') == (255, 255, 255)
|
||||
assert state.attributes.get('brightness') == 255
|
||||
assert state.attributes.get('white_value') == 255
|
||||
|
||||
# Bad color values
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb',
|
||||
@ -706,8 +702,8 @@ async def test_invalid_color_brightness_and_white_values(hass, mqtt_mock):
|
||||
|
||||
# Color should not have changed
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('rgb_color') == (255, 255, 255)
|
||||
|
||||
# Bad brightness values
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb',
|
||||
@ -716,8 +712,8 @@ async def test_invalid_color_brightness_and_white_values(hass, mqtt_mock):
|
||||
|
||||
# Brightness should not have changed
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('brightness') == 255
|
||||
|
||||
# Bad white value
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb',
|
||||
@ -726,8 +722,8 @@ async def test_invalid_color_brightness_and_white_values(hass, mqtt_mock):
|
||||
|
||||
# White value should not have changed
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 255 == state.attributes.get('white_value')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('white_value') == 255
|
||||
|
||||
|
||||
async def test_default_availability_payload(hass, mqtt_mock):
|
||||
@ -744,17 +740,17 @@ async def test_default_availability_payload(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'online')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'offline')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
@ -773,17 +769,17 @@ async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'good')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'nogood')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
@ -801,7 +797,7 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '{ "val": "100" }')
|
||||
state = hass.states.get('light.test')
|
||||
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
@ -863,7 +859,7 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
await hass.async_block_till_done()
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
|
||||
state = hass.states.get('light.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Change json_attributes_topic
|
||||
async_fire_mqtt_message(hass, 'homeassistant/light/bla/config',
|
||||
@ -873,12 +869,12 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
# Verify we are no longer subscribing to the old topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
|
||||
state = hass.states.get('light.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Verify we are subscribing to the new topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
|
||||
state = hass.states.get('light.beer')
|
||||
assert '75' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '75'
|
||||
|
||||
|
||||
async def test_unique_id(hass):
|
||||
|
@ -112,7 +112,7 @@ async def test_state_change_via_topic(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('color_temp') is None
|
||||
@ -122,7 +122,7 @@ async def test_state_change_via_topic(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', 'on')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('color_temp') is None
|
||||
@ -165,7 +165,7 @@ async def test_state_brightness_color_effect_temp_white_change_via_topic(
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('effect') is None
|
||||
@ -178,50 +178,48 @@ async def test_state_brightness_color_effect_temp_white_change_via_topic(
|
||||
'on,255,145,123,255-128-64,')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert (255, 128, 63) == state.attributes.get('rgb_color')
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
assert 145 == state.attributes.get('color_temp')
|
||||
assert 123 == state.attributes.get('white_value')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('rgb_color') == (255, 128, 63)
|
||||
assert state.attributes.get('brightness') == 255
|
||||
assert state.attributes.get('color_temp') == 145
|
||||
assert state.attributes.get('white_value') == 123
|
||||
assert state.attributes.get('effect') is None
|
||||
|
||||
# turn the light off
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', 'off')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
# lower the brightness
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', 'on,100')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert 100 == light_state.attributes['brightness']
|
||||
assert light_state.attributes['brightness'] == 100
|
||||
|
||||
# change the color temp
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', 'on,,195')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert 195 == light_state.attributes['color_temp']
|
||||
assert light_state.attributes['color_temp'] == 195
|
||||
|
||||
# change the color
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', 'on,,,,41-42-43')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert (243, 249, 255) == \
|
||||
light_state.attributes.get('rgb_color')
|
||||
assert light_state.attributes.get('rgb_color') == (243, 249, 255)
|
||||
|
||||
# change the white value
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', 'on,,,134')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert 134 == light_state.attributes['white_value']
|
||||
assert light_state.attributes['white_value'] == 134
|
||||
|
||||
# change the effect
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb',
|
||||
'on,,,,41-42-43,rainbow')
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', 'on,,,,41-42-43,rainbow')
|
||||
|
||||
light_state = hass.states.get('light.test')
|
||||
assert 'rainbow' == light_state.attributes.get('effect')
|
||||
assert light_state.attributes.get('effect') == 'rainbow'
|
||||
|
||||
|
||||
async def test_optimistic(hass, mqtt_mock):
|
||||
@ -256,12 +254,12 @@ async def test_optimistic(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 95 == state.attributes.get('brightness')
|
||||
assert (100, 100) == state.attributes.get('hs_color')
|
||||
assert 'random' == state.attributes.get('effect')
|
||||
assert 100 == state.attributes.get('color_temp')
|
||||
assert 50 == state.attributes.get('white_value')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('brightness') == 95
|
||||
assert state.attributes.get('hs_color') == (100, 100)
|
||||
assert state.attributes.get('effect') == 'random'
|
||||
assert state.attributes.get('color_temp') == 100
|
||||
assert state.attributes.get('white_value') == 50
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
|
||||
@ -281,7 +279,7 @@ async def test_flash(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_transition(hass, mqtt_mock):
|
||||
@ -299,7 +297,7 @@ async def test_transition(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_invalid_values(hass, mqtt_mock):
|
||||
@ -336,7 +334,7 @@ async def test_invalid_values(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('color_temp') is None
|
||||
@ -349,54 +347,54 @@ async def test_invalid_values(hass, mqtt_mock):
|
||||
'on,255,215,222,255-255-255,rainbow')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
assert 215 == state.attributes.get('color_temp')
|
||||
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||
assert 222 == state.attributes.get('white_value')
|
||||
assert 'rainbow' == state.attributes.get('effect')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get('brightness') == 255
|
||||
assert state.attributes.get('color_temp') == 215
|
||||
assert state.attributes.get('rgb_color') == (255, 255, 255)
|
||||
assert state.attributes.get('white_value') == 222
|
||||
assert state.attributes.get('effect') == 'rainbow'
|
||||
|
||||
# bad state value
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', 'offf')
|
||||
|
||||
# state should not have changed
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
# bad brightness values
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', 'on,off,255-255-255')
|
||||
|
||||
# brightness should not have changed
|
||||
state = hass.states.get('light.test')
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
assert state.attributes.get('brightness') == 255
|
||||
|
||||
# bad color temp values
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', 'on,,off,255-255-255')
|
||||
|
||||
# color temp should not have changed
|
||||
state = hass.states.get('light.test')
|
||||
assert 215 == state.attributes.get('color_temp')
|
||||
assert state.attributes.get('color_temp') == 215
|
||||
|
||||
# bad color values
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', 'on,255,a-b-c')
|
||||
|
||||
# color should not have changed
|
||||
state = hass.states.get('light.test')
|
||||
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||
assert state.attributes.get('rgb_color') == (255, 255, 255)
|
||||
|
||||
# bad white value values
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', 'on,,,off,255-255-255')
|
||||
|
||||
# white value should not have changed
|
||||
state = hass.states.get('light.test')
|
||||
assert 222 == state.attributes.get('white_value')
|
||||
assert state.attributes.get('white_value') == 222
|
||||
|
||||
# bad effect value
|
||||
async_fire_mqtt_message(hass, 'test_light_rgb', 'on,255,a-b-c,white')
|
||||
|
||||
# effect should not have changed
|
||||
state = hass.states.get('light.test')
|
||||
assert 'rainbow' == state.attributes.get('effect')
|
||||
assert state.attributes.get('effect') == 'rainbow'
|
||||
|
||||
|
||||
async def test_default_availability_payload(hass, mqtt_mock):
|
||||
@ -414,17 +412,17 @@ async def test_default_availability_payload(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'online')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'offline')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
@ -444,17 +442,17 @@ async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'good')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'nogood')
|
||||
|
||||
state = hass.states.get('light.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
@ -474,7 +472,7 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '{ "val": "100" }')
|
||||
state = hass.states.get('light.test')
|
||||
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
@ -544,7 +542,7 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
await hass.async_block_till_done()
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
|
||||
state = hass.states.get('light.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Change json_attributes_topic
|
||||
async_fire_mqtt_message(hass, 'homeassistant/light/bla/config',
|
||||
@ -554,12 +552,12 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
# Verify we are no longer subscribing to the old topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
|
||||
state = hass.states.get('light.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Verify we are subscribing to the new topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
|
||||
state = hass.states.get('light.beer')
|
||||
assert '75' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '75'
|
||||
|
||||
|
||||
async def test_unique_id(hass):
|
||||
|
@ -218,7 +218,7 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '{ "val": "100" }')
|
||||
state = hass.states.get('lock.test')
|
||||
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
@ -276,7 +276,7 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
await hass.async_block_till_done()
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
|
||||
state = hass.states.get('lock.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Change json_attributes_topic
|
||||
async_fire_mqtt_message(hass, 'homeassistant/lock/bla/config',
|
||||
@ -286,12 +286,12 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
# Verify we are no longer subscribing to the old topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
|
||||
state = hass.states.get('lock.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Verify we are subscribing to the new topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
|
||||
state = hass.states.get('lock.beer')
|
||||
assert '75' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '75'
|
||||
|
||||
|
||||
async def test_unique_id(hass):
|
||||
|
@ -30,9 +30,8 @@ async def test_setting_sensor_value_via_mqtt_message(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'test-topic', '100')
|
||||
state = hass.states.get('sensor.test')
|
||||
|
||||
assert '100' == state.state
|
||||
assert 'fav unit' == \
|
||||
state.attributes.get('unit_of_measurement')
|
||||
assert state.state == '100'
|
||||
assert state.attributes.get('unit_of_measurement') == 'fav unit'
|
||||
|
||||
|
||||
async def test_setting_sensor_value_expires(hass, mqtt_mock, caplog):
|
||||
@ -49,7 +48,7 @@ async def test_setting_sensor_value_expires(hass, mqtt_mock, caplog):
|
||||
})
|
||||
|
||||
state = hass.states.get('sensor.test')
|
||||
assert 'unknown' == state.state
|
||||
assert state.state == 'unknown'
|
||||
|
||||
now = datetime(2017, 1, 1, 1, tzinfo=dt_util.UTC)
|
||||
with patch(('homeassistant.helpers.event.'
|
||||
@ -60,7 +59,7 @@ async def test_setting_sensor_value_expires(hass, mqtt_mock, caplog):
|
||||
|
||||
# Value was set correctly.
|
||||
state = hass.states.get('sensor.test')
|
||||
assert '100' == state.state
|
||||
assert state.state == '100'
|
||||
|
||||
# Time jump +3s
|
||||
now = now + timedelta(seconds=3)
|
||||
@ -69,7 +68,7 @@ async def test_setting_sensor_value_expires(hass, mqtt_mock, caplog):
|
||||
|
||||
# Value is not yet expired
|
||||
state = hass.states.get('sensor.test')
|
||||
assert '100' == state.state
|
||||
assert state.state == '100'
|
||||
|
||||
# Next message resets timer
|
||||
with patch(('homeassistant.helpers.event.'
|
||||
@ -80,7 +79,7 @@ async def test_setting_sensor_value_expires(hass, mqtt_mock, caplog):
|
||||
|
||||
# Value was updated correctly.
|
||||
state = hass.states.get('sensor.test')
|
||||
assert '101' == state.state
|
||||
assert state.state == '101'
|
||||
|
||||
# Time jump +3s
|
||||
now = now + timedelta(seconds=3)
|
||||
@ -89,7 +88,7 @@ async def test_setting_sensor_value_expires(hass, mqtt_mock, caplog):
|
||||
|
||||
# Value is not yet expired
|
||||
state = hass.states.get('sensor.test')
|
||||
assert '101' == state.state
|
||||
assert state.state == '101'
|
||||
|
||||
# Time jump +2s
|
||||
now = now + timedelta(seconds=2)
|
||||
@ -98,7 +97,7 @@ async def test_setting_sensor_value_expires(hass, mqtt_mock, caplog):
|
||||
|
||||
# Value is expired now
|
||||
state = hass.states.get('sensor.test')
|
||||
assert 'unknown' == state.state
|
||||
assert state.state == 'unknown'
|
||||
|
||||
|
||||
async def test_setting_sensor_value_via_mqtt_json_message(hass, mqtt_mock):
|
||||
@ -116,7 +115,7 @@ async def test_setting_sensor_value_via_mqtt_json_message(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'test-topic', '{ "val": "100" }')
|
||||
state = hass.states.get('sensor.test')
|
||||
|
||||
assert '100' == state.state
|
||||
assert state.state == '100'
|
||||
|
||||
|
||||
async def test_force_update_disabled(hass, mqtt_mock):
|
||||
@ -140,11 +139,11 @@ async def test_force_update_disabled(hass, mqtt_mock):
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', '100')
|
||||
await hass.async_block_till_done()
|
||||
assert 1 == len(events)
|
||||
assert len(events) == 1
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', '100')
|
||||
await hass.async_block_till_done()
|
||||
assert 1 == len(events)
|
||||
assert len(events) == 1
|
||||
|
||||
|
||||
async def test_force_update_enabled(hass, mqtt_mock):
|
||||
@ -169,11 +168,11 @@ async def test_force_update_enabled(hass, mqtt_mock):
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', '100')
|
||||
await hass.async_block_till_done()
|
||||
assert 1 == len(events)
|
||||
assert len(events) == 1
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', '100')
|
||||
await hass.async_block_till_done()
|
||||
assert 2 == len(events)
|
||||
assert len(events) == 2
|
||||
|
||||
|
||||
async def test_default_availability_payload(hass, mqtt_mock):
|
||||
@ -188,17 +187,17 @@ async def test_default_availability_payload(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('sensor.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'online')
|
||||
|
||||
state = hass.states.get('sensor.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'offline')
|
||||
|
||||
state = hass.states.get('sensor.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
@ -215,17 +214,17 @@ async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('sensor.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'good')
|
||||
|
||||
state = hass.states.get('sensor.test')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'nogood')
|
||||
|
||||
state = hass.states.get('sensor.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_setting_sensor_attribute_via_legacy_mqtt_json_message(
|
||||
@ -244,8 +243,7 @@ async def test_setting_sensor_attribute_via_legacy_mqtt_json_message(
|
||||
async_fire_mqtt_message(hass, 'test-topic', '{ "val": "100" }')
|
||||
state = hass.states.get('sensor.test')
|
||||
|
||||
assert '100' == \
|
||||
state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
|
||||
async def test_update_with_legacy_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
@ -302,9 +300,8 @@ async def test_update_with_legacy_json_attrs_and_template(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'test-topic', '{ "val": "100" }')
|
||||
state = hass.states.get('sensor.test')
|
||||
|
||||
assert '100' == \
|
||||
state.attributes.get('val')
|
||||
assert '100' == state.state
|
||||
assert state.attributes.get('val') == '100'
|
||||
assert state.state == '100'
|
||||
|
||||
|
||||
async def test_invalid_device_class(hass, mqtt_mock):
|
||||
@ -358,7 +355,7 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '{ "val": "100" }')
|
||||
state = hass.states.get('sensor.test')
|
||||
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
|
||||
async def test_setting_attribute_with_template(hass, mqtt_mock):
|
||||
@ -377,8 +374,8 @@ async def test_setting_attribute_with_template(hass, mqtt_mock):
|
||||
{"Timer1": {"Arm": 0, "Time": "22:18"}}))
|
||||
state = hass.states.get('sensor.test')
|
||||
|
||||
assert 0 == state.attributes.get('Arm')
|
||||
assert '22:18' == state.attributes.get('Time')
|
||||
assert state.attributes.get('Arm') == 0
|
||||
assert state.attributes.get('Time') == '22:18'
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
@ -436,7 +433,7 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
await hass.async_block_till_done()
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
|
||||
state = hass.states.get('sensor.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Change json_attributes_topic
|
||||
async_fire_mqtt_message(hass, 'homeassistant/sensor/bla/config',
|
||||
@ -446,12 +443,12 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
# Verify we are no longer subscribing to the old topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
|
||||
state = hass.states.get('sensor.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Verify we are subscribing to the new topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
|
||||
state = hass.states.get('sensor.beer')
|
||||
assert '75' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '75'
|
||||
|
||||
|
||||
async def test_unique_id(hass):
|
||||
|
@ -33,24 +33,24 @@ async def test_subscribe_topics(hass, mqtt_mock, caplog):
|
||||
'msg_callback': record_calls2}})
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic1', 'test-payload1')
|
||||
assert 1 == len(calls1)
|
||||
assert 'test-topic1' == calls1[0][0].topic
|
||||
assert 'test-payload1' == calls1[0][0].payload
|
||||
assert 0 == len(calls2)
|
||||
assert len(calls1) == 1
|
||||
assert calls1[0][0].topic == 'test-topic1'
|
||||
assert calls1[0][0].payload == 'test-payload1'
|
||||
assert len(calls2) == 0
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic2', 'test-payload2')
|
||||
assert 1 == len(calls1)
|
||||
assert 1 == len(calls2)
|
||||
assert 'test-topic2' == calls2[0][0].topic
|
||||
assert 'test-payload2' == calls2[0][0].payload
|
||||
assert len(calls1) == 1
|
||||
assert len(calls2) == 1
|
||||
assert calls2[0][0].topic == 'test-topic2'
|
||||
assert calls2[0][0].payload == 'test-payload2'
|
||||
|
||||
await async_unsubscribe_topics(hass, sub_state)
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic1', 'test-payload')
|
||||
async_fire_mqtt_message(hass, 'test-topic2', 'test-payload')
|
||||
|
||||
assert 1 == len(calls1)
|
||||
assert 1 == len(calls2)
|
||||
assert len(calls1) == 1
|
||||
assert len(calls2) == 1
|
||||
|
||||
|
||||
async def test_modify_topics(hass, mqtt_mock, caplog):
|
||||
@ -78,12 +78,12 @@ async def test_modify_topics(hass, mqtt_mock, caplog):
|
||||
'msg_callback': record_calls2}})
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic1', 'test-payload')
|
||||
assert 1 == len(calls1)
|
||||
assert 0 == len(calls2)
|
||||
assert len(calls1) == 1
|
||||
assert len(calls2) == 0
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic2', 'test-payload')
|
||||
assert 1 == len(calls1)
|
||||
assert 1 == len(calls2)
|
||||
assert len(calls1) == 1
|
||||
assert len(calls2) == 1
|
||||
|
||||
sub_state = await async_subscribe_topics(
|
||||
hass, sub_state,
|
||||
@ -92,22 +92,22 @@ async def test_modify_topics(hass, mqtt_mock, caplog):
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic1', 'test-payload')
|
||||
async_fire_mqtt_message(hass, 'test-topic2', 'test-payload')
|
||||
assert 1 == len(calls1)
|
||||
assert 1 == len(calls2)
|
||||
assert len(calls1) == 1
|
||||
assert len(calls2) == 1
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic1_1', 'test-payload')
|
||||
assert 2 == len(calls1)
|
||||
assert 'test-topic1_1' == calls1[1][0].topic
|
||||
assert 'test-payload' == calls1[1][0].payload
|
||||
assert 1 == len(calls2)
|
||||
assert len(calls1) == 2
|
||||
assert calls1[1][0].topic == 'test-topic1_1'
|
||||
assert calls1[1][0].payload == 'test-payload'
|
||||
assert len(calls2) == 1
|
||||
|
||||
await async_unsubscribe_topics(hass, sub_state)
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic1_1', 'test-payload')
|
||||
async_fire_mqtt_message(hass, 'test-topic2', 'test-payload')
|
||||
|
||||
assert 2 == len(calls1)
|
||||
assert 1 == len(calls2)
|
||||
assert len(calls1) == 2
|
||||
assert len(calls2) == 1
|
||||
|
||||
|
||||
async def test_qos_encoding_default(hass, mqtt_mock, caplog):
|
||||
|
@ -38,18 +38,18 @@ async def test_controlling_state_via_topic(hass, mock_publish):
|
||||
})
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
async_fire_mqtt_message(hass, 'state-topic', '1')
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
async_fire_mqtt_message(hass, 'state-topic', '0')
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_and_optimistic(hass, mock_publish):
|
||||
@ -71,7 +71,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mock_publish):
|
||||
})
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.turn_on(hass, 'switch.test')
|
||||
@ -81,7 +81,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mock_publish):
|
||||
'command-topic', 'beer on', 2, False)
|
||||
mock_publish.async_publish.reset_mock()
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
common.turn_off(hass, 'switch.test')
|
||||
await hass.async_block_till_done()
|
||||
@ -90,7 +90,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mock_publish):
|
||||
mock_publish.async_publish.assert_called_once_with(
|
||||
'command-topic', 'beer off', 2, False)
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_controlling_state_via_topic_and_json_message(
|
||||
@ -109,17 +109,17 @@ async def test_controlling_state_via_topic_and_json_message(
|
||||
})
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
async_fire_mqtt_message(hass, 'state-topic', '{"val":"beer on"}')
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
async_fire_mqtt_message(hass, 'state-topic', '{"val":"beer off"}')
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_default_availability_payload(hass, mock_publish):
|
||||
@ -137,28 +137,28 @@ async def test_default_availability_payload(hass, mock_publish):
|
||||
})
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability_topic', 'online')
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability_topic', 'offline')
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'state-topic', '1')
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability_topic', 'online')
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
|
||||
async def test_custom_availability_payload(hass, mock_publish):
|
||||
@ -178,28 +178,28 @@ async def test_custom_availability_payload(hass, mock_publish):
|
||||
})
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability_topic', 'good')
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability_topic', 'nogood')
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'state-topic', '1')
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability_topic', 'good')
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
|
||||
async def test_custom_state_payload(hass, mock_publish):
|
||||
@ -218,18 +218,18 @@ async def test_custom_state_payload(hass, mock_publish):
|
||||
})
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
async_fire_mqtt_message(hass, 'state-topic', 'HIGH')
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_ON == state.state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
async_fire_mqtt_message(hass, 'state-topic', 'LOW')
|
||||
|
||||
state = hass.states.get('switch.test')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
@ -246,7 +246,7 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '{ "val": "100" }')
|
||||
state = hass.states.get('switch.test')
|
||||
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
@ -304,7 +304,7 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
await hass.async_block_till_done()
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
|
||||
state = hass.states.get('switch.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Change json_attributes_topic
|
||||
async_fire_mqtt_message(hass, 'homeassistant/switch/bla/config',
|
||||
@ -314,12 +314,12 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
# Verify we are no longer subscribing to the old topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
|
||||
state = hass.states.get('switch.beer')
|
||||
assert '100' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Verify we are subscribing to the new topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
|
||||
state = hass.states.get('switch.beer')
|
||||
assert '75' == state.attributes.get('val')
|
||||
assert state.attributes.get('val') == '75'
|
||||
|
||||
|
||||
async def test_unique_id(hass):
|
||||
|
Loading…
x
Reference in New Issue
Block a user