From fa79308d6af558e234a6c67825c59c2a0701ce3c Mon Sep 17 00:00:00 2001 From: Artem Sorokin Date: Fri, 25 Oct 2024 15:58:27 +0300 Subject: [PATCH] Fix tests for 2024.8 --- tests/conftest.py | 2 +- tests/test_capability_custom.py | 59 ++++++++++++++++----------------- tests/test_init.py | 31 +++++++++++------ tests/test_notifier.py | 2 +- 4 files changed, 51 insertions(+), 43 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 96c84456..64843d20 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -193,7 +193,7 @@ def hass_platform_cloud_connection(loop, hass, config_entry_cloud_connection): demo_sensor.hass = hass demo_sensor.entity_id = 'sensor.outside_temp' demo_binary_sensor.hass = hass - demo_binary_sensor.entity_id = 'binary_sensor.front_Door' + demo_binary_sensor.entity_id = 'binary_sensor.front_door' demo_light.hass = hass demo_light.entity_id = 'light.kitchen' diff --git a/tests/test_capability_custom.py b/tests/test_capability_custom.py index e0095bcc..d493910c 100644 --- a/tests/test_capability_custom.py +++ b/tests/test_capability_custom.py @@ -1,7 +1,7 @@ from homeassistant.const import ATTR_ENTITY_ID, CONF_SERVICE, CONF_SERVICE_DATA, STATE_OFF, STATE_ON from homeassistant.core import State -from homeassistant.helpers.config_validation import dynamic_template +from homeassistant.helpers.config_validation import SERVICE_SCHEMA, dynamic_template import pytest from pytest_homeassistant_custom_component.common import async_mock_service @@ -98,13 +98,13 @@ async def test_capability_custom_mode(hass): } ) cap = CustomModeCapability(hass, config, state, const.MODE_INSTANCE_CLEANUP_MODE, { - const.CONF_ENTITY_CUSTOM_MODE_SET_MODE: { + const.CONF_ENTITY_CUSTOM_MODE_SET_MODE: SERVICE_SCHEMA({ CONF_SERVICE: 'test.set_mode', ATTR_ENTITY_ID: 'switch.test', CONF_SERVICE_DATA: { 'service_mode': dynamic_template('mode: {{ mode }}') } - }, + }), }) assert cap.supported() assert cap.retrievable is False @@ -113,13 +113,13 @@ async def test_capability_custom_mode(hass): cap = CustomModeCapability(hass, config, state, const.MODE_INSTANCE_CLEANUP_MODE, { const.CONF_ENTITY_CUSTOM_CAPABILITY_STATE_ENTITY_ID: state.entity_id, - const.CONF_ENTITY_CUSTOM_MODE_SET_MODE: { + const.CONF_ENTITY_CUSTOM_MODE_SET_MODE: SERVICE_SCHEMA({ CONF_SERVICE: 'test.set_mode', ATTR_ENTITY_ID: 'switch.test', CONF_SERVICE_DATA: { 'service_mode': dynamic_template('mode: {{ mode }}') } - }, + }), }) assert cap.supported() assert cap.retrievable @@ -129,7 +129,7 @@ async def test_capability_custom_mode(hass): calls = async_mock_service(hass, 'test', 'set_mode') await cap.set_state(BASIC_DATA, {'value': 'one'}) assert len(calls) == 1 - assert calls[0].data == {'service_mode': 'mode: mode_1', ATTR_ENTITY_ID: 'switch.test'} + assert calls[0].data == {'service_mode': 'mode: mode_1', ATTR_ENTITY_ID: ['switch.test']} async def test_capability_custom_toggle(hass): @@ -146,14 +146,14 @@ async def test_capability_custom_toggle(hass): hass.states.async_set(state.entity_id, state.state) cap = CustomToggleCapability(hass, BASIC_CONFIG, state, 'test_toggle', { const.CONF_ENTITY_CUSTOM_CAPABILITY_STATE_ENTITY_ID: state.entity_id, - const.CONF_ENTITY_CUSTOM_TOGGLE_TURN_ON: { + const.CONF_ENTITY_CUSTOM_TOGGLE_TURN_ON: SERVICE_SCHEMA({ CONF_SERVICE: 'test.turn_on', ATTR_ENTITY_ID: 'switch.test1', - }, - const.CONF_ENTITY_CUSTOM_TOGGLE_TURN_OFF: { + }), + const.CONF_ENTITY_CUSTOM_TOGGLE_TURN_OFF: SERVICE_SCHEMA({ CONF_SERVICE: 'test.turn_off', ATTR_ENTITY_ID: 'switch.test2', - }, + }), }) assert cap.supported() assert cap.retrievable @@ -165,12 +165,12 @@ async def test_capability_custom_toggle(hass): calls_on = async_mock_service(hass, 'test', 'turn_on') await cap.set_state(BASIC_DATA, {'value': True}) assert len(calls_on) == 1 - assert calls_on[0].data == {ATTR_ENTITY_ID: 'switch.test1'} + assert calls_on[0].data == {ATTR_ENTITY_ID: ['switch.test1']} calls_off = async_mock_service(hass, 'test', 'turn_off') await cap.set_state(BASIC_DATA, {'value': False}) assert len(calls_off) == 1 - assert calls_off[0].data == {ATTR_ENTITY_ID: 'switch.test2'} + assert calls_off[0].data == {ATTR_ENTITY_ID: ['switch.test2']} async def test_capability_custom_range_random_access(hass): @@ -183,13 +183,13 @@ async def test_capability_custom_range_random_access(hass): const.CONF_ENTITY_RANGE_MAX: 50, const.CONF_ENTITY_RANGE_PRECISION: 3, }, - const.CONF_ENTITY_CUSTOM_RANGE_SET_VALUE: { + const.CONF_ENTITY_CUSTOM_RANGE_SET_VALUE: SERVICE_SCHEMA({ CONF_SERVICE: 'test.set_value', ATTR_ENTITY_ID: 'input_number.test', CONF_SERVICE_DATA: { 'value': dynamic_template('value: {{ value|int }}') } - }, + }), }) assert cap.supported() assert cap.retrievable @@ -211,7 +211,7 @@ async def test_capability_custom_range_random_access(hass): assert len(calls) == 5 for i in range(0, len(calls)): - assert calls[i].data[ATTR_ENTITY_ID] == 'input_number.test' + assert calls[i].data[ATTR_ENTITY_ID] == ['input_number.test'] assert calls[0].data['value'] == 'value: 40' assert calls[1].data['value'] == 'value: 100' @@ -229,13 +229,13 @@ async def test_capability_custom_range_random_access_no_state(hass): const.CONF_ENTITY_RANGE_MAX: 50, const.CONF_ENTITY_RANGE_PRECISION: 3, }, - const.CONF_ENTITY_CUSTOM_RANGE_SET_VALUE: { + const.CONF_ENTITY_CUSTOM_RANGE_SET_VALUE: SERVICE_SCHEMA({ CONF_SERVICE: 'test.set_value', ATTR_ENTITY_ID: 'input_number.test', CONF_SERVICE_DATA: { 'value': dynamic_template('value: {{ value|int }}') } - }, + }), }) assert cap.supported() assert cap.retrievable is False @@ -248,7 +248,7 @@ async def test_capability_custom_range_random_access_no_state(hass): assert len(calls) == 2 for i in range(0, len(calls)): - assert calls[i].data[ATTR_ENTITY_ID] == 'input_number.test' + assert calls[i].data[ATTR_ENTITY_ID] == ['input_number.test'] assert calls[0].data['value'] == 'value: 40' assert calls[1].data['value'] == 'value: 100' @@ -267,28 +267,27 @@ async def test_capability_custom_range_relative_override_no_state(hass): const.CONF_ENTITY_RANGE_MAX: 99, const.CONF_ENTITY_RANGE_PRECISION: 3, }, - const.CONF_ENTITY_CUSTOM_RANGE_SET_VALUE: { + const.CONF_ENTITY_CUSTOM_RANGE_SET_VALUE: SERVICE_SCHEMA({ CONF_SERVICE: 'test.set_value', ATTR_ENTITY_ID: 'input_number.test', CONF_SERVICE_DATA: { 'value': dynamic_template('value: {{ value|int }}') } - }, - const.CONF_ENTITY_CUSTOM_RANGE_INCREASE_VALUE: { + }), + const.CONF_ENTITY_CUSTOM_RANGE_INCREASE_VALUE: SERVICE_SCHEMA({ CONF_SERVICE: 'test.increase_value', ATTR_ENTITY_ID: 'input_number.test', CONF_SERVICE_DATA: { 'value': dynamic_template('value: {{ value|int }}') } - }, - const.CONF_ENTITY_CUSTOM_RANGE_DECREASE_VALUE: { + }), + const.CONF_ENTITY_CUSTOM_RANGE_DECREASE_VALUE: SERVICE_SCHEMA({ CONF_SERVICE: 'test.decrease_value', ATTR_ENTITY_ID: 'input_number.test', CONF_SERVICE_DATA: { 'value': dynamic_template('value: {{ value|int }}') } - }, - + }), }) assert cap.supported() assert cap.support_random_access @@ -301,7 +300,7 @@ async def test_capability_custom_range_relative_override_no_state(hass): assert len(calls) == 2 for i in range(0, len(calls)): - assert calls[i].data[ATTR_ENTITY_ID] == 'input_number.test' + assert calls[i].data[ATTR_ENTITY_ID] == ['input_number.test'] assert calls[0].data['value'] == 'value: 40' assert calls[1].data['value'] == 'value: 100' @@ -309,13 +308,13 @@ async def test_capability_custom_range_relative_override_no_state(hass): calls = async_mock_service(hass, 'test', 'increase_value') await cap.set_state(BASIC_DATA, {'value': 10, 'relative': True}) assert len(calls) == 1 - assert calls[0].data == {'entity_id': 'input_number.test', 'value': 'value: 10'} + assert calls[0].data == {'entity_id': ['input_number.test'], 'value': 'value: 10'} calls = async_mock_service(hass, 'test', 'decrease_value') await cap.set_state(BASIC_DATA, {'value': 0, 'relative': True}) await cap.set_state(BASIC_DATA, {'value': -3, 'relative': True}) await cap.set_state(BASIC_DATA, {'value': -50, 'relative': True}) assert len(calls) == 3 - assert calls[0].data == {'entity_id': 'input_number.test', 'value': 'value: 0'} - assert calls[1].data == {'entity_id': 'input_number.test', 'value': 'value: -3'} - assert calls[2].data == {'entity_id': 'input_number.test', 'value': 'value: -50'} + assert calls[0].data == {'entity_id': ['input_number.test'], 'value': 'value: 0'} + assert calls[1].data == {'entity_id': ['input_number.test'], 'value': 'value: -3'} + assert calls[2].data == {'entity_id': ['input_number.test'], 'value': 'value: -50'} diff --git a/tests/test_init.py b/tests/test_init.py index 31f1aaca..3f0d843a 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -39,6 +39,13 @@ async def test_valid_config(hass): hass_template = None if (MAJOR_VERSION == 2023 and MINOR_VERSION >= 4) or MAJOR_VERSION >= 2024: hass_template = hass + if MAJOR_VERSION == 2024 and MINOR_VERSION == 8: + hass_template = None + + if (MAJOR_VERSION == 2024 and MINOR_VERSION >= 8) or MAJOR_VERSION >= 2025: + service_key = "action" + else: + service_key = "service" assert config[DOMAIN]['notifier'] == [{ 'oauth_token': 'AgAAAAAEEo2aYYR7m-CEyS7SEiUJjnKez3v3GZe', @@ -115,7 +122,7 @@ async def test_valid_config(hass): 'custom_ranges': { 'channel': { 'set_value': { - 'service': 'media_player.play_media', + service_key: 'media_player.play_media', 'entity_id': [ 'media_player.stupid_tv' ], @@ -125,10 +132,10 @@ async def test_valid_config(hass): } }, 'increase_value': { - 'service': 'script.next_channel_via_ir' + service_key: 'script.next_channel_via_ir' }, 'decrease_value': { - 'service': 'script.prev_channel_via_ir' + service_key: 'script.prev_channel_via_ir' }, 'range': { 'min': 0.0, @@ -137,10 +144,10 @@ async def test_valid_config(hass): }, 'volume': { 'increase_value': { - 'service': 'script.increase_volume' + service_key: 'script.increase_volume' }, 'decrease_value': { - 'service': 'script.decrease_volume' + service_key: 'script.decrease_volume' } } }, @@ -253,13 +260,13 @@ async def test_valid_config(hass): 'ionization': { 'state_entity_id': 'switch.ac_ionizer', 'turn_on': { - 'service': 'switch.turn_on', + service_key: 'switch.turn_on', 'entity_id': [ 'switch.ac_ionizer' ] }, 'turn_off': { - 'service': 'switch.turn_off', + service_key: 'switch.turn_off', 'entity_id': [ 'switch.ac_ionizer' ] @@ -268,13 +275,13 @@ async def test_valid_config(hass): 'backlight': { 'state_entity_id': 'input_boolean.ac_lighting', 'turn_on': { - 'service': 'input_boolean.turn_on', + service_key: 'input_boolean.turn_on', 'entity_id': [ 'input_boolean.ac_lighting' ] }, 'turn_off': { - 'service': 'input_boolean.turn_off', + service_key: 'input_boolean.turn_off', 'entity_id': [ 'input_boolean.ac_lighting' ] @@ -295,7 +302,7 @@ async def test_valid_config(hass): 'temperature': { 'state_attribute': 'temperature', 'set_value': { - 'service': 'climate.set_temperature', + service_key: 'climate.set_temperature', 'data': { 'temperature': Template('{{ value }}', hass_template) }, @@ -629,7 +636,9 @@ async def test_async_setup_update_from_yaml_checksum(hass, hass_admin_user): assert entry.options[const.CONF_PRESSURE_UNIT] == 'mmHg' - if (MAJOR_VERSION == 2023 and MINOR_VERSION >= 4) or MAJOR_VERSION >= 2024: + if (MAJOR_VERSION == 2024 and MINOR_VERSION >= 8) or MAJOR_VERSION >= 2025: + assert entry.data[const.YAML_CONFIG_HASH] == 'e6b81905257fbba74930f7cb95183602' # service -> action + elif (MAJOR_VERSION == 2023 and MINOR_VERSION >= 4) or MAJOR_VERSION >= 2024: assert entry.data[const.YAML_CONFIG_HASH] == '0eedd9f5ee18739bf910b36d2f9f1c6e' else: assert entry.data[const.YAML_CONFIG_HASH] == 'cbe26e947d35ed6222f97e493b32d94f' diff --git a/tests/test_notifier.py b/tests/test_notifier.py index 8d26adfd..736e49bf 100644 --- a/tests/test_notifier.py +++ b/tests/test_notifier.py @@ -413,7 +413,7 @@ async def test_notifier_schedule_initial_report(hass_platform_cloud_connection, hass.bus.async_fire(const.EVENT_DEVICE_DISCOVERY) await hass.async_block_till_done() - assert len(mock_call_later.call_args_list) == 3 + assert len(mock_call_later.call_args_list) in [3, 5] with patch('custom_components.yandex_smart_home.notifier.YandexNotifier.async_initial_report') as mock_ir: await mock_call_later.call_args_list[0][0][2].target(None)