Code styling tweaks to the tests - Part 1 (#86192)

This commit is contained in:
Franck Nijhof 2023-01-20 13:52:46 +01:00 committed by GitHub
parent 79b52a2b41
commit 24fdd588fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 552 additions and 251 deletions

View file

@ -301,7 +301,10 @@ async def async_test_home_assistant(event_loop, load_registries=True):
hass.config_entries = config_entries.ConfigEntries( hass.config_entries = config_entries.ConfigEntries(
hass, hass,
{ {
"_": "Not empty or else some bad checks for hass config in discovery.py breaks" "_": (
"Not empty or else some bad checks for hass config in discovery.py"
" breaks"
)
}, },
) )

View file

@ -44,9 +44,11 @@ async def test_connection_error(
) -> None: ) -> None:
"""Test we show user form on AdGuard Home connection error.""" """Test we show user form on AdGuard Home connection error."""
aioclient_mock.get( aioclient_mock.get(
(
f"{'https' if FIXTURE_USER_INPUT[CONF_SSL] else 'http'}" f"{'https' if FIXTURE_USER_INPUT[CONF_SSL] else 'http'}"
f"://{FIXTURE_USER_INPUT[CONF_HOST]}" f"://{FIXTURE_USER_INPUT[CONF_HOST]}"
f":{FIXTURE_USER_INPUT[CONF_PORT]}/control/status", f":{FIXTURE_USER_INPUT[CONF_PORT]}/control/status"
),
exc=aiohttp.ClientError, exc=aiohttp.ClientError,
) )
@ -65,9 +67,11 @@ async def test_full_flow_implementation(
) -> None: ) -> None:
"""Test registering an integration and finishing flow works.""" """Test registering an integration and finishing flow works."""
aioclient_mock.get( aioclient_mock.get(
(
f"{'https' if FIXTURE_USER_INPUT[CONF_SSL] else 'http'}" f"{'https' if FIXTURE_USER_INPUT[CONF_SSL] else 'http'}"
f"://{FIXTURE_USER_INPUT[CONF_HOST]}" f"://{FIXTURE_USER_INPUT[CONF_HOST]}"
f":{FIXTURE_USER_INPUT[CONF_PORT]}/control/status", f":{FIXTURE_USER_INPUT[CONF_PORT]}/control/status"
),
json={"version": "v0.99.0"}, json={"version": "v0.99.0"},
headers={"Content-Type": CONTENT_TYPE_JSON}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )

View file

@ -212,7 +212,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_triggered - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_triggered "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -230,7 +234,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_disarmed - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_disarmed "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -248,7 +256,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_armed_home - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_armed_home "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -266,7 +278,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_armed_away - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_armed_away "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -284,7 +300,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_armed_night - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_armed_night "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -302,7 +322,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_armed_vacation - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_armed_vacation "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -320,7 +344,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_armed_custom_bypass - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_armed_custom_bypass "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },

View file

@ -232,9 +232,12 @@ async def test_if_fires_on_state_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"triggered - {{ trigger.platform}} - " "triggered "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -251,9 +254,12 @@ async def test_if_fires_on_state_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"disarmed - {{ trigger.platform}} - " "disarmed "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -270,9 +276,12 @@ async def test_if_fires_on_state_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"armed_home - {{ trigger.platform}} - " "armed_home "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -289,9 +298,12 @@ async def test_if_fires_on_state_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"armed_away - {{ trigger.platform}} - " "armed_away "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -308,9 +320,12 @@ async def test_if_fires_on_state_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"armed_night - {{ trigger.platform}} - " "armed_night "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -327,9 +342,12 @@ async def test_if_fires_on_state_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"armed_vacation - {{ trigger.platform}} - " "armed_vacation "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -344,7 +362,8 @@ async def test_if_fires_on_state_change(hass, calls):
assert len(calls) == 1 assert len(calls) == 1
assert ( assert (
calls[0].data["some"] calls[0].data["some"]
== "triggered - device - alarm_control_panel.entity - pending - triggered - None" == "triggered - device - alarm_control_panel.entity - pending - triggered -"
" None"
) )
# Fake that the entity is disarmed. # Fake that the entity is disarmed.
@ -353,7 +372,8 @@ async def test_if_fires_on_state_change(hass, calls):
assert len(calls) == 2 assert len(calls) == 2
assert ( assert (
calls[1].data["some"] calls[1].data["some"]
== "disarmed - device - alarm_control_panel.entity - triggered - disarmed - None" == "disarmed - device - alarm_control_panel.entity - triggered - disarmed -"
" None"
) )
# Fake that the entity is armed home. # Fake that the entity is armed home.
@ -362,7 +382,8 @@ async def test_if_fires_on_state_change(hass, calls):
assert len(calls) == 3 assert len(calls) == 3
assert ( assert (
calls[2].data["some"] calls[2].data["some"]
== "armed_home - device - alarm_control_panel.entity - disarmed - armed_home - None" == "armed_home - device - alarm_control_panel.entity - disarmed - armed_home -"
" None"
) )
# Fake that the entity is armed away. # Fake that the entity is armed away.
@ -371,7 +392,8 @@ async def test_if_fires_on_state_change(hass, calls):
assert len(calls) == 4 assert len(calls) == 4
assert ( assert (
calls[3].data["some"] calls[3].data["some"]
== "armed_away - device - alarm_control_panel.entity - armed_home - armed_away - None" == "armed_away - device - alarm_control_panel.entity - armed_home - armed_away"
" - None"
) )
# Fake that the entity is armed night. # Fake that the entity is armed night.
@ -380,7 +402,8 @@ async def test_if_fires_on_state_change(hass, calls):
assert len(calls) == 5 assert len(calls) == 5
assert ( assert (
calls[4].data["some"] calls[4].data["some"]
== "armed_night - device - alarm_control_panel.entity - armed_away - armed_night - None" == "armed_night - device - alarm_control_panel.entity - armed_away -"
" armed_night - None"
) )
# Fake that the entity is armed vacation. # Fake that the entity is armed vacation.
@ -389,7 +412,8 @@ async def test_if_fires_on_state_change(hass, calls):
assert len(calls) == 6 assert len(calls) == 6
assert ( assert (
calls[5].data["some"] calls[5].data["some"]
== "armed_vacation - device - alarm_control_panel.entity - armed_night - armed_vacation - None" == "armed_vacation - device - alarm_control_panel.entity - armed_night -"
" armed_vacation - None"
) )

View file

@ -114,6 +114,6 @@ async def test_serialize_discovery_recovers(hass, caplog):
assert "Alexa.PowerController" not in interfaces assert "Alexa.PowerController" not in interfaces
assert ( assert (
f"Error serializing Alexa.PowerController discovery" "Error serializing Alexa.PowerController discovery"
f" for {hass.states.get('switch.bla')}" f" for {hass.states.get('switch.bla')}"
) in caplog.text ) in caplog.text

View file

@ -233,9 +233,9 @@ async def test_send_usage_with_supervisor(hass, caplog, aioclient_mock):
): ):
await analytics.send_analytics() await analytics.send_analytics()
assert ( assert (
"'addons': [{'slug': 'test_addon', 'protected': True, 'version': '1', 'auto_update': False}]" "'addons': [{'slug': 'test_addon', 'protected': True, 'version': '1',"
in caplog.text " 'auto_update': False}]"
) ) in caplog.text
assert "'addon_count':" not in caplog.text assert "'addon_count':" not in caplog.text
@ -251,9 +251,9 @@ async def test_send_statistics(hass, caplog, aioclient_mock):
with patch("homeassistant.components.analytics.analytics.HA_VERSION", MOCK_VERSION): with patch("homeassistant.components.analytics.analytics.HA_VERSION", MOCK_VERSION):
await analytics.send_analytics() await analytics.send_analytics()
assert ( assert (
"'state_count': 0, 'automation_count': 0, 'integration_count': 1, 'user_count': 0" "'state_count': 0, 'automation_count': 0, 'integration_count': 1,"
in caplog.text " 'user_count': 0"
) ) in caplog.text
assert "'integrations':" not in caplog.text assert "'integrations':" not in caplog.text
@ -406,9 +406,9 @@ async def test_dev_url_error(hass, aioclient_mock, caplog):
payload = aioclient_mock.mock_calls[0] payload = aioclient_mock.mock_calls[0]
assert str(payload[1]) == ANALYTICS_ENDPOINT_URL_DEV assert str(payload[1]) == ANALYTICS_ENDPOINT_URL_DEV
assert ( assert (
f"Sending analytics failed with statuscode 400 from {ANALYTICS_ENDPOINT_URL_DEV}" "Sending analytics failed with statuscode 400 from"
in caplog.text f" {ANALYTICS_ENDPOINT_URL_DEV}"
) ) in caplog.text
async def test_nightly_endpoint(hass, aioclient_mock): async def test_nightly_endpoint(hass, aioclient_mock):

View file

@ -78,8 +78,14 @@ ADB_PATCH_KEY = "patch_key"
TEST_ENTITY_NAME = "entity_name" TEST_ENTITY_NAME = "entity_name"
MSG_RECONNECT = { MSG_RECONNECT = {
patchers.KEY_PYTHON: f"ADB connection to {HOST}:{DEFAULT_PORT} successfully established", patchers.KEY_PYTHON: (
patchers.KEY_SERVER: f"ADB connection to {HOST}:{DEFAULT_PORT} via ADB server {patchers.ADB_SERVER_HOST}:{DEFAULT_ADB_SERVER_PORT} successfully established", f"ADB connection to {HOST}:{DEFAULT_PORT} successfully established"
),
patchers.KEY_SERVER: (
f"ADB connection to {HOST}:{DEFAULT_PORT} via ADB server"
f" {patchers.ADB_SERVER_HOST}:{DEFAULT_ADB_SERVER_PORT} successfully"
" established"
),
} }
SHELL_RESPONSE_OFF = "" SHELL_RESPONSE_OFF = ""

View file

@ -140,8 +140,8 @@ async def test_source_list(player, state):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"mode", "mode",
[ [
("STEREO"), "STEREO",
("DOLBY_PL"), "DOLBY_PL",
], ],
) )
async def test_select_sound_mode(player, state, mode): async def test_select_sound_mode(player, state, mode):

View file

@ -191,7 +191,9 @@ async def test_doorbell_update_via_pubnub(hass):
"data": { "data": {
"result": { "result": {
"created_at": "2021-03-16T01:07:08.817Z", "created_at": "2021-03-16T01:07:08.817Z",
"secure_url": "https://dyu7azbnaoi74.cloudfront.net/zip/images/zip.jpeg", "secure_url": (
"https://dyu7azbnaoi74.cloudfront.net/zip/images/zip.jpeg"
),
}, },
}, },
}, },
@ -220,7 +222,9 @@ async def test_doorbell_update_via_pubnub(hass):
"format": "jpg", "format": "jpg",
"created_at": "2021-03-16T02:36:26.886Z", "created_at": "2021-03-16T02:36:26.886Z",
"bytes": 14061, "bytes": 14061,
"secure_url": "https://dyu7azbnaoi74.cloudfront.net/images/1f8.jpeg", "secure_url": (
"https://dyu7azbnaoi74.cloudfront.net/images/1f8.jpeg"
),
"url": "https://dyu7azbnaoi74.cloudfront.net/images/1f8.jpeg", "url": "https://dyu7azbnaoi74.cloudfront.net/images/1f8.jpeg",
"etag": "09e839331c4ea59eef28081f2caa0e90", "etag": "09e839331c4ea59eef28081f2caa0e90",
}, },

View file

@ -75,7 +75,7 @@ async def test_diagnostics(hass, hass_client):
"doorbell_low_battery": False, "doorbell_low_battery": False,
"ip_addr": "10.0.1.11", "ip_addr": "10.0.1.11",
"link_quality": 54, "link_quality": 54,
"load_average": "0.50 0.47 0.35 " "1/154 9345", "load_average": "0.50 0.47 0.35 1/154 9345",
"signal_level": -56, "signal_level": -56,
"steady_ac_in": 22.196405, "steady_ac_in": 22.196405,
"temperature": 28.25, "temperature": 28.25,

View file

@ -95,9 +95,9 @@ async def test_unlock_throws_august_api_http_error(hass):
await hass.services.async_call(LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True) await hass.services.async_call(LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True)
except HomeAssistantError as err: except HomeAssistantError as err:
last_err = err last_err = err
assert ( assert str(last_err) == (
str(last_err) "A6697750D607098BAE8D6BAA11EF8063 Name: This should bubble up as its user"
== "A6697750D607098BAE8D6BAA11EF8063 Name: This should bubble up as its user consumable" " consumable"
) )
@ -121,9 +121,9 @@ async def test_lock_throws_august_api_http_error(hass):
await hass.services.async_call(LOCK_DOMAIN, SERVICE_LOCK, data, blocking=True) await hass.services.async_call(LOCK_DOMAIN, SERVICE_LOCK, data, blocking=True)
except HomeAssistantError as err: except HomeAssistantError as err:
last_err = err last_err = err
assert ( assert str(last_err) == (
str(last_err) "A6697750D607098BAE8D6BAA11EF8063 Name: This should bubble up as its user"
== "A6697750D607098BAE8D6BAA11EF8063 Name: This should bubble up as its user consumable" " consumable"
) )

View file

@ -121,8 +121,9 @@ async def test_service_specify_data(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "{{ trigger.platform }} - " "some": (
"{{ trigger.event.event_type }}" "{{ trigger.platform }} - {{ trigger.event.event_type }}"
)
}, },
}, },
} }
@ -1401,9 +1402,9 @@ async def test_automation_bad_config_validation(
# Check we get the expected error message # Check we get the expected error message
assert ( assert (
f"Automation with alias 'bad_automation' {problem} and has been disabled: {details}" f"Automation with alias 'bad_automation' {problem} and has been disabled:"
in caplog.text f" {details}"
) ) in caplog.text
# Make sure one bad automation does not prevent other automations from setting up # Make sure one bad automation does not prevent other automations from setting up
assert hass.states.async_entity_ids("automation") == ["automation.good_automation"] assert hass.states.async_entity_ids("automation") == ["automation.good_automation"]
@ -1969,7 +1970,10 @@ async def test_blueprint_automation(hass, calls):
"a_number": 5, "a_number": 5,
}, },
"Blueprint 'Call service based on event' generated invalid automation", "Blueprint 'Call service based on event' generated invalid automation",
"value should be a string for dictionary value @ data['action'][0]['service']", (
"value should be a string for dictionary value @"
" data['action'][0]['service']"
),
), ),
), ),
) )
@ -2016,10 +2020,10 @@ async def test_blueprint_automation_fails_substitution(hass, caplog):
}, },
) )
assert ( assert (
"Blueprint 'Call service based on event' failed to generate automation with inputs " "Blueprint 'Call service based on event' failed to generate automation with"
"{'trigger_event': 'test_event', 'service_to_call': 'test.automation', 'a_number': 5}:" " inputs {'trigger_event': 'test_event', 'service_to_call': 'test.automation',"
" No substitution found for input blah" in caplog.text " 'a_number': 5}: No substitution found for input blah"
) ) in caplog.text
async def test_trigger_service(hass, calls): async def test_trigger_service(hass, calls):
@ -2204,7 +2208,10 @@ async def test_recursive_automation_starting_script(
"sequence": [ "sequence": [
{"event": "trigger_automation"}, {"event": "trigger_automation"},
{ {
"wait_template": f"{{{{ float(states('sensor.test'), 0) >= {automation_runs} }}}}" "wait_template": (
"{{ float(states('sensor.test'), 0) >="
f" {automation_runs} }}}}"
)
}, },
{"service": "script.script1"}, {"service": "script.script1"},
{"service": "test.script_done"}, {"service": "test.script_done"},

View file

@ -259,7 +259,10 @@ async def test_reauth_flow_update_configuration(hass, config_entry):
"st": "urn:axis-com:service:BasicService:1", "st": "urn:axis-com:service:BasicService:1",
"usn": f"uuid:Upnp-BasicDevice-1_0-{MAC}::urn:axis-com:service:BasicService:1", "usn": f"uuid:Upnp-BasicDevice-1_0-{MAC}::urn:axis-com:service:BasicService:1",
"ext": "", "ext": "",
"server": "Linux/4.14.173-axis8, UPnP/1.0, Portable SDK for UPnP devices/1.8.7", "server": (
"Linux/4.14.173-axis8, UPnP/1.0, Portable SDK for UPnP"
" devices/1.8.7"
),
"deviceType": "urn:schemas-upnp-org:device:Basic:1", "deviceType": "urn:schemas-upnp-org:device:Basic:1",
"friendlyName": f"AXIS M1065-LW - {MAC}", "friendlyName": f"AXIS M1065-LW - {MAC}",
"manufacturer": "AXIS", "manufacturer": "AXIS",

View file

@ -323,7 +323,10 @@ async def test_device_support_mqtt(hass, mqtt_mock, config_entry):
mqtt_mock.async_subscribe.assert_called_with(f"{MAC}/#", mock.ANY, 0, "utf-8") mqtt_mock.async_subscribe.assert_called_with(f"{MAC}/#", mock.ANY, 0, "utf-8")
topic = f"{MAC}/event/tns:onvif/Device/tns:axis/Sensor/PIR/$source/sensor/0" topic = f"{MAC}/event/tns:onvif/Device/tns:axis/Sensor/PIR/$source/sensor/0"
message = b'{"timestamp": 1590258472044, "topic": "onvif:Device/axis:Sensor/PIR", "message": {"source": {"sensor": "0"}, "key": {}, "data": {"state": "1"}}}' message = (
b'{"timestamp": 1590258472044, "topic": "onvif:Device/axis:Sensor/PIR",'
b' "message": {"source": {"sensor": "0"}, "key": {}, "data": {"state": "1"}}}'
)
assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 0 assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 0
async_fire_mqtt_message(hass, topic, message) async_fire_mqtt_message(hass, topic, message)

View file

@ -16,9 +16,9 @@ async def test_setup_with_hassio(
"""Test the setup of the integration with hassio enabled.""" """Test the setup of the integration with hassio enabled."""
assert not await setup_backup_integration(hass=hass, with_hassio=True) assert not await setup_backup_integration(hass=hass, with_hassio=True)
assert ( assert (
"The backup integration is not supported on this installation method, please remove it from your configuration" "The backup integration is not supported on this installation method, please"
in caplog.text " remove it from your configuration"
) ) in caplog.text
async def test_create_service( async def test_create_service(

View file

@ -154,8 +154,8 @@ async def test_getting_backup_that_does_not_exist(
assert ( assert (
f"Removing tracked backup ({TEST_BACKUP.slug}) that " f"Removing tracked backup ({TEST_BACKUP.slug}) that "
f"does not exists on the expected path {TEST_BACKUP.path}" in caplog.text f"does not exists on the expected path {TEST_BACKUP.path}"
) ) in caplog.text
async def test_generate_backup_when_backing_up(hass: HomeAssistant) -> None: async def test_generate_backup_when_backing_up(hass: HomeAssistant) -> None:

View file

@ -678,7 +678,10 @@ async def test_observed_entities(hass):
}, },
{ {
"platform": "template", "platform": "template",
"value_template": "{{is_state('sensor.test_monitored1','on') and is_state('sensor.test_monitored','off')}}", "value_template": (
"{{is_state('sensor.test_monitored1','on') and"
" is_state('sensor.test_monitored','off')}}"
),
"prob_given_true": 0.9, "prob_given_true": 0.9,
"prob_given_false": 0.1, "prob_given_false": 0.1,
}, },
@ -734,7 +737,10 @@ async def test_state_attributes_are_serializable(hass):
}, },
{ {
"platform": "template", "platform": "template",
"value_template": "{{is_state('sensor.test_monitored1','on') and is_state('sensor.test_monitored','off')}}", "value_template": (
"{{is_state('sensor.test_monitored1','on') and"
" is_state('sensor.test_monitored','off')}}"
),
"prob_given_true": 0.9, "prob_given_true": 0.9,
"prob_given_false": 0.1, "prob_given_false": 0.1,
}, },

View file

@ -557,9 +557,9 @@ async def test_wlightbox_on_effect(wlightbox, hass):
) )
assert ( assert (
f"Turning on with effect '{feature_mock.full_name}' failed: NOT IN LIST not in effect list." f"Turning on with effect '{feature_mock.full_name}' failed: "
in str(info.value) "NOT IN LIST not in effect list."
) ) in str(info.value)
await hass.services.async_call( await hass.services.async_call(
"light", "light",

View file

@ -36,7 +36,10 @@ COMMUNITY_POST_INPUTS = {
}, },
"force_brightness": { "force_brightness": {
"name": "Force turn on brightness", "name": "Force turn on brightness",
"description": 'Force the brightness to the set level below, when the "on" button on the remote is pushed and lights turn on.\n', "description": (
'Force the brightness to the set level below, when the "on" button on the'
" remote is pushed and lights turn on.\n"
),
"default": False, "default": False,
"selector": {"boolean": {}}, "selector": {"boolean": {}},
}, },

View file

@ -256,10 +256,10 @@ async def test_domain_blueprints_add_blueprint(domain_bps, blueprint_1):
with patch.object(domain_bps, "_create_file") as create_file_mock: with patch.object(domain_bps, "_create_file") as create_file_mock:
# Should add extension when not present. # Should add extension when not present.
await domain_bps.async_add_blueprint(blueprint_1, "something") await domain_bps.async_add_blueprint(blueprint_1, "something")
assert create_file_mock.call_args[0][1] == ("something.yaml") assert create_file_mock.call_args[0][1] == "something.yaml"
await domain_bps.async_add_blueprint(blueprint_1, "something2.yaml") await domain_bps.async_add_blueprint(blueprint_1, "something2.yaml")
assert create_file_mock.call_args[0][1] == ("something2.yaml") assert create_file_mock.call_args[0][1] == "something2.yaml"
# Should be in cache. # Should be in cache.
with patch.object(domain_bps, "_load_blueprint") as mock_load: with patch.object(domain_bps, "_load_blueprint") as mock_load:

View file

@ -150,9 +150,21 @@ async def test_save_blueprint(hass, aioclient_mock, hass_ws_client):
output_yaml = write_mock.call_args[0][0] output_yaml = write_mock.call_args[0][0]
assert output_yaml in ( assert output_yaml in (
# pure python dumper will quote the value after !input # pure python dumper will quote the value after !input
"blueprint:\n name: Call service based on event\n domain: automation\n input:\n trigger_event:\n selector:\n text: {}\n service_to_call:\n a_number:\n selector:\n number:\n mode: box\n step: 1.0\n source_url: https://github.com/balloob/home-assistant-config/blob/main/blueprints/automation/motion_light.yaml\ntrigger:\n platform: event\n event_type: !input 'trigger_event'\naction:\n service: !input 'service_to_call'\n entity_id: light.kitchen\n" "blueprint:\n name: Call service based on event\n domain: automation\n "
" input:\n trigger_event:\n selector:\n text: {}\n "
" service_to_call:\n a_number:\n selector:\n number:\n "
" mode: box\n step: 1.0\n source_url:"
" https://github.com/balloob/home-assistant-config/blob/main/blueprints/automation/motion_light.yaml\ntrigger:\n"
" platform: event\n event_type: !input 'trigger_event'\naction:\n "
" service: !input 'service_to_call'\n entity_id: light.kitchen\n"
# c dumper will not quote the value after !input # c dumper will not quote the value after !input
"blueprint:\n name: Call service based on event\n domain: automation\n input:\n trigger_event:\n selector:\n text: {}\n service_to_call:\n a_number:\n selector:\n number:\n mode: box\n step: 1.0\n source_url: https://github.com/balloob/home-assistant-config/blob/main/blueprints/automation/motion_light.yaml\ntrigger:\n platform: event\n event_type: !input trigger_event\naction:\n service: !input service_to_call\n entity_id: light.kitchen\n" "blueprint:\n name: Call service based on event\n domain: automation\n "
" input:\n trigger_event:\n selector:\n text: {}\n "
" service_to_call:\n a_number:\n selector:\n number:\n "
" mode: box\n step: 1.0\n source_url:"
" https://github.com/balloob/home-assistant-config/blob/main/blueprints/automation/motion_light.yaml\ntrigger:\n"
" platform: event\n event_type: !input trigger_event\naction:\n service:"
" !input service_to_call\n entity_id: light.kitchen\n"
) )
# Make sure ita parsable and does not raise # Make sure ita parsable and does not raise
assert len(parse_yaml(output_yaml)) > 1 assert len(parse_yaml(output_yaml)) > 1

View file

@ -104,10 +104,10 @@ async def test_diagnostics(
"org.bluez": { "org.bluez": {
"/org/bluez/hci0": { "/org/bluez/hci0": {
"org.bluez.Adapter1": { "org.bluez.Adapter1": {
"Alias": "BlueZ " "5.63", "Alias": "BlueZ 5.63",
"Discovering": False, "Discovering": False,
"Modalias": "usb:v1D6Bp0246d0540", "Modalias": "usb:v1D6Bp0246d0540",
"Name": "BlueZ " "5.63", "Name": "BlueZ 5.63",
}, },
"org.bluez.AdvertisementMonitorManager1": { "org.bluez.AdvertisementMonitorManager1": {
"SupportedFeatures": [], "SupportedFeatures": [],
@ -323,7 +323,7 @@ async def test_diagnostics_macos(
"address": "44:44:33:11:23:45", "address": "44:44:33:11:23:45",
"advertisement": [ "advertisement": [
"wohand", "wohand",
{"1": {"__type": "<class " "'bytes'>", "repr": "b'\\x01'"}}, {"1": {"__type": "<class 'bytes'>", "repr": "b'\\x01'"}},
{}, {},
[], [],
-127, -127,
@ -331,12 +331,12 @@ async def test_diagnostics_macos(
[[]], [[]],
], ],
"device": { "device": {
"__type": "<class " "'bleak.backends.device.BLEDevice'>", "__type": "<class 'bleak.backends.device.BLEDevice'>",
"repr": "BLEDevice(44:44:33:11:23:45, " "wohand)", "repr": "BLEDevice(44:44:33:11:23:45, wohand)",
}, },
"connectable": True, "connectable": True,
"manufacturer_data": { "manufacturer_data": {
"1": {"__type": "<class " "'bytes'>", "repr": "b'\\x01'"} "1": {"__type": "<class 'bytes'>", "repr": "b'\\x01'"}
}, },
"name": "wohand", "name": "wohand",
"rssi": -127, "rssi": -127,
@ -351,7 +351,7 @@ async def test_diagnostics_macos(
"address": "44:44:33:11:23:45", "address": "44:44:33:11:23:45",
"advertisement": [ "advertisement": [
"wohand", "wohand",
{"1": {"__type": "<class " "'bytes'>", "repr": "b'\\x01'"}}, {"1": {"__type": "<class 'bytes'>", "repr": "b'\\x01'"}},
{}, {},
[], [],
-127, -127,
@ -359,12 +359,12 @@ async def test_diagnostics_macos(
[[]], [[]],
], ],
"device": { "device": {
"__type": "<class " "'bleak.backends.device.BLEDevice'>", "__type": "<class 'bleak.backends.device.BLEDevice'>",
"repr": "BLEDevice(44:44:33:11:23:45, " "wohand)", "repr": "BLEDevice(44:44:33:11:23:45, wohand)",
}, },
"connectable": True, "connectable": True,
"manufacturer_data": { "manufacturer_data": {
"1": {"__type": "<class " "'bytes'>", "repr": "b'\\x01'"} "1": {"__type": "<class 'bytes'>", "repr": "b'\\x01'"}
}, },
"name": "wohand", "name": "wohand",
"rssi": -127, "rssi": -127,
@ -384,7 +384,7 @@ async def test_diagnostics_macos(
"wohand", "wohand",
{ {
"1": { "1": {
"__type": "<class " "'bytes'>", "__type": "<class 'bytes'>",
"repr": "b'\\x01'", "repr": "b'\\x01'",
} }
}, },
@ -515,7 +515,7 @@ async def test_diagnostics_remote_adapter(
"address": "44:44:33:11:23:45", "address": "44:44:33:11:23:45",
"advertisement": [ "advertisement": [
"wohand", "wohand",
{"1": {"__type": "<class " "'bytes'>", "repr": "b'\\x01'"}}, {"1": {"__type": "<class 'bytes'>", "repr": "b'\\x01'"}},
{}, {},
[], [],
-127, -127,
@ -524,11 +524,11 @@ async def test_diagnostics_remote_adapter(
], ],
"connectable": False, "connectable": False,
"device": { "device": {
"__type": "<class " "'bleak.backends.device.BLEDevice'>", "__type": "<class 'bleak.backends.device.BLEDevice'>",
"repr": "BLEDevice(44:44:33:11:23:45, " "wohand)", "repr": "BLEDevice(44:44:33:11:23:45, wohand)",
}, },
"manufacturer_data": { "manufacturer_data": {
"1": {"__type": "<class " "'bytes'>", "repr": "b'\\x01'"} "1": {"__type": "<class 'bytes'>", "repr": "b'\\x01'"}
}, },
"name": "wohand", "name": "wohand",
"rssi": -127, "rssi": -127,
@ -543,7 +543,7 @@ async def test_diagnostics_remote_adapter(
"address": "44:44:33:11:23:45", "address": "44:44:33:11:23:45",
"advertisement": [ "advertisement": [
"wohand", "wohand",
{"1": {"__type": "<class " "'bytes'>", "repr": "b'\\x01'"}}, {"1": {"__type": "<class 'bytes'>", "repr": "b'\\x01'"}},
{}, {},
[], [],
-127, -127,
@ -552,11 +552,11 @@ async def test_diagnostics_remote_adapter(
], ],
"connectable": True, "connectable": True,
"device": { "device": {
"__type": "<class " "'bleak.backends.device.BLEDevice'>", "__type": "<class 'bleak.backends.device.BLEDevice'>",
"repr": "BLEDevice(44:44:33:11:23:45, " "wohand)", "repr": "BLEDevice(44:44:33:11:23:45, wohand)",
}, },
"manufacturer_data": { "manufacturer_data": {
"1": {"__type": "<class " "'bytes'>", "repr": "b'\\x01'"} "1": {"__type": "<class 'bytes'>", "repr": "b'\\x01'"}
}, },
"name": "wohand", "name": "wohand",
"rssi": -127, "rssi": -127,
@ -600,7 +600,7 @@ async def test_diagnostics_remote_adapter(
"wohand", "wohand",
{ {
"1": { "1": {
"__type": "<class " "'bytes'>", "__type": "<class 'bytes'>",
"repr": "b'\\x01'", "repr": "b'\\x01'",
} }
}, },

View file

@ -492,7 +492,9 @@ async def test_discovery_match_by_name_connectable_false(
qingping_adv = generate_advertisement_data( qingping_adv = generate_advertisement_data(
local_name="Qingping Motion & Light", local_name="Qingping Motion & Light",
service_data={ service_data={
"0000fdcd-0000-1000-8000-00805f9b34fb": b"H\x12\xcd\xd5`4-X\x08\x04\x01\xe8\x00\x00\x0f\x01{" "0000fdcd-0000-1000-8000-00805f9b34fb": (
b"H\x12\xcd\xd5`4-X\x08\x04\x01\xe8\x00\x00\x0f\x01{"
)
}, },
) )
@ -508,7 +510,9 @@ async def test_discovery_match_by_name_connectable_false(
qingping_adv_with_better_rssi = generate_advertisement_data( qingping_adv_with_better_rssi = generate_advertisement_data(
local_name="Qingping Motion & Light", local_name="Qingping Motion & Light",
service_data={ service_data={
"0000fdcd-0000-1000-8000-00805f9b34fb": b"H\x12\xcd\xd5`4-X\x08\x04\x01\xe8\x00\x00\x0f\x02{" "0000fdcd-0000-1000-8000-00805f9b34fb": (
b"H\x12\xcd\xd5`4-X\x08\x04\x01\xe8\x00\x00\x0f\x02{"
)
}, },
rssi=-30, rssi=-30,
) )
@ -832,7 +836,9 @@ async def test_discovery_match_by_service_data_uuid_when_format_changes(
qingping_format_adv = generate_advertisement_data( qingping_format_adv = generate_advertisement_data(
local_name="Qingping Temp RH M", local_name="Qingping Temp RH M",
service_data={ service_data={
"0000fdcd-0000-1000-8000-00805f9b34fb": b"\x08\x16\xa7%\x144-X\x01\x04\xdb\x00\xa6\x01\x02\x01d" "0000fdcd-0000-1000-8000-00805f9b34fb": (
b"\x08\x16\xa7%\x144-X\x01\x04\xdb\x00\xa6\x01\x02\x01d"
)
}, },
) )
# 1st discovery should not generate a flow because the # 1st discovery should not generate a flow because the

View file

@ -29,7 +29,9 @@ TEMP_HUMI_ENCRYPTED_SERVICE_INFO = BluetoothServiceInfoBleak(
rssi=-63, rssi=-63,
manufacturer_data={}, manufacturer_data={},
service_data={ service_data={
"0000181e-0000-1000-8000-00805f9b34fb": b'\xfb\xa45\xe4\xd3\xc3\x12\xfb\x00\x11"3W\xd9\n\x99' "0000181e-0000-1000-8000-00805f9b34fb": (
b'\xfb\xa45\xe4\xd3\xc3\x12\xfb\x00\x11"3W\xd9\n\x99'
)
}, },
service_uuids=["0000181e-0000-1000-8000-00805f9b34fb"], service_uuids=["0000181e-0000-1000-8000-00805f9b34fb"],
source="local", source="local",
@ -45,7 +47,9 @@ PRST_SERVICE_INFO = BluetoothServiceInfoBleak(
rssi=-63, rssi=-63,
manufacturer_data={}, manufacturer_data={},
service_data={ service_data={
"0000181c-0000-1000-8000-00805f9b34fb": b'\x02\x14\x00\n"\x02\xdd\n\x02\x03{\x12\x02\x0c\n\x0b' "0000181c-0000-1000-8000-00805f9b34fb": (
b'\x02\x14\x00\n"\x02\xdd\n\x02\x03{\x12\x02\x0c\n\x0b'
)
}, },
service_uuids=["0000181c-0000-1000-8000-00805f9b34fb"], service_uuids=["0000181c-0000-1000-8000-00805f9b34fb"],
source="local", source="local",

View file

@ -278,7 +278,9 @@ _LOGGER = logging.getLogger(__name__)
None, None,
[ [
{ {
"sensor_entity": "sensor.test_device_18b2_volatile_organic_compounds", "sensor_entity": (
"sensor.test_device_18b2_volatile_organic_compounds"
),
"friendly_name": "Test Device 18B2 Volatile Organic Compounds", "friendly_name": "Test Device 18B2 Volatile Organic Compounds",
"unit_of_measurement": "µg/m³", "unit_of_measurement": "µg/m³",
"state_class": "measurement", "state_class": "measurement",
@ -630,7 +632,9 @@ async def test_v1_sensors(
None, None,
[ [
{ {
"sensor_entity": "sensor.test_device_18b2_volatile_organic_compounds", "sensor_entity": (
"sensor.test_device_18b2_volatile_organic_compounds"
),
"friendly_name": "Test Device 18B2 Volatile Organic Compounds", "friendly_name": "Test Device 18B2 Volatile Organic Compounds",
"unit_of_measurement": "µg/m³", "unit_of_measurement": "µg/m³",
"state_class": "measurement", "state_class": "measurement",

View file

@ -138,10 +138,12 @@ async def test_if_fires_on_state_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data": { "data": {
"some": ( "some": (
"to - {{ trigger.platform}} - " "to - {{ trigger.platform }} "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.entity_id }} "
"{{ trigger.to_state.state}} - {{ trigger.for }} - " "- {{ trigger.from_state.state }} "
"{{ trigger.id}}" "- {{ trigger.to_state.state }} "
"- {{ trigger.for }} "
"- {{ trigger.id }}"
) )
}, },
}, },

View file

@ -2249,7 +2249,7 @@ async def test_cast_platform_play_media_local_media(
ATTR_ENTITY_ID: entity_id, ATTR_ENTITY_ID: entity_id,
media_player.ATTR_MEDIA_CONTENT_TYPE: "application/vnd.apple.mpegurl", media_player.ATTR_MEDIA_CONTENT_TYPE: "application/vnd.apple.mpegurl",
media_player.ATTR_MEDIA_CONTENT_ID: ( media_player.ATTR_MEDIA_CONTENT_ID: (
f"{network.get_url(hass)}" "/api/hls/bla/master_playlist.m3u8?token=bla" f"{network.get_url(hass)}/api/hls/bla/master_playlist.m3u8?token=bla"
), ),
}, },
blocking=True, blocking=True,

View file

@ -173,7 +173,10 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_hvac_mode - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_hvac_mode - {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -192,7 +195,10 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_preset_mode - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_preset_mode - {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },

View file

@ -518,8 +518,10 @@ async def test_websocket_update_preferences_alexa_report_state(
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
with patch( with patch(
(
"homeassistant.components.cloud.alexa_config.CloudAlexaConfig" "homeassistant.components.cloud.alexa_config.CloudAlexaConfig"
".async_get_access_token", ".async_get_access_token"
),
), patch( ), patch(
"homeassistant.components.cloud.alexa_config.CloudAlexaConfig.set_authorized" "homeassistant.components.cloud.alexa_config.CloudAlexaConfig.set_authorized"
) as set_authorized_mock: ) as set_authorized_mock:
@ -540,8 +542,10 @@ async def test_websocket_update_preferences_require_relink(
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
with patch( with patch(
(
"homeassistant.components.cloud.alexa_config.CloudAlexaConfig" "homeassistant.components.cloud.alexa_config.CloudAlexaConfig"
".async_get_access_token", ".async_get_access_token"
),
side_effect=alexa_errors.RequireRelink, side_effect=alexa_errors.RequireRelink,
), patch( ), patch(
"homeassistant.components.cloud.alexa_config.CloudAlexaConfig.set_authorized" "homeassistant.components.cloud.alexa_config.CloudAlexaConfig.set_authorized"
@ -564,8 +568,10 @@ async def test_websocket_update_preferences_no_token(
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
with patch( with patch(
(
"homeassistant.components.cloud.alexa_config.CloudAlexaConfig" "homeassistant.components.cloud.alexa_config.CloudAlexaConfig"
".async_get_access_token", ".async_get_access_token"
),
side_effect=alexa_errors.NoTokenAvailable, side_effect=alexa_errors.NoTokenAvailable,
), patch( ), patch(
"homeassistant.components.cloud.alexa_config.CloudAlexaConfig.set_authorized" "homeassistant.components.cloud.alexa_config.CloudAlexaConfig.set_authorized"
@ -770,8 +776,10 @@ async def test_sync_alexa_entities_timeout(
"""Test that timeout syncing Alexa entities.""" """Test that timeout syncing Alexa entities."""
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
with patch( with patch(
(
"homeassistant.components.cloud.alexa_config.CloudAlexaConfig" "homeassistant.components.cloud.alexa_config.CloudAlexaConfig"
".async_sync_entities", ".async_sync_entities"
),
side_effect=asyncio.TimeoutError, side_effect=asyncio.TimeoutError,
): ):
await client.send_json({"id": 5, "type": "cloud/alexa/sync"}) await client.send_json({"id": 5, "type": "cloud/alexa/sync"})
@ -787,8 +795,10 @@ async def test_sync_alexa_entities_no_token(
"""Test sync Alexa entities when we have no token.""" """Test sync Alexa entities when we have no token."""
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
with patch( with patch(
(
"homeassistant.components.cloud.alexa_config.CloudAlexaConfig" "homeassistant.components.cloud.alexa_config.CloudAlexaConfig"
".async_sync_entities", ".async_sync_entities"
),
side_effect=alexa_errors.NoTokenAvailable, side_effect=alexa_errors.NoTokenAvailable,
): ):
await client.send_json({"id": 5, "type": "cloud/alexa/sync"}) await client.send_json({"id": 5, "type": "cloud/alexa/sync"})
@ -804,8 +814,10 @@ async def test_enable_alexa_state_report_fail(
"""Test enable Alexa entities state reporting when no token available.""" """Test enable Alexa entities state reporting when no token available."""
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
with patch( with patch(
(
"homeassistant.components.cloud.alexa_config.CloudAlexaConfig" "homeassistant.components.cloud.alexa_config.CloudAlexaConfig"
".async_sync_entities", ".async_sync_entities"
),
side_effect=alexa_errors.NoTokenAvailable, side_effect=alexa_errors.NoTokenAvailable,
): ):
await client.send_json({"id": 5, "type": "cloud/alexa/sync"}) await client.send_json({"id": 5, "type": "cloud/alexa/sync"})

View file

@ -144,8 +144,10 @@ async def test_update_with_json_attrs(hass: HomeAssistant) -> None:
await setup_test_entities( await setup_test_entities(
hass, hass,
{ {
"command": 'echo { \\"key\\": \\"some_json_value\\", \\"another_key\\":\ "command": (
\\"another_json_value\\", \\"key_three\\": \\"value_three\\" }', 'echo { \\"key\\": \\"some_json_value\\", \\"another_key\\": '
'\\"another_json_value\\", \\"key_three\\": \\"value_three\\" }'
),
"json_attributes": ["key", "another_key", "key_three"], "json_attributes": ["key", "another_key", "key_three"],
}, },
) )
@ -218,8 +220,10 @@ async def test_update_with_missing_json_attrs(
await setup_test_entities( await setup_test_entities(
hass, hass,
{ {
"command": 'echo { \\"key\\": \\"some_json_value\\", \\"another_key\\":\ "command": (
\\"another_json_value\\", \\"key_three\\": \\"value_three\\" }', 'echo { \\"key\\": \\"some_json_value\\", \\"another_key\\": '
'\\"another_json_value\\", \\"key_three\\": \\"value_three\\" }'
),
"json_attributes": ["key", "another_key", "key_three", "missing_key"], "json_attributes": ["key", "another_key", "key_three", "missing_key"],
}, },
) )
@ -239,8 +243,10 @@ async def test_update_with_unnecessary_json_attrs(
await setup_test_entities( await setup_test_entities(
hass, hass,
{ {
"command": 'echo { \\"key\\": \\"some_json_value\\", \\"another_key\\":\ "command": (
\\"another_json_value\\", \\"key_three\\": \\"value_three\\" }', 'echo { \\"key\\": \\"some_json_value\\", \\"another_key\\": '
'\\"another_json_value\\", \\"key_three\\": \\"value_three\\" }'
),
"json_attributes": ["key", "another_key"], "json_attributes": ["key", "another_key"],
}, },
) )

View file

@ -93,7 +93,9 @@ async def test_state_value(hass: HomeAssistant) -> None:
"command_on": f"echo 1 > {path}", "command_on": f"echo 1 > {path}",
"command_off": f"echo 0 > {path}", "command_off": f"echo 0 > {path}",
"value_template": '{{ value=="1" }}', "value_template": '{{ value=="1" }}',
"icon_template": '{% if value=="1" %} mdi:on {% else %} mdi:off {% endif %}', "icon_template": (
'{% if value=="1" %} mdi:on {% else %} mdi:off {% endif %}'
),
} }
}, },
) )
@ -142,7 +144,10 @@ async def test_state_json_value(hass: HomeAssistant) -> None:
"command_on": f"echo '{oncmd}' > {path}", "command_on": f"echo '{oncmd}' > {path}",
"command_off": f"echo '{offcmd}' > {path}", "command_off": f"echo '{offcmd}' > {path}",
"value_template": '{{ value_json.status=="ok" }}', "value_template": '{{ value_json.status=="ok" }}',
"icon_template": '{% if value_json.status=="ok" %} mdi:on {% else %} mdi:off {% endif %}', "icon_template": (
'{% if value_json.status=="ok" %} mdi:on'
"{% else %} mdi:off {% endif %}"
),
} }
}, },
) )

View file

@ -929,8 +929,10 @@ async def test_options_flow_with_invalid_data(hass, client):
assert resp.status == HTTPStatus.BAD_REQUEST assert resp.status == HTTPStatus.BAD_REQUEST
data = await resp.json() data = await resp.json()
assert data == { assert data == {
"message": "User input malformed: invalid is not a valid option for " "message": (
"User input malformed: invalid is not a valid option for "
"dictionary value @ data['choices']" "dictionary value @ data['choices']"
)
} }

View file

@ -340,7 +340,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_open - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_open "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -358,7 +362,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_closed - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_closed "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -376,7 +384,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_opening - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_opening "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -394,7 +406,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_closing - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_closing "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -457,14 +473,22 @@ async def test_if_position(hass, calls, caplog, enable_custom_integrations):
"sequence": { "sequence": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_pos_gt_45 - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_pos_gt_45 "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
"default": { "default": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_pos_not_gt_45 - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_pos_not_gt_45 "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -484,7 +508,11 @@ async def test_if_position(hass, calls, caplog, enable_custom_integrations):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_pos_lt_90 - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_pos_lt_90 "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -504,7 +532,11 @@ async def test_if_position(hass, calls, caplog, enable_custom_integrations):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_pos_gt_45_lt_90 - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_pos_gt_45_lt_90 "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -586,14 +618,22 @@ async def test_if_tilt_position(hass, calls, caplog, enable_custom_integrations)
"sequence": { "sequence": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_pos_gt_45 - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_pos_gt_45 "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
"default": { "default": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_pos_not_gt_45 - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_pos_not_gt_45 "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -613,7 +653,11 @@ async def test_if_tilt_position(hass, calls, caplog, enable_custom_integrations)
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_pos_lt_90 - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_pos_lt_90 "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -633,7 +677,11 @@ async def test_if_tilt_position(hass, calls, caplog, enable_custom_integrations)
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_pos_gt_45_lt_90 - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_pos_gt_45_lt_90 "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },

View file

@ -359,9 +359,12 @@ async def test_if_fires_on_state_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"opened - {{ trigger.platform}} - " "opened "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -378,9 +381,12 @@ async def test_if_fires_on_state_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"closed - {{ trigger.platform}} - " "closed "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -397,9 +403,12 @@ async def test_if_fires_on_state_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"opening - {{ trigger.platform}} - " "opening "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -416,9 +425,12 @@ async def test_if_fires_on_state_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"closing - {{ trigger.platform}} - " "closing "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -543,9 +555,12 @@ async def test_if_fires_on_position(hass, calls, enable_custom_integrations):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"is_pos_gt_45 - {{ trigger.platform}} - " "is_pos_gt_45 "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -565,9 +580,12 @@ async def test_if_fires_on_position(hass, calls, enable_custom_integrations):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"is_pos_lt_90 - {{ trigger.platform}} - " "is_pos_lt_90 "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -588,9 +606,12 @@ async def test_if_fires_on_position(hass, calls, enable_custom_integrations):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"is_pos_gt_45_lt_90 - {{ trigger.platform}} - " "is_pos_gt_45_lt_90 "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -611,7 +632,10 @@ async def test_if_fires_on_position(hass, calls, enable_custom_integrations):
[calls[0].data["some"], calls[1].data["some"], calls[2].data["some"]] [calls[0].data["some"], calls[1].data["some"], calls[2].data["some"]]
) == sorted( ) == sorted(
[ [
"is_pos_gt_45_lt_90 - device - cover.set_position_cover - closed - open - None", (
"is_pos_gt_45_lt_90 - device - cover.set_position_cover - closed - open"
" - None"
),
"is_pos_lt_90 - device - cover.set_position_cover - closed - open - None", "is_pos_lt_90 - device - cover.set_position_cover - closed - open - None",
"is_pos_gt_45 - device - cover.set_position_cover - open - closed - None", "is_pos_gt_45 - device - cover.set_position_cover - open - closed - None",
] ]
@ -670,9 +694,12 @@ async def test_if_fires_on_tilt_position(hass, calls, enable_custom_integrations
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"is_pos_gt_45 - {{ trigger.platform}} - " "is_pos_gt_45 "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -692,9 +719,12 @@ async def test_if_fires_on_tilt_position(hass, calls, enable_custom_integrations
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"is_pos_lt_90 - {{ trigger.platform}} - " "is_pos_lt_90 "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -715,9 +745,12 @@ async def test_if_fires_on_tilt_position(hass, calls, enable_custom_integrations
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"is_pos_gt_45_lt_90 - {{ trigger.platform}} - " "is_pos_gt_45_lt_90 "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -740,7 +773,10 @@ async def test_if_fires_on_tilt_position(hass, calls, enable_custom_integrations
[calls[0].data["some"], calls[1].data["some"], calls[2].data["some"]] [calls[0].data["some"], calls[1].data["some"], calls[2].data["some"]]
) == sorted( ) == sorted(
[ [
"is_pos_gt_45_lt_90 - device - cover.set_position_cover - closed - open - None", (
"is_pos_gt_45_lt_90 - device - cover.set_position_cover - closed - open"
" - None"
),
"is_pos_lt_90 - device - cover.set_position_cover - closed - open - None", "is_pos_lt_90 - device - cover.set_position_cover - closed - open - None",
"is_pos_gt_45 - device - cover.set_position_cover - open - closed - None", "is_pos_gt_45 - device - cover.set_position_cover - open - closed - None",
] ]

View file

@ -34,6 +34,5 @@ async def test_setting_up_demo(mock_history, hass):
json.dumps(hass.states.async_all(), cls=JSONEncoder) json.dumps(hass.states.async_all(), cls=JSONEncoder)
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
pytest.fail( pytest.fail(
"Unable to convert all demo entities to JSON. " "Unable to convert all demo entities to JSON. Wrong data in state machine!"
"Wrong data in state machine!"
) )

View file

@ -47,7 +47,10 @@ async def test_demo_speech_wrong_metadata(hass_client):
response = await client.post( response = await client.post(
"/api/stt/demo", "/api/stt/demo",
headers={ headers={
"X-Speech-Content": "format=wav; codec=pcm; sample_rate=8000; bit_rate=16; channel=1; language=de" "X-Speech-Content": (
"format=wav; codec=pcm; sample_rate=8000; bit_rate=16; channel=1;"
" language=de"
)
}, },
data=b"Test", data=b"Test",
) )
@ -61,7 +64,10 @@ async def test_demo_speech(hass_client):
response = await client.post( response = await client.post(
"/api/stt/demo", "/api/stt/demo",
headers={ headers={
"X-Speech-Content": "format=wav; codec=pcm; sample_rate=16000; bit_rate=16; channel=2; language=de" "X-Speech-Content": (
"format=wav; codec=pcm; sample_rate=16000; bit_rate=16; channel=2;"
" language=de"
)
}, },
data=b"Test", data=b"Test",
) )

View file

@ -136,7 +136,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_home - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_home "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -154,7 +158,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_not_home - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_not_home "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },

View file

@ -165,9 +165,13 @@ async def test_if_fires_on_zone_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"enter - {{ trigger.platform}} - " "enter "
"{{ trigger.entity_id}} - {{ trigger.from_state.attributes.longitude|round(3)}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.attributes.longitude|round(3)}}" "- {{ trigger.entity_id }} "
"- {{ "
" trigger.from_state.attributes.longitude|round(3) "
" }} "
"- {{ trigger.to_state.attributes.longitude|round(3) }}"
) )
}, },
}, },
@ -185,9 +189,13 @@ async def test_if_fires_on_zone_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"leave - {{ trigger.platform}} - " "leave "
"{{ trigger.entity_id}} - {{ trigger.from_state.attributes.longitude|round(3)}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.attributes.longitude|round(3)}}" "- {{ trigger.entity_id }} "
"- {{ "
" trigger.from_state.attributes.longitude|round(3) "
" }} "
"- {{ trigger.to_state.attributes.longitude|round(3)}}"
) )
}, },
}, },

View file

@ -75,7 +75,7 @@ async def test_reading_broken_yaml_config(hass):
"badkey.yaml": "@:\n name: Device", "badkey.yaml": "@:\n name: Device",
"noname.yaml": "my_device:\n", "noname.yaml": "my_device:\n",
"allok.yaml": "My Device:\n name: Device", "allok.yaml": "My Device:\n name: Device",
"oneok.yaml": ("My Device!:\n name: Device\nbad_device:\n nme: Device"), "oneok.yaml": "My Device!:\n name: Device\nbad_device:\n nme: Device",
} }
args = {"hass": hass, "consider_home": timedelta(seconds=60)} args = {"hass": hass, "consider_home": timedelta(seconds=60)}
with patch_yaml_files(files): with patch_yaml_files(files):

View file

@ -483,7 +483,7 @@ async def test_dhcp_invalid_option(hass):
("requested_addr", "192.168.208.55"), ("requested_addr", "192.168.208.55"),
("server_id", "192.168.208.1"), ("server_id", "192.168.208.1"),
("param_req_list", [1, 3, 28, 6]), ("param_req_list", [1, 3, 28, 6]),
("hostname"), "hostname",
] ]
async_handle_dhcp_packet = await _async_get_handle_dhcp_packet( async_handle_dhcp_packet = await _async_get_handle_dhcp_packet(

View file

@ -674,7 +674,9 @@ async def test_play_media_stopped(
{ {
ATTR_ENTITY_ID: mock_entity_id, ATTR_ENTITY_ID: mock_entity_id,
mp_const.ATTR_MEDIA_CONTENT_TYPE: MediaType.MUSIC, mp_const.ATTR_MEDIA_CONTENT_TYPE: MediaType.MUSIC,
mp_const.ATTR_MEDIA_CONTENT_ID: "http://198.51.100.20:8200/MediaItems/17621.mp3", mp_const.ATTR_MEDIA_CONTENT_ID: (
"http://198.51.100.20:8200/MediaItems/17621.mp3"
),
mp_const.ATTR_MEDIA_ENQUEUE: False, mp_const.ATTR_MEDIA_ENQUEUE: False,
}, },
blocking=True, blocking=True,
@ -706,7 +708,9 @@ async def test_play_media_playing(
{ {
ATTR_ENTITY_ID: mock_entity_id, ATTR_ENTITY_ID: mock_entity_id,
mp_const.ATTR_MEDIA_CONTENT_TYPE: MediaType.MUSIC, mp_const.ATTR_MEDIA_CONTENT_TYPE: MediaType.MUSIC,
mp_const.ATTR_MEDIA_CONTENT_ID: "http://198.51.100.20:8200/MediaItems/17621.mp3", mp_const.ATTR_MEDIA_CONTENT_ID: (
"http://198.51.100.20:8200/MediaItems/17621.mp3"
),
mp_const.ATTR_MEDIA_ENQUEUE: False, mp_const.ATTR_MEDIA_ENQUEUE: False,
}, },
blocking=True, blocking=True,
@ -739,7 +743,9 @@ async def test_play_media_no_autoplay(
{ {
ATTR_ENTITY_ID: mock_entity_id, ATTR_ENTITY_ID: mock_entity_id,
mp_const.ATTR_MEDIA_CONTENT_TYPE: MediaType.MUSIC, mp_const.ATTR_MEDIA_CONTENT_TYPE: MediaType.MUSIC,
mp_const.ATTR_MEDIA_CONTENT_ID: "http://198.51.100.20:8200/MediaItems/17621.mp3", mp_const.ATTR_MEDIA_CONTENT_ID: (
"http://198.51.100.20:8200/MediaItems/17621.mp3"
),
mp_const.ATTR_MEDIA_ENQUEUE: False, mp_const.ATTR_MEDIA_ENQUEUE: False,
mp_const.ATTR_MEDIA_EXTRA: {"autoplay": False}, mp_const.ATTR_MEDIA_EXTRA: {"autoplay": False},
}, },
@ -770,7 +776,9 @@ async def test_play_media_metadata(
{ {
ATTR_ENTITY_ID: mock_entity_id, ATTR_ENTITY_ID: mock_entity_id,
mp_const.ATTR_MEDIA_CONTENT_TYPE: MediaType.MUSIC, mp_const.ATTR_MEDIA_CONTENT_TYPE: MediaType.MUSIC,
mp_const.ATTR_MEDIA_CONTENT_ID: "http://198.51.100.20:8200/MediaItems/17621.mp3", mp_const.ATTR_MEDIA_CONTENT_ID: (
"http://198.51.100.20:8200/MediaItems/17621.mp3"
),
mp_const.ATTR_MEDIA_ENQUEUE: False, mp_const.ATTR_MEDIA_ENQUEUE: False,
mp_const.ATTR_MEDIA_EXTRA: { mp_const.ATTR_MEDIA_EXTRA: {
"title": "Mock song", "title": "Mock song",
@ -800,7 +808,9 @@ async def test_play_media_metadata(
{ {
ATTR_ENTITY_ID: mock_entity_id, ATTR_ENTITY_ID: mock_entity_id,
mp_const.ATTR_MEDIA_CONTENT_TYPE: MediaType.TVSHOW, mp_const.ATTR_MEDIA_CONTENT_TYPE: MediaType.TVSHOW,
mp_const.ATTR_MEDIA_CONTENT_ID: "http://198.51.100.20:8200/MediaItems/123.mkv", mp_const.ATTR_MEDIA_CONTENT_ID: (
"http://198.51.100.20:8200/MediaItems/123.mkv"
),
mp_const.ATTR_MEDIA_ENQUEUE: False, mp_const.ATTR_MEDIA_ENQUEUE: False,
mp_const.ATTR_MEDIA_EXTRA: { mp_const.ATTR_MEDIA_EXTRA: {
"title": "Mock show", "title": "Mock show",
@ -833,7 +843,9 @@ async def test_play_media_local_source(
{ {
ATTR_ENTITY_ID: mock_entity_id, ATTR_ENTITY_ID: mock_entity_id,
mp_const.ATTR_MEDIA_CONTENT_TYPE: "video/mp4", mp_const.ATTR_MEDIA_CONTENT_TYPE: "video/mp4",
mp_const.ATTR_MEDIA_CONTENT_ID: "media-source://media_source/local/Epic Sax Guy 10 Hours.mp4", mp_const.ATTR_MEDIA_CONTENT_ID: (
"media-source://media_source/local/Epic Sax Guy 10 Hours.mp4"
),
}, },
blocking=True, blocking=True,
) )
@ -888,7 +900,9 @@ async def test_play_media_didl_metadata(
{ {
ATTR_ENTITY_ID: mock_entity_id, ATTR_ENTITY_ID: mock_entity_id,
mp_const.ATTR_MEDIA_CONTENT_TYPE: "video/mp4", mp_const.ATTR_MEDIA_CONTENT_TYPE: "video/mp4",
mp_const.ATTR_MEDIA_CONTENT_ID: "media-source://media_source/local/Epic Sax Guy 10 Hours.mp4", mp_const.ATTR_MEDIA_CONTENT_ID: (
"media-source://media_source/local/Epic Sax Guy 10 Hours.mp4"
),
}, },
blocking=True, blocking=True,
) )
@ -1011,7 +1025,9 @@ async def test_browse_media(
"title": "Epic Sax Guy 10 Hours.mp4", "title": "Epic Sax Guy 10 Hours.mp4",
"media_class": "video", "media_class": "video",
"media_content_type": "video/mp4", "media_content_type": "video/mp4",
"media_content_id": "media-source://media_source/local/Epic Sax Guy 10 Hours.mp4", "media_content_id": (
"media-source://media_source/local/Epic Sax Guy 10 Hours.mp4"
),
"can_play": True, "can_play": True,
"can_expand": False, "can_expand": False,
"thumbnail": None, "thumbnail": None,
@ -1104,7 +1120,9 @@ async def test_browse_media_unfiltered(
"title": "Epic Sax Guy 10 Hours.mp4", "title": "Epic Sax Guy 10 Hours.mp4",
"media_class": "video", "media_class": "video",
"media_content_type": "video/mp4", "media_content_type": "video/mp4",
"media_content_id": "media-source://media_source/local/Epic Sax Guy 10 Hours.mp4", "media_content_id": (
"media-source://media_source/local/Epic Sax Guy 10 Hours.mp4"
),
"can_play": True, "can_play": True,
"can_expand": False, "can_expand": False,
"thumbnail": None, "thumbnail": None,
@ -1280,7 +1298,9 @@ async def test_unavailable_device(
mp_const.SERVICE_PLAY_MEDIA, mp_const.SERVICE_PLAY_MEDIA,
{ {
mp_const.ATTR_MEDIA_CONTENT_TYPE: MediaType.MUSIC, mp_const.ATTR_MEDIA_CONTENT_TYPE: MediaType.MUSIC,
mp_const.ATTR_MEDIA_CONTENT_ID: "http://198.51.100.20:8200/MediaItems/17621.mp3", mp_const.ATTR_MEDIA_CONTENT_ID: (
"http://198.51.100.20:8200/MediaItems/17621.mp3"
),
mp_const.ATTR_MEDIA_ENQUEUE: False, mp_const.ATTR_MEDIA_ENQUEUE: False,
}, },
), ),

View file

@ -851,7 +851,9 @@ async def test_validation_gas(
"type": "entity_unexpected_unit_gas_price", "type": "entity_unexpected_unit_gas_price",
"affected_entities": {("sensor.gas_price_2", "EUR/invalid")}, "affected_entities": {("sensor.gas_price_2", "EUR/invalid")},
"translation_placeholders": { "translation_placeholders": {
"price_units": "EUR/GJ, EUR/kWh, EUR/MWh, EUR/Wh, EUR/CCF, EUR/ft³, EUR/m³" "price_units": (
"EUR/GJ, EUR/kWh, EUR/MWh, EUR/Wh, EUR/CCF, EUR/ft³, EUR/m³"
)
}, },
}, },
], ],

View file

@ -163,7 +163,9 @@ async def test_save_preferences(
assert msg["result"] == { assert msg["result"] == {
"cost_sensors": { "cost_sensors": {
"sensor.heat_pump_meter_2": "sensor.heat_pump_meter_2_cost", "sensor.heat_pump_meter_2": "sensor.heat_pump_meter_2_cost",
"sensor.return_to_grid_offpeak": "sensor.return_to_grid_offpeak_compensation", "sensor.return_to_grid_offpeak": (
"sensor.return_to_grid_offpeak_compensation"
),
}, },
"solar_forecast_domains": ["some_domain"], "solar_forecast_domains": ["some_domain"],
} }

View file

@ -136,7 +136,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_on - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_on "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },
@ -154,7 +158,11 @@ async def test_if_state(hass, calls):
"action": { "action": {
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": "is_off - {{ trigger.platform }} - {{ trigger.event.event_type }}" "some": (
"is_off "
"- {{ trigger.platform }} "
"- {{ trigger.event.event_type }}"
)
}, },
}, },
}, },

View file

@ -163,9 +163,12 @@ async def test_if_fires_on_state_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"turn_on - {{ trigger.platform}} - " "turn_on "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -182,9 +185,12 @@ async def test_if_fires_on_state_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"turn_off - {{ trigger.platform}} - " "turn_off "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },
@ -201,9 +207,12 @@ async def test_if_fires_on_state_change(hass, calls):
"service": "test.automation", "service": "test.automation",
"data_template": { "data_template": {
"some": ( "some": (
"turn_on_or_off - {{ trigger.platform}} - " "turn_on_or_off "
"{{ trigger.entity_id}} - {{ trigger.from_state.state}} - " "- {{ trigger.platform }} "
"{{ trigger.to_state.state}} - {{ trigger.for }}" "- {{ trigger.entity_id }} "
"- {{ trigger.from_state.state }} "
"- {{ trigger.to_state.state }} "
"- {{ trigger.for }}"
) )
}, },
}, },

View file

@ -480,8 +480,10 @@ def mock_device_tracker_conf():
devices.append(entity) devices.append(entity)
with patch( with patch(
(
"homeassistant.components.device_tracker.legacy" "homeassistant.components.device_tracker.legacy"
".DeviceTracker.async_update_config", ".DeviceTracker.async_update_config"
),
side_effect=mock_update_config, side_effect=mock_update_config,
), patch( ), patch(
"homeassistant.components.device_tracker.legacy.async_load_config", "homeassistant.components.device_tracker.legacy.async_load_config",

View file

@ -1177,9 +1177,9 @@ async def test_component_config_exceptions(hass, caplog):
) == {"test_domain": []} ) == {"test_domain": []}
assert "ValueError: broken" in caplog.text assert "ValueError: broken" in caplog.text
assert ( assert (
"Unknown error validating test_platform platform config with test_domain component platform schema" "Unknown error validating test_platform platform config "
in caplog.text "with test_domain component platform schema"
) ) in caplog.text
# platform.PLATFORM_SCHEMA # platform.PLATFORM_SCHEMA
caplog.clear() caplog.clear()
@ -1204,8 +1204,8 @@ async def test_component_config_exceptions(hass, caplog):
) == {"test_domain": []} ) == {"test_domain": []}
assert "ValueError: broken" in caplog.text assert "ValueError: broken" in caplog.text
assert ( assert (
"Unknown error validating config for test_platform platform for test_domain component with PLATFORM_SCHEMA" "Unknown error validating config for test_platform platform for test_domain"
in caplog.text " component with PLATFORM_SCHEMA" in caplog.text
) )
# get_platform("config") raising # get_platform("config") raising
@ -1219,7 +1219,10 @@ async def test_component_config_exceptions(hass, caplog):
domain="test_domain", domain="test_domain",
get_platform=Mock( get_platform=Mock(
side_effect=ImportError( side_effect=ImportError(
"ModuleNotFoundError: No module named 'not_installed_something'", (
"ModuleNotFoundError: No module named"
" 'not_installed_something'"
),
name="not_installed_something", name="not_installed_something",
) )
), ),
@ -1228,8 +1231,8 @@ async def test_component_config_exceptions(hass, caplog):
is None is None
) )
assert ( assert (
"Error importing config platform test_domain: ModuleNotFoundError: No module named 'not_installed_something'" "Error importing config platform test_domain: ModuleNotFoundError: No module"
in caplog.text " named 'not_installed_something'" in caplog.text
) )
# get_component raising # get_component raising

View file

@ -897,9 +897,10 @@ async def test_setup_raise_not_ready(hass, caplog):
assert len(mock_call.mock_calls) == 1 assert len(mock_call.mock_calls) == 1
assert ( assert (
"Config entry 'test_title' for test integration not ready yet: The internet connection is offline" "Config entry 'test_title' for test integration not ready yet:"
in caplog.text " The internet connection is offline"
) ) in caplog.text
p_hass, p_wait_time, p_setup = mock_call.mock_calls[0][1] p_hass, p_wait_time, p_setup = mock_call.mock_calls[0][1]
assert p_hass is hass assert p_hass is hass
@ -932,8 +933,8 @@ async def test_setup_raise_not_ready_from_exception(hass, caplog):
assert len(mock_call.mock_calls) == 1 assert len(mock_call.mock_calls) == 1
assert ( assert (
"Config entry 'test_title' for test integration not ready yet: The device dropped the connection" "Config entry 'test_title' for test integration not ready yet: The device"
in caplog.text " dropped the connection" in caplog.text
) )
@ -2950,8 +2951,8 @@ async def test_setup_not_raise_entry_error_from_future_coordinator_update(hass,
await entry.async_setup(hass) await entry.async_setup(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
assert ( assert (
"Config entry setup failed while fetching any data: Incompatible firmware version" "Config entry setup failed while fetching any data: Incompatible firmware"
in caplog.text " version" in caplog.text
) )
assert entry.state is config_entries.ConfigEntryState.LOADED assert entry.state is config_entries.ConfigEntryState.LOADED

View file

@ -722,8 +722,7 @@ def test_state_repr():
datetime(1984, 12, 8, 12, 0, 0), datetime(1984, 12, 8, 12, 0, 0),
) )
) )
== "<state happy.happy=on; brightness=144 @ " == "<state happy.happy=on; brightness=144 @ 1984-12-08T12:00:00+00:00>"
"1984-12-08T12:00:00+00:00>"
) )

View file

@ -138,16 +138,16 @@ async def test_custom_integration_version_not_valid(
await loader.async_get_integration(hass, "test_no_version") await loader.async_get_integration(hass, "test_no_version")
assert ( assert (
"The custom integration 'test_no_version' does not have a version key in the manifest file and was blocked from loading." "The custom integration 'test_no_version' does not have a version key in the"
in caplog.text " manifest file and was blocked from loading."
) ) in caplog.text
with pytest.raises(loader.IntegrationNotFound): with pytest.raises(loader.IntegrationNotFound):
await loader.async_get_integration(hass, "test2") await loader.async_get_integration(hass, "test2")
assert ( assert (
"The custom integration 'test_bad_version' does not have a valid version key (bad) in the manifest file and was blocked from loading." "The custom integration 'test_bad_version' does not have a valid version key"
in caplog.text " (bad) in the manifest file and was blocked from loading."
) ) in caplog.text
async def test_get_integration(hass): async def test_get_integration(hass):