Skip to content

Commit

Permalink
Fix tests for 2024.8
Browse files Browse the repository at this point in the history
  • Loading branch information
dext0r committed Oct 25, 2024
1 parent f5ab7e8 commit fa79308
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 43 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
59 changes: 29 additions & 30 deletions tests/test_capability_custom.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -301,21 +300,21 @@ 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'

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'}
31 changes: 20 additions & 11 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'
],
Expand All @@ -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,
Expand All @@ -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'
}
}
},
Expand Down Expand Up @@ -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'
]
Expand All @@ -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'
]
Expand All @@ -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)
},
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion tests/test_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fa79308

Please sign in to comment.