|
@@ -87,6 +87,19 @@ def test__report_position_invalid(caplog, position):
|
|
|
publish_mock.assert_not_called()
|
|
|
|
|
|
|
|
|
+def test__update_position():
|
|
|
+ with unittest.mock.patch("switchbot.SwitchbotCurtain.__init__", return_value=None):
|
|
|
+ actor = switchbot_mqtt._CurtainMotor(mac_address="dummy")
|
|
|
+ with unittest.mock.patch(
|
|
|
+ "switchbot.SwitchbotCurtain.update"
|
|
|
+ ) as update_mock, unittest.mock.patch.object(
|
|
|
+ actor, "_report_position"
|
|
|
+ ) as report_position_mock:
|
|
|
+ actor._update_position(mqtt_client="client")
|
|
|
+ update_mock.assert_called_once_with()
|
|
|
+ report_position_mock.assert_called_once_with(mqtt_client="client")
|
|
|
+
|
|
|
+
|
|
|
@pytest.mark.parametrize("mac_address", ["aa:bb:cc:dd:ee:ff", "aa:bb:cc:11:22:33"])
|
|
|
@pytest.mark.parametrize(
|
|
|
("message_payload", "action_name"),
|
|
@@ -108,16 +121,18 @@ def test_execute_command(
|
|
|
):
|
|
|
with unittest.mock.patch(
|
|
|
"switchbot.SwitchbotCurtain.__init__", return_value=None
|
|
|
- ) as device_init_mock, caplog.at_level(logging.INFO):
|
|
|
+ ) as device_init_mock:
|
|
|
actor = switchbot_mqtt._CurtainMotor(mac_address=mac_address)
|
|
|
- with unittest.mock.patch.object(
|
|
|
- actor, "report_state"
|
|
|
- ) as report_mock, unittest.mock.patch(
|
|
|
- action_name, return_value=command_successful
|
|
|
- ) as action_mock:
|
|
|
- actor.execute_command(
|
|
|
- mqtt_client="dummy", mqtt_message_payload=message_payload
|
|
|
- )
|
|
|
+ with unittest.mock.patch.object(
|
|
|
+ actor, "report_state"
|
|
|
+ ) as report_mock, unittest.mock.patch(
|
|
|
+ action_name, return_value=command_successful
|
|
|
+ ) as action_mock, unittest.mock.patch.object(
|
|
|
+ actor, "_update_position"
|
|
|
+ ) as update_position_mock, caplog.at_level(
|
|
|
+ logging.INFO
|
|
|
+ ):
|
|
|
+ actor.execute_command(mqtt_client="dummy", mqtt_message_payload=message_payload)
|
|
|
device_init_mock.assert_called_once_with(mac=mac_address, reverse_mode=True)
|
|
|
action_mock.assert_called_once_with()
|
|
|
if command_successful:
|
|
@@ -151,6 +166,10 @@ def test_execute_command(
|
|
|
)
|
|
|
]
|
|
|
report_mock.assert_not_called()
|
|
|
+ if action_name == "switchbot.SwitchbotCurtain.stop" and command_successful:
|
|
|
+ update_position_mock.assert_called_once_with(mqtt_client="dummy")
|
|
|
+ else:
|
|
|
+ update_position_mock.assert_not_called()
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("mac_address", ["aa:bb:cc:dd:ee:ff"])
|