mirror of
https://github.com/home-assistant/core.git
synced 2025-09-01 10:51:47 +02:00
Use constants in Tuya tests (#150739)
This commit is contained in:
@@ -9,13 +9,16 @@ from syrupy.assertion import SnapshotAssertion
|
||||
from tuya_sharing import CustomerDevice
|
||||
|
||||
from homeassistant.components.climate import (
|
||||
ATTR_FAN_MODE,
|
||||
ATTR_HUMIDITY,
|
||||
ATTR_TEMPERATURE,
|
||||
DOMAIN as CLIMATE_DOMAIN,
|
||||
SERVICE_SET_FAN_MODE,
|
||||
SERVICE_SET_HUMIDITY,
|
||||
SERVICE_SET_TEMPERATURE,
|
||||
)
|
||||
from homeassistant.components.tuya import ManagerCompat
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceNotSupported
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@@ -60,11 +63,11 @@ async def test_set_temperature(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_TEMPERATURE,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"temperature": 22.7,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_TEMPERATURE: 22.7,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_manager.send_commands.assert_called_once_with(
|
||||
mock_device.id, [{"code": "temp_set", "value": 22}]
|
||||
)
|
||||
@@ -86,16 +89,16 @@ async def test_fan_mode_windspeed(
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state is not None, f"{entity_id} does not exist"
|
||||
assert state.attributes["fan_mode"] == 1
|
||||
assert state.attributes[ATTR_FAN_MODE] == 1
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_FAN_MODE,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"fan_mode": 2,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_FAN_MODE: 2,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_manager.send_commands.assert_called_once_with(
|
||||
mock_device.id, [{"code": "windspeed", "value": "2"}]
|
||||
)
|
||||
@@ -122,14 +125,14 @@ async def test_fan_mode_no_valid_code(
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state is not None, f"{entity_id} does not exist"
|
||||
assert state.attributes.get("fan_mode") is None
|
||||
assert state.attributes.get(ATTR_FAN_MODE) is None
|
||||
with pytest.raises(ServiceNotSupported):
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_FAN_MODE,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"fan_mode": 2,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_FAN_MODE: 2,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
@@ -156,8 +159,8 @@ async def test_set_humidity_not_supported(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_HUMIDITY,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"humidity": 50,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_HUMIDITY: 50,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
@@ -9,6 +9,9 @@ from syrupy.assertion import SnapshotAssertion
|
||||
from tuya_sharing import CustomerDevice
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
ATTR_CURRENT_POSITION,
|
||||
ATTR_POSITION,
|
||||
ATTR_TILT_POSITION,
|
||||
DOMAIN as COVER_DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
SERVICE_OPEN_COVER,
|
||||
@@ -16,7 +19,7 @@ from homeassistant.components.cover import (
|
||||
SERVICE_SET_COVER_TILT_POSITION,
|
||||
)
|
||||
from homeassistant.components.tuya import ManagerCompat
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceNotSupported
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@@ -62,10 +65,10 @@ async def test_open_service(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_OPEN_COVER,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_manager.send_commands.assert_called_once_with(
|
||||
mock_device.id,
|
||||
[
|
||||
@@ -96,10 +99,10 @@ async def test_close_service(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_manager.send_commands.assert_called_once_with(
|
||||
mock_device.id,
|
||||
[
|
||||
@@ -129,11 +132,11 @@ async def test_set_position(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_SET_COVER_POSITION,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"position": 25,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_POSITION: 25,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_manager.send_commands.assert_called_once_with(
|
||||
mock_device.id,
|
||||
[
|
||||
@@ -173,7 +176,7 @@ async def test_percent_state_on_cover(
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state is not None, f"{entity_id} does not exist"
|
||||
assert state.attributes["current_position"] == percent_state
|
||||
assert state.attributes[ATTR_CURRENT_POSITION] == percent_state
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -197,8 +200,8 @@ async def test_set_tilt_position_not_supported(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_SET_COVER_TILT_POSITION,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"tilt_position": 50,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_TILT_POSITION: 50,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
@@ -9,13 +9,14 @@ from syrupy.assertion import SnapshotAssertion
|
||||
from tuya_sharing import CustomerDevice
|
||||
|
||||
from homeassistant.components.humidifier import (
|
||||
ATTR_HUMIDITY,
|
||||
DOMAIN as HUMIDIFIER_DOMAIN,
|
||||
SERVICE_SET_HUMIDITY,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
)
|
||||
from homeassistant.components.tuya import ManagerCompat
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@@ -59,9 +60,9 @@ async def test_turn_on(
|
||||
await hass.services.async_call(
|
||||
HUMIDIFIER_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{"entity_id": entity_id},
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_manager.send_commands.assert_called_once_with(
|
||||
mock_device.id, [{"code": "switch", "value": True}]
|
||||
)
|
||||
@@ -86,9 +87,9 @@ async def test_turn_off(
|
||||
await hass.services.async_call(
|
||||
HUMIDIFIER_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{"entity_id": entity_id},
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_manager.send_commands.assert_called_once_with(
|
||||
mock_device.id, [{"code": "switch", "value": False}]
|
||||
)
|
||||
@@ -114,11 +115,11 @@ async def test_set_humidity(
|
||||
HUMIDIFIER_DOMAIN,
|
||||
SERVICE_SET_HUMIDITY,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"humidity": 50,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_HUMIDITY: 50,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_manager.send_commands.assert_called_once_with(
|
||||
mock_device.id, [{"code": "dehumidify_set_value", "value": 50}]
|
||||
)
|
||||
@@ -149,7 +150,7 @@ async def test_turn_on_unsupported(
|
||||
await hass.services.async_call(
|
||||
HUMIDIFIER_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{"entity_id": entity_id},
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
assert err.value.translation_key == "action_dpcode_not_found"
|
||||
@@ -184,7 +185,7 @@ async def test_turn_off_unsupported(
|
||||
await hass.services.async_call(
|
||||
HUMIDIFIER_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{"entity_id": entity_id},
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
assert err.value.translation_key == "action_dpcode_not_found"
|
||||
@@ -220,8 +221,8 @@ async def test_set_humidity_unsupported(
|
||||
HUMIDIFIER_DOMAIN,
|
||||
SERVICE_SET_HUMIDITY,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"humidity": 50,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_HUMIDITY: 50,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
@@ -10,12 +10,14 @@ from syrupy.assertion import SnapshotAssertion
|
||||
from tuya_sharing import CustomerDevice
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_WHITE,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
)
|
||||
from homeassistant.components.tuya import ManagerCompat
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
@@ -48,7 +50,7 @@ async def test_platform_setup_and_discovery(
|
||||
[
|
||||
(
|
||||
{
|
||||
"white": True,
|
||||
ATTR_WHITE: True,
|
||||
},
|
||||
[
|
||||
{"code": "switch_led", "value": True},
|
||||
@@ -58,7 +60,7 @@ async def test_platform_setup_and_discovery(
|
||||
),
|
||||
(
|
||||
{
|
||||
"brightness": 150,
|
||||
ATTR_BRIGHTNESS: 150,
|
||||
},
|
||||
[
|
||||
{"code": "switch_led", "value": True},
|
||||
@@ -67,8 +69,8 @@ async def test_platform_setup_and_discovery(
|
||||
),
|
||||
(
|
||||
{
|
||||
"white": True,
|
||||
"brightness": 150,
|
||||
ATTR_WHITE: True,
|
||||
ATTR_BRIGHTNESS: 150,
|
||||
},
|
||||
[
|
||||
{"code": "switch_led", "value": True},
|
||||
@@ -78,7 +80,7 @@ async def test_platform_setup_and_discovery(
|
||||
),
|
||||
(
|
||||
{
|
||||
"white": 150,
|
||||
ATTR_WHITE: 150,
|
||||
},
|
||||
[
|
||||
{"code": "switch_led", "value": True},
|
||||
@@ -106,11 +108,11 @@ async def test_turn_on_white(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
**turn_on_input,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_manager.send_commands.assert_called_once_with(
|
||||
mock_device.id,
|
||||
expected_commands,
|
||||
@@ -137,10 +139,10 @@ async def test_turn_off(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_manager.send_commands.assert_called_once_with(
|
||||
mock_device.id, [{"code": "switch_led", "value": False}]
|
||||
)
|
||||
|
@@ -8,9 +8,13 @@ import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from tuya_sharing import CustomerDevice
|
||||
|
||||
from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN, SERVICE_SET_VALUE
|
||||
from homeassistant.components.number import (
|
||||
ATTR_VALUE,
|
||||
DOMAIN as NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
)
|
||||
from homeassistant.components.tuya import ManagerCompat
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@@ -55,11 +59,11 @@ async def test_set_value(
|
||||
NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"value": 18,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_VALUE: 18,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_manager.send_commands.assert_called_once_with(
|
||||
mock_device.id, [{"code": "delay_set", "value": 18}]
|
||||
)
|
||||
@@ -91,8 +95,8 @@ async def test_set_value_no_function(
|
||||
NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"value": 18,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_VALUE: 18,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
@@ -9,11 +9,12 @@ from syrupy.assertion import SnapshotAssertion
|
||||
from tuya_sharing import CustomerDevice
|
||||
|
||||
from homeassistant.components.select import (
|
||||
ATTR_OPTION,
|
||||
DOMAIN as SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
)
|
||||
from homeassistant.components.tuya import ManagerCompat
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@@ -58,8 +59,8 @@ async def test_select_option(
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"option": "forward",
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_OPTION: "forward",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
@@ -89,8 +90,8 @@ async def test_select_invalid_option(
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
"option": "hello",
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_OPTION: "hello",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
@@ -13,7 +13,7 @@ from homeassistant.components.vacuum import (
|
||||
DOMAIN as VACUUM_DOMAIN,
|
||||
SERVICE_RETURN_TO_BASE,
|
||||
)
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
@@ -58,7 +58,7 @@ async def test_return_home(
|
||||
VACUUM_DOMAIN,
|
||||
SERVICE_RETURN_TO_BASE,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
@@ -14,7 +14,7 @@ from homeassistant.components.valve import (
|
||||
SERVICE_CLOSE_VALVE,
|
||||
SERVICE_OPEN_VALVE,
|
||||
)
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
@@ -58,7 +58,7 @@ async def test_open_valve(
|
||||
VALVE_DOMAIN,
|
||||
SERVICE_OPEN_VALVE,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
@@ -87,7 +87,7 @@ async def test_close_valve(
|
||||
VALVE_DOMAIN,
|
||||
SERVICE_CLOSE_VALVE,
|
||||
{
|
||||
"entity_id": entity_id,
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
Reference in New Issue
Block a user