Convert some test helpers to coroutines and adjust tests (#23352)
* Convert some test helpers to coroutines * Fix tests
This commit is contained in:
1 parent
86b017e2f0
commit
5376e15286
24 files changed
+498
-991
No files matched your search
@@ -92,8 +92,7 @@ async def test_arm_home_publishes_mqtt(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
common.async_alarm_arm_home(hass)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_alarm_arm_home(hass)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'alarm/command', 'ARM_HOME', 0, False)
|
||||
|
||||
@@ -116,8 +115,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()
|
||||
await common.async_alarm_arm_home(hass, 'abcd')
|
||||
assert mqtt_mock.async_publish.call_count == call_count
|
||||
|
||||
|
||||
@@ -137,8 +135,7 @@ async def test_arm_home_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
common.async_alarm_arm_home(hass)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_alarm_arm_home(hass)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'alarm/command', 'ARM_HOME', 0, False)
|
||||
|
||||
@@ -154,8 +151,7 @@ async def test_arm_away_publishes_mqtt(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
common.async_alarm_arm_away(hass)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_alarm_arm_away(hass)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'alarm/command', 'ARM_AWAY', 0, False)
|
||||
|
||||
@@ -178,8 +174,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()
|
||||
await common.async_alarm_arm_away(hass, 'abcd')
|
||||
assert mqtt_mock.async_publish.call_count == call_count
|
||||
|
||||
|
||||
@@ -199,8 +194,7 @@ async def test_arm_away_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
common.async_alarm_arm_away(hass)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_alarm_arm_away(hass)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'alarm/command', 'ARM_AWAY', 0, False)
|
||||
|
||||
@@ -216,8 +210,7 @@ async def test_arm_night_publishes_mqtt(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
common.async_alarm_arm_night(hass)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_alarm_arm_night(hass)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'alarm/command', 'ARM_NIGHT', 0, False)
|
||||
|
||||
@@ -240,8 +233,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()
|
||||
await common.async_alarm_arm_night(hass, 'abcd')
|
||||
assert mqtt_mock.async_publish.call_count == call_count
|
||||
|
||||
|
||||
@@ -261,8 +253,7 @@ async def test_arm_night_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
common.async_alarm_arm_night(hass)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_alarm_arm_night(hass)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'alarm/command', 'ARM_NIGHT', 0, False)
|
||||
|
||||
@@ -278,8 +269,7 @@ async def test_disarm_publishes_mqtt(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
common.async_alarm_disarm(hass)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_alarm_disarm(hass)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'alarm/command', 'DISARM', 0, False)
|
||||
|
||||
@@ -301,8 +291,7 @@ async def test_disarm_publishes_mqtt_with_template(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
common.async_alarm_disarm(hass, 1234)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_alarm_disarm(hass, 1234)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'alarm/command', '{\"action\":\"DISARM\",\"code\":\"1234\"}',
|
||||
0,
|
||||
@@ -325,8 +314,7 @@ async def test_disarm_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
|
||||
}
|
||||
})
|
||||
|
||||
common.async_alarm_disarm(hass)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_alarm_disarm(hass)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'alarm/command', 'DISARM', 0, False)
|
||||
|
||||
@@ -349,8 +337,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()
|
||||
await common.async_alarm_disarm(hass, 'abcd')
|
||||
assert mqtt_mock.async_publish.call_count == call_count
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
"""The tests for the mqtt climate component."""
|
||||
import copy
|
||||
import json
|
||||
import pytest
|
||||
import unittest
|
||||
from unittest.mock import ANY
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import mqtt
|
||||
from homeassistant.components.climate import (
|
||||
DEFAULT_MAX_TEMP, DEFAULT_MIN_TEMP)
|
||||
@@ -89,11 +92,11 @@ async def test_set_operation_bad_attr_and_state(hass, mqtt_mock, caplog):
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
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()
|
||||
with pytest.raises(vol.Invalid) as excinfo:
|
||||
await common.async_set_operation_mode(hass, None, ENTITY_CLIMATE)
|
||||
assert ("string value is None for dictionary value @ "
|
||||
"data['operation_mode']")\
|
||||
in caplog.text
|
||||
in str(excinfo.value)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('operation_mode') == 'off'
|
||||
assert state.state == 'off'
|
||||
@@ -106,8 +109,7 @@ async def test_set_operation(hass, mqtt_mock):
|
||||
state = hass.states.get(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()
|
||||
await common.async_set_operation_mode(hass, 'cool', ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('operation_mode') == 'cool'
|
||||
assert state.state == 'cool'
|
||||
@@ -125,8 +127,7 @@ async def test_set_operation_pessimistic(hass, mqtt_mock):
|
||||
assert state.attributes.get('operation_mode') is None
|
||||
assert state.state == 'unknown'
|
||||
|
||||
common.async_set_operation_mode(hass, 'cool', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_operation_mode(hass, 'cool', ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('operation_mode') is None
|
||||
assert state.state == 'unknown'
|
||||
@@ -151,8 +152,7 @@ async def test_set_operation_with_power_command(hass, mqtt_mock):
|
||||
state = hass.states.get(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()
|
||||
await common.async_set_operation_mode(hass, 'on', ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('operation_mode') == 'on'
|
||||
assert state.state == 'on'
|
||||
@@ -162,8 +162,7 @@ async def test_set_operation_with_power_command(hass, mqtt_mock):
|
||||
])
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.async_set_operation_mode(hass, 'off', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_operation_mode(hass, 'off', ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('operation_mode') == 'off'
|
||||
assert state.state == 'off'
|
||||
@@ -180,10 +179,10 @@ async def test_set_fan_mode_bad_attr(hass, mqtt_mock, caplog):
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('fan_mode') == 'low'
|
||||
common.async_set_fan_mode(hass, None, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
with pytest.raises(vol.Invalid) as excinfo:
|
||||
await common.async_set_fan_mode(hass, None, ENTITY_CLIMATE)
|
||||
assert "string value is None for dictionary value @ data['fan_mode']"\
|
||||
in caplog.text
|
||||
in str(excinfo.value)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('fan_mode') == 'low'
|
||||
|
||||
@@ -197,8 +196,7 @@ async def test_set_fan_mode_pessimistic(hass, mqtt_mock):
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('fan_mode') is None
|
||||
|
||||
common.async_set_fan_mode(hass, 'high', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_fan_mode(hass, 'high', ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('fan_mode') is None
|
||||
|
||||
@@ -217,8 +215,7 @@ async def test_set_fan_mode(hass, mqtt_mock):
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('fan_mode') == 'low'
|
||||
common.async_set_fan_mode(hass, 'high', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_fan_mode(hass, 'high', ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'fan-mode-topic', 'high', 0, False)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
@@ -231,10 +228,10 @@ async def test_set_swing_mode_bad_attr(hass, mqtt_mock, caplog):
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('swing_mode') == 'off'
|
||||
common.async_set_swing_mode(hass, None, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
with pytest.raises(vol.Invalid) as excinfo:
|
||||
await common.async_set_swing_mode(hass, None, ENTITY_CLIMATE)
|
||||
assert "string value is None for dictionary value @ data['swing_mode']"\
|
||||
in caplog.text
|
||||
in str(excinfo.value)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('swing_mode') == 'off'
|
||||
|
||||
@@ -248,8 +245,7 @@ async def test_set_swing_pessimistic(hass, mqtt_mock):
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('swing_mode') is None
|
||||
|
||||
common.async_set_swing_mode(hass, 'on', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_swing_mode(hass, 'on', ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('swing_mode') is None
|
||||
|
||||
@@ -268,8 +264,7 @@ async def test_set_swing(hass, mqtt_mock):
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('swing_mode') == 'off'
|
||||
common.async_set_swing_mode(hass, 'on', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_swing_mode(hass, 'on', ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'swing-mode-topic', 'on', 0, False)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
@@ -282,16 +277,14 @@ async def test_set_target_temperature(hass, mqtt_mock):
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('temperature') == 21
|
||||
common.async_set_operation_mode(hass, 'heat', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_operation_mode(hass, 'heat', ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
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()
|
||||
common.async_set_temperature(hass, temperature=47,
|
||||
entity_id=ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_temperature(hass, temperature=47,
|
||||
entity_id=ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('temperature') == 47
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
@@ -299,10 +292,9 @@ async def test_set_target_temperature(hass, mqtt_mock):
|
||||
|
||||
# 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',
|
||||
entity_id=ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_temperature(hass, temperature=21,
|
||||
operation_mode='cool',
|
||||
entity_id=ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('operation_mode') == 'cool'
|
||||
assert state.attributes.get('temperature') == 21
|
||||
@@ -321,11 +313,9 @@ async def test_set_target_temperature_pessimistic(hass, mqtt_mock):
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('temperature') is None
|
||||
common.async_set_operation_mode(hass, 'heat', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
common.async_set_temperature(hass, temperature=47,
|
||||
entity_id=ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_operation_mode(hass, 'heat', ENTITY_CLIMATE)
|
||||
await common.async_set_temperature(hass, temperature=47,
|
||||
entity_id=ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('temperature') is None
|
||||
|
||||
@@ -342,10 +332,9 @@ async def test_set_target_temperature_low_high(hass, mqtt_mock):
|
||||
"""Test setting the low/high target temperature."""
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
||||
|
||||
common.async_set_temperature(hass, target_temp_low=20,
|
||||
target_temp_high=23,
|
||||
entity_id=ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_temperature(hass, target_temp_low=20,
|
||||
target_temp_high=23,
|
||||
entity_id=ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('target_temp_low') == 20
|
||||
assert state.attributes.get('target_temp_high') == 23
|
||||
@@ -367,10 +356,9 @@ async def test_set_target_temperature_low_highpessimistic(hass, mqtt_mock):
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('target_temp_low') is None
|
||||
assert state.attributes.get('target_temp_high') is None
|
||||
common.async_set_temperature(hass, target_temp_low=20,
|
||||
target_temp_high=23,
|
||||
entity_id=ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_temperature(hass, target_temp_low=20,
|
||||
target_temp_high=23,
|
||||
entity_id=ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('target_temp_low') is None
|
||||
assert state.attributes.get('target_temp_high') is None
|
||||
@@ -414,8 +402,7 @@ async def test_set_away_mode_pessimistic(hass, mqtt_mock):
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('away_mode') == 'off'
|
||||
|
||||
common.async_set_away_mode(hass, True, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_away_mode(hass, True, ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('away_mode') == 'off'
|
||||
|
||||
@@ -442,16 +429,14 @@ async def test_set_away_mode(hass, mqtt_mock):
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('away_mode') == 'off'
|
||||
common.async_set_away_mode(hass, True, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_away_mode(hass, True, ENTITY_CLIMATE)
|
||||
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 state.attributes.get('away_mode') == 'on'
|
||||
|
||||
common.async_set_away_mode(hass, False, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_away_mode(hass, False, ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'away-mode-topic', 'AUS', 0, False)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
@@ -467,8 +452,7 @@ async def test_set_hold_pessimistic(hass, mqtt_mock):
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('hold_mode') is None
|
||||
|
||||
common.async_set_hold_mode(hass, 'on', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_hold_mode(hass, 'on', ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('hold_mode') is None
|
||||
|
||||
@@ -487,16 +471,14 @@ async def test_set_hold(hass, mqtt_mock):
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('hold_mode') is None
|
||||
common.async_set_hold_mode(hass, 'on', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_hold_mode(hass, 'on', ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'hold-topic', 'on', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('hold_mode') == 'on'
|
||||
|
||||
common.async_set_hold_mode(hass, 'off', ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_hold_mode(hass, 'off', ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'hold-topic', 'off', 0, False)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
@@ -512,8 +494,7 @@ async def test_set_aux_pessimistic(hass, mqtt_mock):
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('aux_heat') == 'off'
|
||||
|
||||
common.async_set_aux_heat(hass, True, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_aux_heat(hass, True, ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('aux_heat') == 'off'
|
||||
|
||||
@@ -536,16 +517,14 @@ async def test_set_aux(hass, mqtt_mock):
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get('aux_heat') == 'off'
|
||||
common.async_set_aux_heat(hass, True, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_aux_heat(hass, True, ENTITY_CLIMATE)
|
||||
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 state.attributes.get('aux_heat') == 'on'
|
||||
|
||||
common.async_set_aux_heat(hass, False, ENTITY_CLIMATE)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_aux_heat(hass, False, ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'aux-topic', 'OFF', 0, False)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
|
||||
@@ -172,8 +172,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_OFF
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_turn_on(hass, 'fan.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'fan.test')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'command-topic', 'StAtE_On', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -181,8 +180,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_ON
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_turn_off(hass, 'fan.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass, 'fan.test')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'command-topic', 'StAtE_OfF', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -190,8 +188,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_OFF
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_oscillate(hass, 'fan.test', True)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_oscillate(hass, 'fan.test', True)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'oscillation-command-topic', 'OsC_On', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -199,8 +196,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_OFF
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_oscillate(hass, 'fan.test', False)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_oscillate(hass, 'fan.test', False)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'oscillation-command-topic', 'OsC_OfF', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -208,8 +204,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_OFF
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_set_speed(hass, 'fan.test', fan.SPEED_LOW)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_speed(hass, 'fan.test', fan.SPEED_LOW)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'speed-command-topic', 'speed_lOw', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -217,8 +212,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_OFF
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_set_speed(hass, 'fan.test', fan.SPEED_MEDIUM)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_speed(hass, 'fan.test', fan.SPEED_MEDIUM)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'speed-command-topic', 'speed_mEdium', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -226,8 +220,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_OFF
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_set_speed(hass, 'fan.test', fan.SPEED_HIGH)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_speed(hass, 'fan.test', fan.SPEED_HIGH)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'speed-command-topic', 'speed_High', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -235,8 +228,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_OFF
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_set_speed(hass, 'fan.test', fan.SPEED_OFF)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_speed(hass, 'fan.test', fan.SPEED_OFF)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'speed-command-topic', 'speed_OfF', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -265,8 +257,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_OFF
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_turn_on(hass, 'fan.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'fan.test')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'command-topic', 'ON', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -274,8 +265,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_ON
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_turn_off(hass, 'fan.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass, 'fan.test')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'command-topic', 'OFF', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -283,8 +273,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_OFF
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_oscillate(hass, 'fan.test', True)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_oscillate(hass, 'fan.test', True)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'oscillation-command-topic', 'oscillate_on', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -292,8 +281,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_OFF
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_oscillate(hass, 'fan.test', False)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_oscillate(hass, 'fan.test', False)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'oscillation-command-topic', 'oscillate_off', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -301,8 +289,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_OFF
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_set_speed(hass, 'fan.test', fan.SPEED_LOW)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_speed(hass, 'fan.test', fan.SPEED_LOW)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'speed-command-topic', 'low', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -310,8 +297,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_OFF
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_set_speed(hass, 'fan.test', fan.SPEED_MEDIUM)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_speed(hass, 'fan.test', fan.SPEED_MEDIUM)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'speed-command-topic', 'medium', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -319,8 +305,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_OFF
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_set_speed(hass, 'fan.test', fan.SPEED_HIGH)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_speed(hass, 'fan.test', fan.SPEED_HIGH)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'speed-command-topic', 'high', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
@@ -328,8 +313,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_OFF
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_set_speed(hass, 'fan.test', fan.SPEED_OFF)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_speed(hass, 'fan.test', fan.SPEED_OFF)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'speed-command-topic', 'off', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
@@ -66,82 +66,61 @@ async def test_all_commands(hass, mqtt_mock):
|
||||
vacuum.DOMAIN: config,
|
||||
})
|
||||
|
||||
common.turn_on(hass, 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'vacuum/command', 'turn_on', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.turn_off(hass, 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass, 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'vacuum/command', 'turn_off', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.stop(hass, 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_stop(hass, 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'vacuum/command', 'stop', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.clean_spot(hass, 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_clean_spot(hass, 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'vacuum/command', 'clean_spot', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.locate(hass, 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_locate(hass, 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'vacuum/command', 'locate', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.start_pause(hass, 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_start_pause(hass, 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'vacuum/command', 'start_pause', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.return_to_base(hass, 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_return_to_base(hass, 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'vacuum/command', 'return_to_base', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.set_fan_speed(hass, 'high', 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_fan_speed(hass, 'high', 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'vacuum/set_fan_speed', 'high', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.send_command(hass, '44 FE 93', entity_id='vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_send_command(hass, '44 FE 93',
|
||||
entity_id='vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'vacuum/send_command', '44 FE 93', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.send_command(hass, '44 FE 93', {"key": "value"},
|
||||
entity_id='vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_send_command(hass, '44 FE 93', {"key": "value"},
|
||||
entity_id='vacuum.mqtttest')
|
||||
assert json.loads(mqtt_mock.async_publish.mock_calls[-1][1][1]) == {
|
||||
"command": "44 FE 93",
|
||||
"key": "value"
|
||||
}
|
||||
|
||||
common.send_command(hass, '44 FE 93', {"key": "value"},
|
||||
entity_id='vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_send_command(hass, '44 FE 93', {"key": "value"},
|
||||
entity_id='vacuum.mqtttest')
|
||||
assert json.loads(mqtt_mock.async_publish.mock_calls[-1][1][1]) == {
|
||||
"command": "44 FE 93",
|
||||
"key": "value"
|
||||
@@ -160,57 +139,40 @@ async def test_commands_without_supported_features(hass, mqtt_mock):
|
||||
vacuum.DOMAIN: config,
|
||||
})
|
||||
|
||||
common.turn_on(hass, 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.turn_off(hass, 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass, 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.stop(hass, 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_stop(hass, 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.clean_spot(hass, 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_clean_spot(hass, 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.locate(hass, 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_locate(hass, 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.start_pause(hass, 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_start_pause(hass, 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.return_to_base(hass, 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_return_to_base(hass, 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.set_fan_speed(hass, 'high', 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_fan_speed(hass, 'high', 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.send_command(hass, '44 FE 93', entity_id='vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_send_command(hass, '44 FE 93',
|
||||
entity_id='vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
@@ -228,7 +190,7 @@ async def test_attributes_without_supported_features(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert STATE_OFF == state.state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get(ATTR_BATTERY_LEVEL) is None
|
||||
assert state.attributes.get(ATTR_BATTERY_ICON) is None
|
||||
|
||||
@@ -251,8 +213,6 @@ async def test_status(hass, mqtt_mock):
|
||||
"fan_speed": "max"
|
||||
}"""
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', message)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get(ATTR_BATTERY_ICON) == 'mdi:battery-50'
|
||||
@@ -268,8 +228,6 @@ async def test_status(hass, mqtt_mock):
|
||||
}"""
|
||||
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', message)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get(ATTR_BATTERY_ICON) == 'mdi:battery-charging-60'
|
||||
@@ -291,8 +249,6 @@ async def test_status_battery(hass, mqtt_mock):
|
||||
"battery_level": 54
|
||||
}"""
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', message)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.attributes.get(ATTR_BATTERY_ICON) == 'mdi:battery-50'
|
||||
|
||||
@@ -311,8 +267,6 @@ async def test_status_cleaning(hass, mqtt_mock):
|
||||
"cleaning": true
|
||||
}"""
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', message)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.state == STATE_ON
|
||||
|
||||
@@ -331,8 +285,6 @@ async def test_status_docked(hass, mqtt_mock):
|
||||
"docked": true
|
||||
}"""
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', message)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
@@ -351,8 +303,6 @@ async def test_status_charging(hass, mqtt_mock):
|
||||
"charging": true
|
||||
}"""
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', message)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.attributes.get(ATTR_BATTERY_ICON) == 'mdi:battery-outline'
|
||||
|
||||
@@ -371,8 +321,6 @@ async def test_status_fan_speed(hass, mqtt_mock):
|
||||
"fan_speed": "max"
|
||||
}"""
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', message)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.attributes.get(ATTR_FAN_SPEED) == 'max'
|
||||
|
||||
@@ -391,7 +339,6 @@ async def test_status_error(hass, mqtt_mock):
|
||||
"error": "Error1"
|
||||
}"""
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', message)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.attributes.get(ATTR_STATUS) == 'Error: Error1'
|
||||
|
||||
@@ -399,7 +346,6 @@ async def test_status_error(hass, mqtt_mock):
|
||||
"error": ""
|
||||
}"""
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', message)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.attributes.get(ATTR_STATUS) == 'Stopped'
|
||||
|
||||
@@ -419,7 +365,6 @@ async def test_battery_template(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
async_fire_mqtt_message(hass, 'retroroomba/battery_level', '54')
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.attributes.get(ATTR_BATTERY_LEVEL) == 54
|
||||
assert state.attributes.get(ATTR_BATTERY_ICON) == 'mdi:battery-50'
|
||||
@@ -436,7 +381,6 @@ async def test_status_invalid_json(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', '{"asdfasas false}')
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get(ATTR_STATUS) == "Stopped"
|
||||
@@ -532,21 +476,17 @@ async def test_default_availability_payload(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'online')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'offline')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
@@ -563,21 +503,17 @@ async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'good')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'nogood')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_discovery_removal_vacuum(hass, mqtt_mock):
|
||||
@@ -593,7 +529,6 @@ async def test_discovery_removal_vacuum(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config',
|
||||
data)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.beer')
|
||||
assert state is not None
|
||||
@@ -601,7 +536,6 @@ async def test_discovery_removal_vacuum(hass, mqtt_mock):
|
||||
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config', '')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.beer')
|
||||
assert state is None
|
||||
@@ -631,7 +565,6 @@ async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config',
|
||||
data2)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.milk')
|
||||
assert state is not None
|
||||
@@ -665,7 +598,6 @@ async def test_discovery_update_vacuum(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config',
|
||||
data2)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.beer')
|
||||
assert state is not None
|
||||
@@ -686,7 +618,6 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '{ "val": "100" }')
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.test')
|
||||
|
||||
assert state.attributes.get('val') == '100'
|
||||
@@ -704,7 +635,6 @@ async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
})
|
||||
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '[ "list", "of", "things"]')
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.test')
|
||||
|
||||
assert state.attributes.get('val') is None
|
||||
@@ -723,7 +653,6 @@ async def test_update_with_json_attrs_bad_json(hass, mqtt_mock, caplog):
|
||||
})
|
||||
|
||||
async_fire_mqtt_message(hass, 'attr-topic', 'This is not JSON')
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.test')
|
||||
assert state.attributes.get('val') is None
|
||||
@@ -748,8 +677,6 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
data1)
|
||||
await hass.async_block_till_done()
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.beer')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
@@ -757,19 +684,14 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config',
|
||||
data2)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Verify we are no longer subscribing to the old topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.beer')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Verify we are subscribing to the new topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.beer')
|
||||
assert state.attributes.get('val') == '75'
|
||||
|
||||
@@ -792,8 +714,6 @@ async def test_unique_id(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', 'payload')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_entity_ids()) == 2
|
||||
# all vacuums group is 1, unique id created is 1
|
||||
@@ -825,7 +745,6 @@ async def test_entity_device_info_with_identifier(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config',
|
||||
data)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device = registry.async_get_device({('mqtt', 'helloworld')}, set())
|
||||
assert device is not None
|
||||
@@ -866,7 +785,6 @@ async def test_entity_device_info_update(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config',
|
||||
data)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device = registry.async_get_device({('mqtt', 'helloworld')}, set())
|
||||
assert device is not None
|
||||
@@ -877,7 +795,6 @@ async def test_entity_device_info_update(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config',
|
||||
data)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device = registry.async_get_device({('mqtt', 'helloworld')}, set())
|
||||
assert device is not None
|
||||
|
||||
@@ -540,8 +540,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert state.attributes.get('white_value') == 50
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_turn_on(hass, 'light.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test')
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'test_light_rgb/set', 'on', 2, False)
|
||||
@@ -549,8 +548,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
state = hass.states.get('light.test')
|
||||
assert state.state == STATE_ON
|
||||
|
||||
common.async_turn_off(hass, 'light.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass, 'light.test')
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'test_light_rgb/set', 'off', 2, False)
|
||||
@@ -559,13 +557,12 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
mqtt_mock.reset_mock()
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, hs_color=[359, 78])
|
||||
common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 0],
|
||||
white_value=80)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
await common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, hs_color=[359, 78])
|
||||
await common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 0],
|
||||
white_value=80)
|
||||
|
||||
mqtt_mock.async_publish.assert_has_calls([
|
||||
mock.call('test_light_rgb/set', 'on', 2, False),
|
||||
@@ -604,8 +601,7 @@ async def test_sending_mqtt_rgb_command_with_template(hass, mqtt_mock):
|
||||
state = hass.states.get('light.test')
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 64])
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 64])
|
||||
|
||||
mqtt_mock.async_publish.assert_has_calls([
|
||||
mock.call('test_light_rgb/set', 'on', 0, False),
|
||||
@@ -635,8 +631,7 @@ async def test_sending_mqtt_color_temp_command_with_template(hass, mqtt_mock):
|
||||
state = hass.states.get('light.test')
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test', color_temp=100)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test', color_temp=100)
|
||||
|
||||
mqtt_mock.async_publish.assert_has_calls([
|
||||
mock.call('test_light_color_temp/set', 'on', 0, False),
|
||||
@@ -801,8 +796,7 @@ async def test_on_command_first(hass, mqtt_mock):
|
||||
state = hass.states.get('light.test')
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test', brightness=50)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test', brightness=50)
|
||||
|
||||
# Should get the following MQTT messages.
|
||||
# test_light/set: 'ON'
|
||||
@@ -813,8 +807,7 @@ async def test_on_command_first(hass, mqtt_mock):
|
||||
], any_order=True)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.async_turn_off(hass, 'light.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass, 'light.test')
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'test_light/set', 'OFF', 0, False)
|
||||
@@ -834,8 +827,7 @@ async def test_on_command_last(hass, mqtt_mock):
|
||||
state = hass.states.get('light.test')
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test', brightness=50)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test', brightness=50)
|
||||
|
||||
# Should get the following MQTT messages.
|
||||
# test_light/bright: 50
|
||||
@@ -846,8 +838,7 @@ async def test_on_command_last(hass, mqtt_mock):
|
||||
], any_order=True)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.async_turn_off(hass, 'light.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass, 'light.test')
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'test_light/set', 'OFF', 0, False)
|
||||
@@ -870,8 +861,7 @@ async def test_on_command_brightness(hass, mqtt_mock):
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
# Turn on w/ no brightness - should set to max
|
||||
common.async_turn_on(hass, 'light.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test')
|
||||
|
||||
# Should get the following MQTT messages.
|
||||
# test_light/bright: 255
|
||||
@@ -879,28 +869,24 @@ async def test_on_command_brightness(hass, mqtt_mock):
|
||||
'test_light/bright', 255, 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.async_turn_off(hass, 'light.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass, 'light.test')
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'test_light/set', 'OFF', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
# Turn on w/ brightness
|
||||
common.async_turn_on(hass, 'light.test', brightness=50)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test', brightness=50)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'test_light/bright', 50, 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.async_turn_off(hass, 'light.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass, 'light.test')
|
||||
|
||||
# Turn on w/ just a color to insure brightness gets
|
||||
# added and sent.
|
||||
common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 0])
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 0])
|
||||
|
||||
mqtt_mock.async_publish.assert_has_calls([
|
||||
mock.call('test_light/rgb', '255,128,0', 0, False),
|
||||
@@ -922,8 +908,7 @@ async def test_on_command_rgb(hass, mqtt_mock):
|
||||
state = hass.states.get('light.test')
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test', brightness=127)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test', brightness=127)
|
||||
|
||||
# Should get the following MQTT messages.
|
||||
# test_light/rgb: '127,127,127'
|
||||
@@ -934,8 +919,7 @@ async def test_on_command_rgb(hass, mqtt_mock):
|
||||
], any_order=True)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.async_turn_off(hass, 'light.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass, 'light.test')
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'test_light/set', 'OFF', 0, False)
|
||||
|
||||
@@ -306,8 +306,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 191
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_turn_on(hass, 'light.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test')
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'test_light_rgb/set', '{"state": "ON"}', 2, False)
|
||||
@@ -315,8 +314,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
state = hass.states.get('light.test')
|
||||
assert state.state == STATE_ON
|
||||
|
||||
common.async_turn_off(hass, 'light.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass, 'light.test')
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'test_light_rgb/set', '{"state": "OFF"}', 2, False)
|
||||
@@ -325,13 +323,12 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
mqtt_mock.reset_mock()
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, hs_color=[359, 78])
|
||||
common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 0],
|
||||
white_value=80)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
await common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, hs_color=[359, 78])
|
||||
await common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 0],
|
||||
white_value=80)
|
||||
|
||||
mqtt_mock.async_publish.assert_has_calls([
|
||||
mock.call(
|
||||
@@ -383,13 +380,12 @@ async def test_sending_hs_color(hass, mqtt_mock):
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
mqtt_mock.reset_mock()
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, hs_color=[359, 78])
|
||||
common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 0],
|
||||
white_value=80)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
await common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, hs_color=[359, 78])
|
||||
await common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 0],
|
||||
white_value=80)
|
||||
|
||||
mqtt_mock.async_publish.assert_has_calls([
|
||||
mock.call(
|
||||
@@ -428,13 +424,12 @@ async def test_sending_rgb_color_no_brightness(hass, mqtt_mock):
|
||||
state = hass.states.get('light.test')
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, hs_color=[359, 78])
|
||||
common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 0],
|
||||
brightness=255)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
await common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, hs_color=[359, 78])
|
||||
await common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 0],
|
||||
brightness=255)
|
||||
|
||||
mqtt_mock.async_publish.assert_has_calls([
|
||||
mock.call(
|
||||
@@ -471,13 +466,12 @@ async def test_sending_rgb_color_with_brightness(hass, mqtt_mock):
|
||||
state = hass.states.get('light.test')
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, hs_color=[359, 78])
|
||||
common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 0],
|
||||
white_value=80)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
await common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, hs_color=[359, 78])
|
||||
await common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 0],
|
||||
white_value=80)
|
||||
|
||||
mqtt_mock.async_publish.assert_has_calls([
|
||||
mock.call(
|
||||
@@ -517,13 +511,12 @@ async def test_sending_xy_color(hass, mqtt_mock):
|
||||
state = hass.states.get('light.test')
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, hs_color=[359, 78])
|
||||
common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 0],
|
||||
white_value=80)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
await common.async_turn_on(hass, 'light.test',
|
||||
brightness=50, hs_color=[359, 78])
|
||||
await common.async_turn_on(hass, 'light.test', rgb_color=[255, 128, 0],
|
||||
white_value=80)
|
||||
|
||||
mqtt_mock.async_publish.assert_has_calls([
|
||||
mock.call(
|
||||
@@ -565,8 +558,7 @@ async def test_flash_short_and_long(hass, mqtt_mock):
|
||||
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()
|
||||
await common.async_turn_on(hass, 'light.test', flash='short')
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'test_light_rgb/set', JsonValidator(
|
||||
@@ -575,8 +567,7 @@ async def test_flash_short_and_long(hass, mqtt_mock):
|
||||
state = hass.states.get('light.test')
|
||||
assert state.state == STATE_ON
|
||||
|
||||
common.async_turn_on(hass, 'light.test', flash='long')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'light.test', flash='long')
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'test_light_rgb/set', JsonValidator(
|
||||
@@ -602,8 +593,7 @@ async def test_transition(hass, mqtt_mock):
|
||||
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()
|
||||
await common.async_turn_on(hass, 'light.test', transition=15)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'test_light_rgb/set', JsonValidator(
|
||||
@@ -612,8 +602,7 @@ async def test_transition(hass, mqtt_mock):
|
||||
state = hass.states.get('light.test')
|
||||
assert state.state == STATE_ON
|
||||
|
||||
common.async_turn_off(hass, 'light.test', transition=30)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass, 'light.test', transition=30)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'test_light_rgb/set', JsonValidator(
|
||||
|
||||
@@ -86,8 +86,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_UNLOCKED
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_lock(hass, 'lock.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_lock(hass, 'lock.test')
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'command-topic', 'LOCK', 0, False)
|
||||
@@ -96,8 +95,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_LOCKED
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_unlock(hass, 'lock.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_unlock(hass, 'lock.test')
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'command-topic', 'UNLOCK', 0, False)
|
||||
@@ -125,8 +123,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_UNLOCKED
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_lock(hass, 'lock.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_lock(hass, 'lock.test')
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'command-topic', 'LOCK', 0, False)
|
||||
@@ -135,8 +132,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
|
||||
assert state.state is STATE_LOCKED
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.async_unlock(hass, 'lock.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_unlock(hass, 'lock.test')
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'command-topic', 'UNLOCK', 0, False)
|
||||
|
||||
@@ -64,70 +64,53 @@ async def test_all_commands(hass, mqtt_mock):
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_START, blocking=True)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
COMMAND_TOPIC, 'start', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_STOP, blocking=True)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
COMMAND_TOPIC, 'stop', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_PAUSE, blocking=True)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
COMMAND_TOPIC, 'pause', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_LOCATE, blocking=True)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
COMMAND_TOPIC, 'locate', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_CLEAN_SPOT, blocking=True)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
COMMAND_TOPIC, 'clean_spot', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_RETURN_TO_BASE, blocking=True)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
COMMAND_TOPIC, 'return_to_base', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.set_fan_speed(hass, 'medium', 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_fan_speed(hass, 'medium', 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'vacuum/set_fan_speed', 'medium', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.send_command(hass, '44 FE 93', entity_id='vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_send_command(hass, '44 FE 93',
|
||||
entity_id='vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
'vacuum/send_command', '44 FE 93', 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.send_command(hass, '44 FE 93', {"key": "value"},
|
||||
entity_id='vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_send_command(hass, '44 FE 93', {"key": "value"},
|
||||
entity_id='vacuum.mqtttest')
|
||||
assert json.loads(mqtt_mock.async_publish.mock_calls[-1][1][1]) == {
|
||||
"command": "44 FE 93",
|
||||
"key": "value"
|
||||
@@ -148,56 +131,40 @@ async def test_commands_without_supported_features(hass, mqtt_mock):
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_START, blocking=True)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_PAUSE, blocking=True)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_STOP, blocking=True)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_RETURN_TO_BASE, blocking=True)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_LOCATE, blocking=True)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_CLEAN_SPOT, blocking=True)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.set_fan_speed(hass, 'medium', 'vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_set_fan_speed(hass, 'medium', 'vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
common.send_command(hass, '44 FE 93', {"key": "value"},
|
||||
entity_id='vacuum.mqtttest')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_send_command(hass, '44 FE 93', {"key": "value"},
|
||||
entity_id='vacuum.mqtttest')
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
|
||||
|
||||
@@ -217,8 +184,6 @@ async def test_status(hass, mqtt_mock):
|
||||
"fan_speed": "max"
|
||||
}"""
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', message)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.state == STATE_CLEANING
|
||||
assert state.attributes.get(ATTR_BATTERY_LEVEL) == 54
|
||||
@@ -232,8 +197,6 @@ async def test_status(hass, mqtt_mock):
|
||||
}"""
|
||||
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', message)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.state == STATE_DOCKED
|
||||
assert state.attributes.get(ATTR_BATTERY_ICON) == 'mdi:battery-charging-60'
|
||||
@@ -259,8 +222,6 @@ async def test_no_fan_vacuum(hass, mqtt_mock):
|
||||
"state": "cleaning"
|
||||
}"""
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', message)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.state == STATE_CLEANING
|
||||
assert state.attributes.get(ATTR_FAN_SPEED) is None
|
||||
@@ -274,8 +235,6 @@ async def test_no_fan_vacuum(hass, mqtt_mock):
|
||||
"fan_speed": "max"
|
||||
}"""
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', message)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
|
||||
assert state.state == STATE_CLEANING
|
||||
@@ -291,8 +250,6 @@ async def test_no_fan_vacuum(hass, mqtt_mock):
|
||||
}"""
|
||||
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', message)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.state == STATE_DOCKED
|
||||
assert state.attributes.get(ATTR_BATTERY_ICON) == 'mdi:battery-charging-60'
|
||||
@@ -311,7 +268,6 @@ async def test_status_invalid_json(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
async_fire_mqtt_message(hass, 'vacuum/state', '{"asdfasas false}')
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
@@ -331,15 +287,11 @@ async def test_default_availability_payload(hass, mqtt_mock):
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'online')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'offline')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
@@ -362,15 +314,11 @@ async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'good')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, 'availability-topic', 'nogood')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.mqtttest')
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
@@ -390,7 +338,6 @@ async def test_discovery_removal_vacuum(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config',
|
||||
data)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.beer')
|
||||
assert state is not None
|
||||
@@ -398,7 +345,6 @@ async def test_discovery_removal_vacuum(hass, mqtt_mock):
|
||||
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config', '')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.beer')
|
||||
assert state is None
|
||||
@@ -430,7 +376,6 @@ async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config',
|
||||
data2)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.milk')
|
||||
assert state is not None
|
||||
@@ -466,7 +411,6 @@ async def test_discovery_update_vacuum(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config',
|
||||
data2)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.beer')
|
||||
assert state is not None
|
||||
@@ -487,7 +431,6 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '{ "val": "100" }')
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.test')
|
||||
|
||||
assert state.attributes.get('val') == '100'
|
||||
@@ -505,7 +448,6 @@ async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
})
|
||||
|
||||
async_fire_mqtt_message(hass, 'attr-topic', '[ "list", "of", "things"]')
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.test')
|
||||
|
||||
assert state.attributes.get('val') is None
|
||||
@@ -524,7 +466,6 @@ async def test_update_with_json_attrs_bad_json(hass, mqtt_mock, caplog):
|
||||
})
|
||||
|
||||
async_fire_mqtt_message(hass, 'attr-topic', 'This is not JSON')
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('vacuum.test')
|
||||
assert state.attributes.get('val') is None
|
||||
@@ -549,8 +490,6 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
data1)
|
||||
await hass.async_block_till_done()
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.beer')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
@@ -558,19 +497,14 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config',
|
||||
data2)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Verify we are no longer subscribing to the old topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.beer')
|
||||
assert state.attributes.get('val') == '100'
|
||||
|
||||
# Verify we are subscribing to the new topic
|
||||
async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('vacuum.beer')
|
||||
assert state.attributes.get('val') == '75'
|
||||
|
||||
@@ -593,8 +527,6 @@ async def test_unique_id(hass, mqtt_mock):
|
||||
})
|
||||
|
||||
async_fire_mqtt_message(hass, 'test-topic', 'payload')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_entity_ids()) == 2
|
||||
# all vacuums group is 1, unique id created is 1
|
||||
@@ -626,7 +558,6 @@ async def test_entity_device_info_with_identifier(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config',
|
||||
data)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device = registry.async_get_device({('mqtt', 'helloworld')}, set())
|
||||
assert device is not None
|
||||
@@ -667,7 +598,6 @@ async def test_entity_device_info_update(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config',
|
||||
data)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device = registry.async_get_device({('mqtt', 'helloworld')}, set())
|
||||
assert device is not None
|
||||
@@ -678,7 +608,6 @@ async def test_entity_device_info_update(hass, mqtt_mock):
|
||||
async_fire_mqtt_message(hass, 'homeassistant/vacuum/bla/config',
|
||||
data)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device = registry.async_get_device({('mqtt', 'helloworld')}, set())
|
||||
assert device is not None
|
||||
|
||||
@@ -74,8 +74,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mock_publish):
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.turn_on(hass, 'switch.test')
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_on(hass, 'switch.test')
|
||||
|
||||
mock_publish.async_publish.assert_called_once_with(
|
||||
'command-topic', 'beer on', 2, False)
|
||||
@@ -83,9 +82,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mock_publish):
|
||||
state = hass.states.get('switch.test')
|
||||
assert state.state == STATE_ON
|
||||
|
||||
common.turn_off(hass, 'switch.test')
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass, 'switch.test')
|
||||
|
||||
mock_publish.async_publish.assert_called_once_with(
|
||||
'command-topic', 'beer off', 2, False)
|
||||
|
||||
Reference in new issue
Block a user