Enable Ruff A001 (#115654)
This commit is contained in:
parent
8754b12d08
commit
895f73d8e4
36 changed files with 347 additions and 321 deletions
|
@ -291,8 +291,11 @@ def websocket_list_runs(
|
||||||
msg["id"],
|
msg["id"],
|
||||||
{
|
{
|
||||||
"pipeline_runs": [
|
"pipeline_runs": [
|
||||||
{"pipeline_run_id": id, "timestamp": pipeline_run.timestamp}
|
{
|
||||||
for id, pipeline_run in pipeline_debug.items()
|
"pipeline_run_id": pipeline_run_id,
|
||||||
|
"timestamp": pipeline_run.timestamp,
|
||||||
|
}
|
||||||
|
for pipeline_run_id, pipeline_run in pipeline_debug.items()
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -73,6 +73,6 @@ async def async_remove_config_entry_device(
|
||||||
return not device_entry.identifiers.intersection(
|
return not device_entry.identifiers.intersection(
|
||||||
(
|
(
|
||||||
(DOMAIN, coordinator.server_id),
|
(DOMAIN, coordinator.server_id),
|
||||||
*((DOMAIN, id) for id in coordinator.device_ids),
|
*((DOMAIN, device_id) for device_id in coordinator.device_ids),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -278,9 +278,9 @@ def get_best_stream_youtube(formats: list[dict[str, Any]]) -> str:
|
||||||
|
|
||||||
return get_best_stream(
|
return get_best_stream(
|
||||||
[
|
[
|
||||||
format
|
stream_format
|
||||||
for format in formats
|
for stream_format in formats
|
||||||
if format.get("acodec", "none") != "none"
|
if stream_format.get("acodec", "none") != "none"
|
||||||
and format.get("vcodec", "none") != "none"
|
and stream_format.get("vcodec", "none") != "none"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
|
@ -73,7 +73,7 @@ class NestDeviceInfo:
|
||||||
"""Return device suggested area based on the Google Home room."""
|
"""Return device suggested area based on the Google Home room."""
|
||||||
if parent_relations := self._device.parent_relations:
|
if parent_relations := self._device.parent_relations:
|
||||||
items = sorted(parent_relations.items())
|
items = sorted(parent_relations.items())
|
||||||
names = [name for id, name in items]
|
names = [name for _, name in items]
|
||||||
return " ".join(names)
|
return " ".join(names)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -36,33 +36,33 @@ class OneWireBinarySensorEntityDescription(
|
||||||
DEVICE_BINARY_SENSORS: dict[str, tuple[OneWireBinarySensorEntityDescription, ...]] = {
|
DEVICE_BINARY_SENSORS: dict[str, tuple[OneWireBinarySensorEntityDescription, ...]] = {
|
||||||
"12": tuple(
|
"12": tuple(
|
||||||
OneWireBinarySensorEntityDescription(
|
OneWireBinarySensorEntityDescription(
|
||||||
key=f"sensed.{id}",
|
key=f"sensed.{device_key}",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
read_mode=READ_MODE_BOOL,
|
read_mode=READ_MODE_BOOL,
|
||||||
translation_key="sensed_id",
|
translation_key="sensed_id",
|
||||||
translation_placeholders={"id": str(id)},
|
translation_placeholders={"id": str(device_key)},
|
||||||
)
|
)
|
||||||
for id in DEVICE_KEYS_A_B
|
for device_key in DEVICE_KEYS_A_B
|
||||||
),
|
),
|
||||||
"29": tuple(
|
"29": tuple(
|
||||||
OneWireBinarySensorEntityDescription(
|
OneWireBinarySensorEntityDescription(
|
||||||
key=f"sensed.{id}",
|
key=f"sensed.{device_key}",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
read_mode=READ_MODE_BOOL,
|
read_mode=READ_MODE_BOOL,
|
||||||
translation_key="sensed_id",
|
translation_key="sensed_id",
|
||||||
translation_placeholders={"id": str(id)},
|
translation_placeholders={"id": str(device_key)},
|
||||||
)
|
)
|
||||||
for id in DEVICE_KEYS_0_7
|
for device_key in DEVICE_KEYS_0_7
|
||||||
),
|
),
|
||||||
"3A": tuple(
|
"3A": tuple(
|
||||||
OneWireBinarySensorEntityDescription(
|
OneWireBinarySensorEntityDescription(
|
||||||
key=f"sensed.{id}",
|
key=f"sensed.{device_key}",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
read_mode=READ_MODE_BOOL,
|
read_mode=READ_MODE_BOOL,
|
||||||
translation_key="sensed_id",
|
translation_key="sensed_id",
|
||||||
translation_placeholders={"id": str(id)},
|
translation_placeholders={"id": str(device_key)},
|
||||||
)
|
)
|
||||||
for id in DEVICE_KEYS_A_B
|
for device_key in DEVICE_KEYS_A_B
|
||||||
),
|
),
|
||||||
"EF": (), # "HobbyBoard": special
|
"EF": (), # "HobbyBoard": special
|
||||||
}
|
}
|
||||||
|
@ -71,15 +71,15 @@ DEVICE_BINARY_SENSORS: dict[str, tuple[OneWireBinarySensorEntityDescription, ...
|
||||||
HOBBYBOARD_EF: dict[str, tuple[OneWireBinarySensorEntityDescription, ...]] = {
|
HOBBYBOARD_EF: dict[str, tuple[OneWireBinarySensorEntityDescription, ...]] = {
|
||||||
"HB_HUB": tuple(
|
"HB_HUB": tuple(
|
||||||
OneWireBinarySensorEntityDescription(
|
OneWireBinarySensorEntityDescription(
|
||||||
key=f"hub/short.{id}",
|
key=f"hub/short.{device_key}",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
read_mode=READ_MODE_BOOL,
|
read_mode=READ_MODE_BOOL,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
device_class=BinarySensorDeviceClass.PROBLEM,
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
||||||
translation_key="hub_short_id",
|
translation_key="hub_short_id",
|
||||||
translation_placeholders={"id": str(id)},
|
translation_placeholders={"id": str(device_key)},
|
||||||
)
|
)
|
||||||
for id in DEVICE_KEYS_0_3
|
for device_key in DEVICE_KEYS_0_3
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -233,14 +233,14 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
||||||
"42": (SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION,),
|
"42": (SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION,),
|
||||||
"1D": tuple(
|
"1D": tuple(
|
||||||
OneWireSensorEntityDescription(
|
OneWireSensorEntityDescription(
|
||||||
key=f"counter.{id}",
|
key=f"counter.{device_key}",
|
||||||
native_unit_of_measurement="count",
|
native_unit_of_measurement="count",
|
||||||
read_mode=READ_MODE_INT,
|
read_mode=READ_MODE_INT,
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
translation_key="counter_id",
|
translation_key="counter_id",
|
||||||
translation_placeholders={"id": str(id)},
|
translation_placeholders={"id": str(device_key)},
|
||||||
)
|
)
|
||||||
for id in DEVICE_KEYS_A_B
|
for device_key in DEVICE_KEYS_A_B
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,15 +273,15 @@ HOBBYBOARD_EF: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
||||||
),
|
),
|
||||||
"HB_MOISTURE_METER": tuple(
|
"HB_MOISTURE_METER": tuple(
|
||||||
OneWireSensorEntityDescription(
|
OneWireSensorEntityDescription(
|
||||||
key=f"moisture/sensor.{id}",
|
key=f"moisture/sensor.{device_key}",
|
||||||
device_class=SensorDeviceClass.PRESSURE,
|
device_class=SensorDeviceClass.PRESSURE,
|
||||||
native_unit_of_measurement=UnitOfPressure.CBAR,
|
native_unit_of_measurement=UnitOfPressure.CBAR,
|
||||||
read_mode=READ_MODE_FLOAT,
|
read_mode=READ_MODE_FLOAT,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
translation_key="moisture_id",
|
translation_key="moisture_id",
|
||||||
translation_placeholders={"id": str(id)},
|
translation_placeholders={"id": str(device_key)},
|
||||||
)
|
)
|
||||||
for id in DEVICE_KEYS_0_3
|
for device_key in DEVICE_KEYS_0_3
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,23 +40,23 @@ DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = {
|
||||||
"12": tuple(
|
"12": tuple(
|
||||||
[
|
[
|
||||||
OneWireSwitchEntityDescription(
|
OneWireSwitchEntityDescription(
|
||||||
key=f"PIO.{id}",
|
key=f"PIO.{device_key}",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
read_mode=READ_MODE_BOOL,
|
read_mode=READ_MODE_BOOL,
|
||||||
translation_key="pio_id",
|
translation_key="pio_id",
|
||||||
translation_placeholders={"id": str(id)},
|
translation_placeholders={"id": str(device_key)},
|
||||||
)
|
)
|
||||||
for id in DEVICE_KEYS_A_B
|
for device_key in DEVICE_KEYS_A_B
|
||||||
]
|
]
|
||||||
+ [
|
+ [
|
||||||
OneWireSwitchEntityDescription(
|
OneWireSwitchEntityDescription(
|
||||||
key=f"latch.{id}",
|
key=f"latch.{device_key}",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
read_mode=READ_MODE_BOOL,
|
read_mode=READ_MODE_BOOL,
|
||||||
translation_key="latch_id",
|
translation_key="latch_id",
|
||||||
translation_placeholders={"id": str(id)},
|
translation_placeholders={"id": str(device_key)},
|
||||||
)
|
)
|
||||||
for id in DEVICE_KEYS_A_B
|
for device_key in DEVICE_KEYS_A_B
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
"26": (
|
"26": (
|
||||||
|
@ -71,34 +71,34 @@ DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = {
|
||||||
"29": tuple(
|
"29": tuple(
|
||||||
[
|
[
|
||||||
OneWireSwitchEntityDescription(
|
OneWireSwitchEntityDescription(
|
||||||
key=f"PIO.{id}",
|
key=f"PIO.{device_key}",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
read_mode=READ_MODE_BOOL,
|
read_mode=READ_MODE_BOOL,
|
||||||
translation_key="pio_id",
|
translation_key="pio_id",
|
||||||
translation_placeholders={"id": str(id)},
|
translation_placeholders={"id": str(device_key)},
|
||||||
)
|
)
|
||||||
for id in DEVICE_KEYS_0_7
|
for device_key in DEVICE_KEYS_0_7
|
||||||
]
|
]
|
||||||
+ [
|
+ [
|
||||||
OneWireSwitchEntityDescription(
|
OneWireSwitchEntityDescription(
|
||||||
key=f"latch.{id}",
|
key=f"latch.{device_key}",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
read_mode=READ_MODE_BOOL,
|
read_mode=READ_MODE_BOOL,
|
||||||
translation_key="latch_id",
|
translation_key="latch_id",
|
||||||
translation_placeholders={"id": str(id)},
|
translation_placeholders={"id": str(device_key)},
|
||||||
)
|
)
|
||||||
for id in DEVICE_KEYS_0_7
|
for device_key in DEVICE_KEYS_0_7
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
"3A": tuple(
|
"3A": tuple(
|
||||||
OneWireSwitchEntityDescription(
|
OneWireSwitchEntityDescription(
|
||||||
key=f"PIO.{id}",
|
key=f"PIO.{device_key}",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
read_mode=READ_MODE_BOOL,
|
read_mode=READ_MODE_BOOL,
|
||||||
translation_key="pio_id",
|
translation_key="pio_id",
|
||||||
translation_placeholders={"id": str(id)},
|
translation_placeholders={"id": str(device_key)},
|
||||||
)
|
)
|
||||||
for id in DEVICE_KEYS_A_B
|
for device_key in DEVICE_KEYS_A_B
|
||||||
),
|
),
|
||||||
"EF": (), # "HobbyBoard": special
|
"EF": (), # "HobbyBoard": special
|
||||||
}
|
}
|
||||||
|
@ -108,37 +108,37 @@ DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = {
|
||||||
HOBBYBOARD_EF: dict[str, tuple[OneWireEntityDescription, ...]] = {
|
HOBBYBOARD_EF: dict[str, tuple[OneWireEntityDescription, ...]] = {
|
||||||
"HB_HUB": tuple(
|
"HB_HUB": tuple(
|
||||||
OneWireSwitchEntityDescription(
|
OneWireSwitchEntityDescription(
|
||||||
key=f"hub/branch.{id}",
|
key=f"hub/branch.{device_key}",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
read_mode=READ_MODE_BOOL,
|
read_mode=READ_MODE_BOOL,
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
translation_key="hub_branch_id",
|
translation_key="hub_branch_id",
|
||||||
translation_placeholders={"id": str(id)},
|
translation_placeholders={"id": str(device_key)},
|
||||||
)
|
)
|
||||||
for id in DEVICE_KEYS_0_3
|
for device_key in DEVICE_KEYS_0_3
|
||||||
),
|
),
|
||||||
"HB_MOISTURE_METER": tuple(
|
"HB_MOISTURE_METER": tuple(
|
||||||
[
|
[
|
||||||
OneWireSwitchEntityDescription(
|
OneWireSwitchEntityDescription(
|
||||||
key=f"moisture/is_leaf.{id}",
|
key=f"moisture/is_leaf.{device_key}",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
read_mode=READ_MODE_BOOL,
|
read_mode=READ_MODE_BOOL,
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
translation_key="leaf_sensor_id",
|
translation_key="leaf_sensor_id",
|
||||||
translation_placeholders={"id": str(id)},
|
translation_placeholders={"id": str(device_key)},
|
||||||
)
|
)
|
||||||
for id in DEVICE_KEYS_0_3
|
for device_key in DEVICE_KEYS_0_3
|
||||||
]
|
]
|
||||||
+ [
|
+ [
|
||||||
OneWireSwitchEntityDescription(
|
OneWireSwitchEntityDescription(
|
||||||
key=f"moisture/is_moisture.{id}",
|
key=f"moisture/is_moisture.{device_key}",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
read_mode=READ_MODE_BOOL,
|
read_mode=READ_MODE_BOOL,
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
translation_key="moisture_sensor_id",
|
translation_key="moisture_sensor_id",
|
||||||
translation_placeholders={"id": str(id)},
|
translation_placeholders={"id": str(device_key)},
|
||||||
)
|
)
|
||||||
for id in DEVICE_KEYS_0_3
|
for device_key in DEVICE_KEYS_0_3
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,8 +56,8 @@ async def async_setup_entry(
|
||||||
config_entry.entry_id
|
config_entry.entry_id
|
||||||
][EVENTS_COORDINATOR]
|
][EVENTS_COORDINATOR]
|
||||||
sensors = [
|
sensors = [
|
||||||
RiscoSensor(coordinator, id, [], name, config_entry.entry_id)
|
RiscoSensor(coordinator, category_id, [], name, config_entry.entry_id)
|
||||||
for id, name in CATEGORIES.items()
|
for category_id, name in CATEGORIES.items()
|
||||||
]
|
]
|
||||||
sensors.append(
|
sensors.append(
|
||||||
RiscoSensor(
|
RiscoSensor(
|
||||||
|
|
|
@ -178,4 +178,8 @@ class RoborockVacuum(RoborockCoordinatedEntity, StateVacuumEntity):
|
||||||
|
|
||||||
async def get_maps(self) -> ServiceResponse:
|
async def get_maps(self) -> ServiceResponse:
|
||||||
"""Get map information such as map id and room ids."""
|
"""Get map information such as map id and room ids."""
|
||||||
return {"maps": [asdict(map) for map in self.coordinator.maps.values()]}
|
return {
|
||||||
|
"maps": [
|
||||||
|
asdict(vacuum_map) for vacuum_map in self.coordinator.maps.values()
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
|
@ -161,6 +161,8 @@ async def async_remove_config_entry_device(
|
||||||
return not device_entry.identifiers.intersection(
|
return not device_entry.identifiers.intersection(
|
||||||
(
|
(
|
||||||
(DOMAIN, serial), # Base device
|
(DOMAIN, serial), # Base device
|
||||||
*((DOMAIN, f"{serial}_{id}") for id in device_ids), # Storage and cameras
|
*(
|
||||||
|
(DOMAIN, f"{serial}_{device_id}") for device_id in device_ids
|
||||||
|
), # Storage and cameras
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -63,7 +63,8 @@ class ZwaveSirenEntity(ZWaveBaseEntity, SirenEntity):
|
||||||
super().__init__(config_entry, driver, info)
|
super().__init__(config_entry, driver, info)
|
||||||
# Entity class attributes
|
# Entity class attributes
|
||||||
self._attr_available_tones = {
|
self._attr_available_tones = {
|
||||||
int(id): val for id, val in self.info.primary_value.metadata.states.items()
|
int(state_id): val
|
||||||
|
for state_id, val in self.info.primary_value.metadata.states.items()
|
||||||
}
|
}
|
||||||
self._attr_supported_features = (
|
self._attr_supported_features = (
|
||||||
SirenEntityFeature.TURN_ON
|
SirenEntityFeature.TURN_ON
|
||||||
|
|
|
@ -1347,8 +1347,8 @@ def device_id(hass: HomeAssistant, entity_id_or_device_name: str) -> str | None:
|
||||||
dev_reg = device_registry.async_get(hass)
|
dev_reg = device_registry.async_get(hass)
|
||||||
return next(
|
return next(
|
||||||
(
|
(
|
||||||
id
|
device_id
|
||||||
for id, device in dev_reg.devices.items()
|
for device_id, device in dev_reg.devices.items()
|
||||||
if (name := device.name_by_user or device.name)
|
if (name := device.name_by_user or device.name)
|
||||||
and (str(entity_id_or_device_name) == name)
|
and (str(entity_id_or_device_name) == name)
|
||||||
),
|
),
|
||||||
|
|
|
@ -251,7 +251,7 @@ disable = [
|
||||||
"nested-min-max", # PLW3301
|
"nested-min-max", # PLW3301
|
||||||
"pointless-statement", # B018
|
"pointless-statement", # B018
|
||||||
"raise-missing-from", # B904
|
"raise-missing-from", # B904
|
||||||
# "redefined-builtin", # A001, ruff is way more stricter, needs work
|
"redefined-builtin", # A001
|
||||||
"try-except-raise", # TRY302
|
"try-except-raise", # TRY302
|
||||||
"unused-argument", # ARG001, we don't use it
|
"unused-argument", # ARG001, we don't use it
|
||||||
"unused-format-string-argument", #F507
|
"unused-format-string-argument", #F507
|
||||||
|
@ -663,6 +663,7 @@ required-version = ">=0.4.1"
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
select = [
|
select = [
|
||||||
|
"A001", # Variable {name} is shadowing a Python builtin
|
||||||
"B002", # Python does not support the unary prefix increment
|
"B002", # Python does not support the unary prefix increment
|
||||||
"B005", # Using .strip() with multi-character strings is misleading
|
"B005", # Using .strip() with multi-character strings is misleading
|
||||||
"B007", # Loop control variable {name} not used within loop body
|
"B007", # Loop control variable {name} not used within loop body
|
||||||
|
|
|
@ -158,14 +158,14 @@ async def assert_power_controller_works(
|
||||||
_, response = await assert_request_calls_service(
|
_, response = await assert_request_calls_service(
|
||||||
"Alexa.PowerController", "TurnOn", endpoint, on_service, hass
|
"Alexa.PowerController", "TurnOn", endpoint, on_service, hass
|
||||||
)
|
)
|
||||||
for property in response["context"]["properties"]:
|
for context_property in response["context"]["properties"]:
|
||||||
assert property["timeOfSample"] == timestamp
|
assert context_property["timeOfSample"] == timestamp
|
||||||
|
|
||||||
_, response = await assert_request_calls_service(
|
_, response = await assert_request_calls_service(
|
||||||
"Alexa.PowerController", "TurnOff", endpoint, off_service, hass
|
"Alexa.PowerController", "TurnOff", endpoint, off_service, hass
|
||||||
)
|
)
|
||||||
for property in response["context"]["properties"]:
|
for context_property in response["context"]["properties"]:
|
||||||
assert property["timeOfSample"] == timestamp
|
assert context_property["timeOfSample"] == timestamp
|
||||||
|
|
||||||
|
|
||||||
async def assert_scene_controller_works(
|
async def assert_scene_controller_works(
|
||||||
|
|
|
@ -328,23 +328,23 @@ async def test_websocket_get_action_capabilities(
|
||||||
assert msg["success"]
|
assert msg["success"]
|
||||||
actions = msg["result"]
|
actions = msg["result"]
|
||||||
|
|
||||||
id = 2
|
msg_id = 2
|
||||||
assert len(actions) == 3
|
assert len(actions) == 3
|
||||||
for action in actions:
|
for action in actions:
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
{
|
{
|
||||||
"id": id,
|
"id": msg_id,
|
||||||
"type": "device_automation/action/capabilities",
|
"type": "device_automation/action/capabilities",
|
||||||
"action": action,
|
"action": action,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
msg = await client.receive_json()
|
msg = await client.receive_json()
|
||||||
assert msg["id"] == id
|
assert msg["id"] == msg_id
|
||||||
assert msg["type"] == TYPE_RESULT
|
assert msg["type"] == TYPE_RESULT
|
||||||
assert msg["success"]
|
assert msg["success"]
|
||||||
capabilities = msg["result"]
|
capabilities = msg["result"]
|
||||||
assert capabilities == expected_capabilities[action["type"]]
|
assert capabilities == expected_capabilities[action["type"]]
|
||||||
id = id + 1
|
msg_id = msg_id + 1
|
||||||
|
|
||||||
|
|
||||||
async def test_websocket_get_action_capabilities_unknown_domain(
|
async def test_websocket_get_action_capabilities_unknown_domain(
|
||||||
|
@ -487,23 +487,23 @@ async def test_websocket_get_condition_capabilities(
|
||||||
assert msg["success"]
|
assert msg["success"]
|
||||||
conditions = msg["result"]
|
conditions = msg["result"]
|
||||||
|
|
||||||
id = 2
|
msg_id = 2
|
||||||
assert len(conditions) == 2
|
assert len(conditions) == 2
|
||||||
for condition in conditions:
|
for condition in conditions:
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
{
|
{
|
||||||
"id": id,
|
"id": msg_id,
|
||||||
"type": "device_automation/condition/capabilities",
|
"type": "device_automation/condition/capabilities",
|
||||||
"condition": condition,
|
"condition": condition,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
msg = await client.receive_json()
|
msg = await client.receive_json()
|
||||||
assert msg["id"] == id
|
assert msg["id"] == msg_id
|
||||||
assert msg["type"] == TYPE_RESULT
|
assert msg["type"] == TYPE_RESULT
|
||||||
assert msg["success"]
|
assert msg["success"]
|
||||||
capabilities = msg["result"]
|
capabilities = msg["result"]
|
||||||
assert capabilities == expected_capabilities
|
assert capabilities == expected_capabilities
|
||||||
id = id + 1
|
msg_id = msg_id + 1
|
||||||
|
|
||||||
|
|
||||||
async def test_websocket_get_condition_capabilities_unknown_domain(
|
async def test_websocket_get_condition_capabilities_unknown_domain(
|
||||||
|
@ -775,23 +775,23 @@ async def test_websocket_get_trigger_capabilities(
|
||||||
assert msg["success"]
|
assert msg["success"]
|
||||||
triggers = msg["result"]
|
triggers = msg["result"]
|
||||||
|
|
||||||
id = 2
|
msg_id = 2
|
||||||
assert len(triggers) == 3 # toggled, turned_on, turned_off
|
assert len(triggers) == 3 # toggled, turned_on, turned_off
|
||||||
for trigger in triggers:
|
for trigger in triggers:
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
{
|
{
|
||||||
"id": id,
|
"id": msg_id,
|
||||||
"type": "device_automation/trigger/capabilities",
|
"type": "device_automation/trigger/capabilities",
|
||||||
"trigger": trigger,
|
"trigger": trigger,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
msg = await client.receive_json()
|
msg = await client.receive_json()
|
||||||
assert msg["id"] == id
|
assert msg["id"] == msg_id
|
||||||
assert msg["type"] == TYPE_RESULT
|
assert msg["type"] == TYPE_RESULT
|
||||||
assert msg["success"]
|
assert msg["success"]
|
||||||
capabilities = msg["result"]
|
capabilities = msg["result"]
|
||||||
assert capabilities == expected_capabilities
|
assert capabilities == expected_capabilities
|
||||||
id = id + 1
|
msg_id = msg_id + 1
|
||||||
|
|
||||||
|
|
||||||
async def test_websocket_get_trigger_capabilities_unknown_domain(
|
async def test_websocket_get_trigger_capabilities_unknown_domain(
|
||||||
|
|
|
@ -66,7 +66,7 @@ async def test_siren_switching(
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"devolo_home_control_api.properties.multi_level_switch_property.MultiLevelSwitchProperty.set"
|
"devolo_home_control_api.properties.multi_level_switch_property.MultiLevelSwitchProperty.set"
|
||||||
) as set:
|
) as property_set:
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"siren",
|
"siren",
|
||||||
"turn_on",
|
"turn_on",
|
||||||
|
@ -78,11 +78,11 @@ async def test_siren_switching(
|
||||||
"Test", ("devolo.SirenMultiLevelSwitch:Test", 1)
|
"Test", ("devolo.SirenMultiLevelSwitch:Test", 1)
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
set.assert_called_once_with(1)
|
property_set.assert_called_once_with(1)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"devolo_home_control_api.properties.multi_level_switch_property.MultiLevelSwitchProperty.set"
|
"devolo_home_control_api.properties.multi_level_switch_property.MultiLevelSwitchProperty.set"
|
||||||
) as set:
|
) as property_set:
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"siren",
|
"siren",
|
||||||
"turn_off",
|
"turn_off",
|
||||||
|
@ -95,7 +95,7 @@ async def test_siren_switching(
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert hass.states.get(f"{DOMAIN}.test").state == STATE_OFF
|
assert hass.states.get(f"{DOMAIN}.test").state == STATE_OFF
|
||||||
set.assert_called_once_with(0)
|
property_set.assert_called_once_with(0)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_zeroconf")
|
@pytest.mark.usefixtures("mock_zeroconf")
|
||||||
|
@ -119,7 +119,7 @@ async def test_siren_change_default_tone(
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"devolo_home_control_api.properties.multi_level_switch_property.MultiLevelSwitchProperty.set"
|
"devolo_home_control_api.properties.multi_level_switch_property.MultiLevelSwitchProperty.set"
|
||||||
) as set:
|
) as property_set:
|
||||||
test_gateway.publisher.dispatch("Test", ("mss:Test", 2))
|
test_gateway.publisher.dispatch("Test", ("mss:Test", 2))
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"siren",
|
"siren",
|
||||||
|
@ -127,7 +127,7 @@ async def test_siren_change_default_tone(
|
||||||
{"entity_id": f"{DOMAIN}.test"},
|
{"entity_id": f"{DOMAIN}.test"},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
set.assert_called_once_with(2)
|
property_set.assert_called_once_with(2)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_zeroconf")
|
@pytest.mark.usefixtures("mock_zeroconf")
|
||||||
|
|
|
@ -36,7 +36,10 @@ def create_mock_api_discovery(aioclient_mock, bridges):
|
||||||
"""Patch aiohttp responses with fake data for bridge discovery."""
|
"""Patch aiohttp responses with fake data for bridge discovery."""
|
||||||
aioclient_mock.get(
|
aioclient_mock.get(
|
||||||
URL_NUPNP,
|
URL_NUPNP,
|
||||||
json=[{"internalipaddress": host, "id": id} for (host, id) in bridges],
|
json=[
|
||||||
|
{"internalipaddress": host, "id": bridge_id}
|
||||||
|
for (host, bridge_id) in bridges
|
||||||
|
],
|
||||||
)
|
)
|
||||||
for host, bridge_id in bridges:
|
for host, bridge_id in bridges:
|
||||||
aioclient_mock.get(
|
aioclient_mock.get(
|
||||||
|
|
|
@ -3033,14 +3033,16 @@ async def test_debug_info_multiple_devices(
|
||||||
for dev in devices:
|
for dev in devices:
|
||||||
data = json.dumps(dev["config"])
|
data = json.dumps(dev["config"])
|
||||||
domain = dev["domain"]
|
domain = dev["domain"]
|
||||||
id = dev["config"]["device"]["identifiers"][0]
|
device_id = dev["config"]["device"]["identifiers"][0]
|
||||||
async_fire_mqtt_message(hass, f"homeassistant/{domain}/{id}/config", data)
|
async_fire_mqtt_message(
|
||||||
|
hass, f"homeassistant/{domain}/{device_id}/config", data
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
for dev in devices:
|
for dev in devices:
|
||||||
domain = dev["domain"]
|
domain = dev["domain"]
|
||||||
id = dev["config"]["device"]["identifiers"][0]
|
device_id = dev["config"]["device"]["identifiers"][0]
|
||||||
device = device_registry.async_get_device(identifiers={("mqtt", id)})
|
device = device_registry.async_get_device(identifiers={("mqtt", device_id)})
|
||||||
assert device is not None
|
assert device is not None
|
||||||
|
|
||||||
debug_info_data = debug_info.info_for_device(hass, device.id)
|
debug_info_data = debug_info.info_for_device(hass, device.id)
|
||||||
|
@ -3058,7 +3060,7 @@ async def test_debug_info_multiple_devices(
|
||||||
assert len(debug_info_data["triggers"]) == 1
|
assert len(debug_info_data["triggers"]) == 1
|
||||||
discovery_data = debug_info_data["triggers"][0]["discovery_data"]
|
discovery_data = debug_info_data["triggers"][0]["discovery_data"]
|
||||||
|
|
||||||
assert discovery_data["topic"] == f"homeassistant/{domain}/{id}/config"
|
assert discovery_data["topic"] == f"homeassistant/{domain}/{device_id}/config"
|
||||||
assert discovery_data["payload"] == dev["config"]
|
assert discovery_data["payload"] == dev["config"]
|
||||||
|
|
||||||
|
|
||||||
|
@ -3116,8 +3118,10 @@ async def test_debug_info_multiple_entities_triggers(
|
||||||
data = json.dumps(c["config"])
|
data = json.dumps(c["config"])
|
||||||
domain = c["domain"]
|
domain = c["domain"]
|
||||||
# Use topic as discovery_id
|
# Use topic as discovery_id
|
||||||
id = c["config"].get("topic", c["config"].get("state_topic"))
|
discovery_id = c["config"].get("topic", c["config"].get("state_topic"))
|
||||||
async_fire_mqtt_message(hass, f"homeassistant/{domain}/{id}/config", data)
|
async_fire_mqtt_message(
|
||||||
|
hass, f"homeassistant/{domain}/{discovery_id}/config", data
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
device_id = config[0]["config"]["device"]["identifiers"][0]
|
device_id = config[0]["config"]["device"]["identifiers"][0]
|
||||||
|
@ -3131,7 +3135,7 @@ async def test_debug_info_multiple_entities_triggers(
|
||||||
# Test we get debug info for each entity and trigger
|
# Test we get debug info for each entity and trigger
|
||||||
domain = c["domain"]
|
domain = c["domain"]
|
||||||
# Use topic as discovery_id
|
# Use topic as discovery_id
|
||||||
id = c["config"].get("topic", c["config"].get("state_topic"))
|
discovery_id = c["config"].get("topic", c["config"].get("state_topic"))
|
||||||
|
|
||||||
if c["domain"] != "device_automation":
|
if c["domain"] != "device_automation":
|
||||||
discovery_data = [e["discovery_data"] for e in debug_info_data["entities"]]
|
discovery_data = [e["discovery_data"] for e in debug_info_data["entities"]]
|
||||||
|
@ -3143,7 +3147,7 @@ async def test_debug_info_multiple_entities_triggers(
|
||||||
discovery_data = [e["discovery_data"] for e in debug_info_data["triggers"]]
|
discovery_data = [e["discovery_data"] for e in debug_info_data["triggers"]]
|
||||||
|
|
||||||
assert {
|
assert {
|
||||||
"topic": f"homeassistant/{domain}/{id}/config",
|
"topic": f"homeassistant/{domain}/{discovery_id}/config",
|
||||||
"payload": c["config"],
|
"payload": c["config"],
|
||||||
} in discovery_data
|
} in discovery_data
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,9 @@ async def async_wait_recording_done(hass: HomeAssistant) -> None:
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
async def async_wait_purge_done(hass: HomeAssistant, max: int | None = None) -> None:
|
async def async_wait_purge_done(
|
||||||
|
hass: HomeAssistant, max_number: int | None = None
|
||||||
|
) -> None:
|
||||||
"""Wait for max number of purge events.
|
"""Wait for max number of purge events.
|
||||||
|
|
||||||
Because a purge may insert another PurgeTask into
|
Because a purge may insert another PurgeTask into
|
||||||
|
@ -117,9 +119,9 @@ async def async_wait_purge_done(hass: HomeAssistant, max: int | None = None) ->
|
||||||
a maximum number of WaitTasks that we will put into the
|
a maximum number of WaitTasks that we will put into the
|
||||||
queue.
|
queue.
|
||||||
"""
|
"""
|
||||||
if not max:
|
if not max_number:
|
||||||
max = DEFAULT_PURGE_TASKS
|
max_number = DEFAULT_PURGE_TASKS
|
||||||
for _ in range(max + 1):
|
for _ in range(max_number + 1):
|
||||||
await async_wait_recording_done(hass)
|
await async_wait_recording_done(hass)
|
||||||
|
|
||||||
|
|
||||||
|
@ -325,10 +327,10 @@ def convert_pending_states_to_meta(instance: Recorder, session: Session) -> None
|
||||||
entity_ids: set[str] = set()
|
entity_ids: set[str] = set()
|
||||||
states: set[States] = set()
|
states: set[States] = set()
|
||||||
states_meta_objects: dict[str, StatesMeta] = {}
|
states_meta_objects: dict[str, StatesMeta] = {}
|
||||||
for object in session:
|
for session_object in session:
|
||||||
if isinstance(object, States):
|
if isinstance(session_object, States):
|
||||||
entity_ids.add(object.entity_id)
|
entity_ids.add(session_object.entity_id)
|
||||||
states.add(object)
|
states.add(session_object)
|
||||||
|
|
||||||
entity_id_to_metadata_ids = instance.states_meta_manager.get_many(
|
entity_id_to_metadata_ids = instance.states_meta_manager.get_many(
|
||||||
entity_ids, session, True
|
entity_ids, session, True
|
||||||
|
@ -352,10 +354,10 @@ def convert_pending_events_to_event_types(instance: Recorder, session: Session)
|
||||||
event_types: set[str] = set()
|
event_types: set[str] = set()
|
||||||
events: set[Events] = set()
|
events: set[Events] = set()
|
||||||
event_types_objects: dict[str, EventTypes] = {}
|
event_types_objects: dict[str, EventTypes] = {}
|
||||||
for object in session:
|
for session_object in session:
|
||||||
if isinstance(object, Events):
|
if isinstance(session_object, Events):
|
||||||
event_types.add(object.event_type)
|
event_types.add(session_object.event_type)
|
||||||
events.add(object)
|
events.add(session_object)
|
||||||
|
|
||||||
event_type_to_event_type_ids = instance.event_type_manager.get_many(
|
event_type_to_event_type_ids = instance.event_type_manager.get_many(
|
||||||
event_types, session, True
|
event_types, session, True
|
||||||
|
|
|
@ -1040,14 +1040,14 @@ async def test_resolve_period(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
def test_chunked_or_all():
|
def test_chunked_or_all():
|
||||||
"""Test chunked_or_all can iterate chunk sizes larger than the passed in collection."""
|
"""Test chunked_or_all can iterate chunk sizes larger than the passed in collection."""
|
||||||
all = []
|
all_items = []
|
||||||
incoming = (1, 2, 3, 4)
|
incoming = (1, 2, 3, 4)
|
||||||
for chunk in chunked_or_all(incoming, 2):
|
for chunk in chunked_or_all(incoming, 2):
|
||||||
assert len(chunk) == 2
|
assert len(chunk) == 2
|
||||||
all.extend(chunk)
|
all_items.extend(chunk)
|
||||||
assert all == [1, 2, 3, 4]
|
assert all_items == [1, 2, 3, 4]
|
||||||
|
|
||||||
all = []
|
all_items = []
|
||||||
incoming = (1, 2, 3, 4)
|
incoming = (1, 2, 3, 4)
|
||||||
for chunk in chunked_or_all(incoming, 5):
|
for chunk in chunked_or_all(incoming, 5):
|
||||||
assert len(chunk) == 4
|
assert len(chunk) == 4
|
||||||
|
@ -1055,5 +1055,5 @@ def test_chunked_or_all():
|
||||||
# collection since we want to avoid copying the collection
|
# collection since we want to avoid copying the collection
|
||||||
# if we don't need to
|
# if we don't need to
|
||||||
assert chunk is incoming
|
assert chunk is incoming
|
||||||
all.extend(chunk)
|
all_items.extend(chunk)
|
||||||
assert all == [1, 2, 3, 4]
|
assert all_items == [1, 2, 3, 4]
|
||||||
|
|
|
@ -641,12 +641,12 @@ async def test_statistic_during_period_hole(
|
||||||
recorder_mock: Recorder, hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
recorder_mock: Recorder, hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test statistic_during_period when there are holes in the data."""
|
"""Test statistic_during_period when there are holes in the data."""
|
||||||
id = 1
|
stat_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal stat_id
|
||||||
id += 1
|
stat_id += 1
|
||||||
return id
|
return stat_id
|
||||||
|
|
||||||
now = dt_util.utcnow()
|
now = dt_util.utcnow()
|
||||||
|
|
||||||
|
|
|
@ -122,11 +122,11 @@ async def test_local_setup(
|
||||||
|
|
||||||
|
|
||||||
async def _check_local_state(
|
async def _check_local_state(
|
||||||
hass, zones, property, value, entity_id, zone_id, callback
|
hass, zones, entity_property, value, entity_id, zone_id, callback
|
||||||
):
|
):
|
||||||
with patch.object(
|
with patch.object(
|
||||||
zones[zone_id],
|
zones[zone_id],
|
||||||
property,
|
entity_property,
|
||||||
new_callable=PropertyMock(return_value=value),
|
new_callable=PropertyMock(return_value=value),
|
||||||
):
|
):
|
||||||
await callback(zone_id, zones[zone_id])
|
await callback(zone_id, zones[zone_id])
|
||||||
|
@ -210,19 +210,19 @@ async def test_armed_local_states(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def _check_system_state(hass, system, property, value, callback):
|
async def _check_system_state(hass, system, entity_property, value, callback):
|
||||||
with patch.object(
|
with patch.object(
|
||||||
system,
|
system,
|
||||||
property,
|
entity_property,
|
||||||
new_callable=PropertyMock(return_value=value),
|
new_callable=PropertyMock(return_value=value),
|
||||||
):
|
):
|
||||||
await callback(system)
|
await callback(system)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
expected_value = STATE_ON if value else STATE_OFF
|
expected_value = STATE_ON if value else STATE_OFF
|
||||||
if property == "ac_trouble":
|
if entity_property == "ac_trouble":
|
||||||
property = "a_c_trouble"
|
entity_property = "a_c_trouble"
|
||||||
entity_id = f"binary_sensor.test_site_name_{property}"
|
entity_id = f"binary_sensor.test_site_name_{entity_property}"
|
||||||
assert hass.states.get(entity_id).state == expected_value
|
assert hass.states.get(entity_id).state == expected_value
|
||||||
|
|
||||||
|
|
||||||
|
@ -275,6 +275,10 @@ async def test_system_states(
|
||||||
"clock_trouble",
|
"clock_trouble",
|
||||||
"box_tamper",
|
"box_tamper",
|
||||||
]
|
]
|
||||||
for property in properties:
|
for entity_property in properties:
|
||||||
await _check_system_state(hass, system_only_local, property, True, callback)
|
await _check_system_state(
|
||||||
await _check_system_state(hass, system_only_local, property, False, callback)
|
hass, system_only_local, entity_property, True, callback
|
||||||
|
)
|
||||||
|
await _check_system_state(
|
||||||
|
hass, system_only_local, entity_property, False, callback
|
||||||
|
)
|
||||||
|
|
|
@ -133,8 +133,8 @@ async def test_error_on_login(
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
registry = er.async_get(hass)
|
||||||
for id in ENTITY_IDS.values():
|
for entity_id in ENTITY_IDS.values():
|
||||||
assert not registry.async_is_registered(id)
|
assert not registry.async_is_registered(entity_id)
|
||||||
|
|
||||||
|
|
||||||
def _check_state(hass, category, entity_id):
|
def _check_state(hass, category, entity_id):
|
||||||
|
@ -184,8 +184,8 @@ async def test_cloud_setup(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test entity setup."""
|
"""Test entity setup."""
|
||||||
registry = er.async_get(hass)
|
registry = er.async_get(hass)
|
||||||
for id in ENTITY_IDS.values():
|
for entity_id in ENTITY_IDS.values():
|
||||||
assert registry.async_is_registered(id)
|
assert registry.async_is_registered(entity_id)
|
||||||
|
|
||||||
save_mock.assert_awaited_once_with({LAST_EVENT_TIMESTAMP_KEY: TEST_EVENTS[0].time})
|
save_mock.assert_awaited_once_with({LAST_EVENT_TIMESTAMP_KEY: TEST_EVENTS[0].time})
|
||||||
for category, entity_id in ENTITY_IDS.items():
|
for category, entity_id in ENTITY_IDS.items():
|
||||||
|
@ -213,5 +213,5 @@ async def test_local_setup(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test entity setup."""
|
"""Test entity setup."""
|
||||||
registry = er.async_get(hass)
|
registry = er.async_get(hass)
|
||||||
for id in ENTITY_IDS.values():
|
for entity_id in ENTITY_IDS.values():
|
||||||
assert not registry.async_is_registered(id)
|
assert not registry.async_is_registered(entity_id)
|
||||||
|
|
|
@ -560,7 +560,7 @@ def test_compile_hourly_statistics_purged_state_changes(
|
||||||
)
|
)
|
||||||
assert_dict_of_states_equal_without_context_and_last_changed(states, hist)
|
assert_dict_of_states_equal_without_context_and_last_changed(states, hist)
|
||||||
|
|
||||||
mean = min = max = float(hist["sensor.test1"][-1].state)
|
mean = min_value = max_value = float(hist["sensor.test1"][-1].state)
|
||||||
|
|
||||||
# Purge all states from the database
|
# Purge all states from the database
|
||||||
with freeze_time(four):
|
with freeze_time(four):
|
||||||
|
@ -594,8 +594,8 @@ def test_compile_hourly_statistics_purged_state_changes(
|
||||||
"start": process_timestamp(zero).timestamp(),
|
"start": process_timestamp(zero).timestamp(),
|
||||||
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
|
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
|
||||||
"mean": pytest.approx(mean),
|
"mean": pytest.approx(mean),
|
||||||
"min": pytest.approx(min),
|
"min": pytest.approx(min_value),
|
||||||
"max": pytest.approx(max),
|
"max": pytest.approx(max_value),
|
||||||
"last_reset": None,
|
"last_reset": None,
|
||||||
"state": None,
|
"state": None,
|
||||||
"sum": None,
|
"sum": None,
|
||||||
|
@ -4113,12 +4113,12 @@ async def test_validate_unit_change_convertible(
|
||||||
|
|
||||||
The test also asserts that the sensor's device class is ignored.
|
The test also asserts that the sensor's device class is ignored.
|
||||||
"""
|
"""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
async def assert_validation_result(client, expected_result):
|
async def assert_validation_result(client, expected_result):
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
@ -4228,12 +4228,12 @@ async def test_validate_statistics_unit_ignore_device_class(
|
||||||
|
|
||||||
The test asserts that the sensor's device class is ignored.
|
The test asserts that the sensor's device class is ignored.
|
||||||
"""
|
"""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
async def assert_validation_result(client, expected_result):
|
async def assert_validation_result(client, expected_result):
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
@ -4321,14 +4321,14 @@ async def test_validate_statistics_unit_change_no_device_class(
|
||||||
conversion, and the unit is then changed to a unit which can and cannot be
|
conversion, and the unit is then changed to a unit which can and cannot be
|
||||||
converted to the original unit.
|
converted to the original unit.
|
||||||
"""
|
"""
|
||||||
id = 1
|
msg_id = 1
|
||||||
attributes = dict(attributes)
|
attributes = dict(attributes)
|
||||||
attributes.pop("device_class")
|
attributes.pop("device_class")
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
async def assert_validation_result(client, expected_result):
|
async def assert_validation_result(client, expected_result):
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
@ -4436,12 +4436,12 @@ async def test_validate_statistics_unsupported_state_class(
|
||||||
unit,
|
unit,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test validate_statistics."""
|
"""Test validate_statistics."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
async def assert_validation_result(client, expected_result):
|
async def assert_validation_result(client, expected_result):
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
@ -4505,12 +4505,12 @@ async def test_validate_statistics_sensor_no_longer_recorded(
|
||||||
unit,
|
unit,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test validate_statistics."""
|
"""Test validate_statistics."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
async def assert_validation_result(client, expected_result):
|
async def assert_validation_result(client, expected_result):
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
@ -4573,12 +4573,12 @@ async def test_validate_statistics_sensor_not_recorded(
|
||||||
unit,
|
unit,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test validate_statistics."""
|
"""Test validate_statistics."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
async def assert_validation_result(client, expected_result):
|
async def assert_validation_result(client, expected_result):
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
@ -4638,12 +4638,12 @@ async def test_validate_statistics_sensor_removed(
|
||||||
unit,
|
unit,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test validate_statistics."""
|
"""Test validate_statistics."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
async def assert_validation_result(client, expected_result):
|
async def assert_validation_result(client, expected_result):
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
@ -4702,12 +4702,12 @@ async def test_validate_statistics_unit_change_no_conversion(
|
||||||
unit2,
|
unit2,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test validate_statistics."""
|
"""Test validate_statistics."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
async def assert_validation_result(client, expected_result):
|
async def assert_validation_result(client, expected_result):
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
@ -4837,12 +4837,12 @@ async def test_validate_statistics_unit_change_equivalent_units(
|
||||||
This tests no validation issue is created when a sensor's unit changes to an
|
This tests no validation issue is created when a sensor's unit changes to an
|
||||||
equivalent unit.
|
equivalent unit.
|
||||||
"""
|
"""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
async def assert_validation_result(client, expected_result):
|
async def assert_validation_result(client, expected_result):
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
@ -4923,12 +4923,12 @@ async def test_validate_statistics_unit_change_equivalent_units_2(
|
||||||
equivalent unit which is not known to the unit converters.
|
equivalent unit which is not known to the unit converters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
async def assert_validation_result(client, expected_result):
|
async def assert_validation_result(client, expected_result):
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
@ -5005,12 +5005,12 @@ async def test_validate_statistics_other_domain(
|
||||||
recorder_mock: Recorder, hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
recorder_mock: Recorder, hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test sensor does not raise issues for statistics for other domains."""
|
"""Test sensor does not raise issues for statistics for other domains."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
async def assert_validation_result(client, expected_result):
|
async def assert_validation_result(client, expected_result):
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
|
|
@ -96,11 +96,11 @@ async def test_get_triggers_rpc_device(
|
||||||
CONF_PLATFORM: "device",
|
CONF_PLATFORM: "device",
|
||||||
CONF_DEVICE_ID: device.id,
|
CONF_DEVICE_ID: device.id,
|
||||||
CONF_DOMAIN: DOMAIN,
|
CONF_DOMAIN: DOMAIN,
|
||||||
CONF_TYPE: type,
|
CONF_TYPE: trigger_type,
|
||||||
CONF_SUBTYPE: "button1",
|
CONF_SUBTYPE: "button1",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
}
|
}
|
||||||
for type in [
|
for trigger_type in [
|
||||||
"btn_down",
|
"btn_down",
|
||||||
"btn_up",
|
"btn_up",
|
||||||
"single_push",
|
"single_push",
|
||||||
|
@ -130,11 +130,11 @@ async def test_get_triggers_button(
|
||||||
CONF_PLATFORM: "device",
|
CONF_PLATFORM: "device",
|
||||||
CONF_DEVICE_ID: device.id,
|
CONF_DEVICE_ID: device.id,
|
||||||
CONF_DOMAIN: DOMAIN,
|
CONF_DOMAIN: DOMAIN,
|
||||||
CONF_TYPE: type,
|
CONF_TYPE: trigger_type,
|
||||||
CONF_SUBTYPE: "button",
|
CONF_SUBTYPE: "button",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
}
|
}
|
||||||
for type in ["single", "double", "triple", "long"]
|
for trigger_type in ["single", "double", "triple", "long"]
|
||||||
]
|
]
|
||||||
|
|
||||||
triggers = await async_get_device_automations(
|
triggers = await async_get_device_automations(
|
||||||
|
|
|
@ -342,7 +342,7 @@ def event_request_factory_fixture(event_factory):
|
||||||
if events is None:
|
if events is None:
|
||||||
events = []
|
events = []
|
||||||
if device_ids:
|
if device_ids:
|
||||||
events.extend([event_factory(id) for id in device_ids])
|
events.extend([event_factory(device_id) for device_id in device_ids])
|
||||||
events.append(event_factory(uuid4()))
|
events.append(event_factory(uuid4()))
|
||||||
events.append(event_factory(device_ids[0], event_type="OTHER"))
|
events.append(event_factory(device_ids[0], event_type="OTHER"))
|
||||||
request.events = events
|
request.events = events
|
||||||
|
|
|
@ -133,7 +133,7 @@ async def test_flow_user_multiple_entries_allowed(hass: HomeAssistant) -> None:
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
input = {
|
user_input = {
|
||||||
CONF_URL: "http://1.2.3.5:8181/test",
|
CONF_URL: "http://1.2.3.5:8181/test",
|
||||||
CONF_API_KEY: "efgh",
|
CONF_API_KEY: "efgh",
|
||||||
CONF_VERIFY_SSL: True,
|
CONF_VERIFY_SSL: True,
|
||||||
|
@ -141,13 +141,13 @@ async def test_flow_user_multiple_entries_allowed(hass: HomeAssistant) -> None:
|
||||||
with patch_config_flow_tautulli(AsyncMock()):
|
with patch_config_flow_tautulli(AsyncMock()):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
user_input=input,
|
user_input=user_input,
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result2["title"] == NAME
|
assert result2["title"] == NAME
|
||||||
assert result2["data"] == input
|
assert result2["data"] == user_input
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_reauth(
|
async def test_flow_reauth(
|
||||||
|
|
|
@ -133,12 +133,12 @@ async def test_get_trace(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test tracing a script or automation."""
|
"""Test tracing a script or automation."""
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
sun_config = {
|
sun_config = {
|
||||||
"id": "sun",
|
"id": "sun",
|
||||||
|
@ -429,12 +429,12 @@ async def test_restore_traces(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test restored traces."""
|
"""Test restored traces."""
|
||||||
hass.set_state(CoreState.not_running)
|
hass.set_state(CoreState.not_running)
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
saved_traces = json.loads(load_fixture(f"trace/{domain}_saved_traces.json"))
|
saved_traces = json.loads(load_fixture(f"trace/{domain}_saved_traces.json"))
|
||||||
hass_storage["trace.saved_traces"] = saved_traces
|
hass_storage["trace.saved_traces"] = saved_traces
|
||||||
|
@ -522,7 +522,7 @@ async def test_trace_overflow(
|
||||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain, stored_traces
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain, stored_traces
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the number of stored traces per script or automation is limited."""
|
"""Test the number of stored traces per script or automation is limited."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
trace_uuids = []
|
trace_uuids = []
|
||||||
|
|
||||||
|
@ -532,9 +532,9 @@ async def test_trace_overflow(
|
||||||
return trace_uuids[-1]
|
return trace_uuids[-1]
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
sun_config = {
|
sun_config = {
|
||||||
"id": "sun",
|
"id": "sun",
|
||||||
|
@ -601,7 +601,7 @@ async def test_restore_traces_overflow(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test restored traces are evicted first."""
|
"""Test restored traces are evicted first."""
|
||||||
hass.set_state(CoreState.not_running)
|
hass.set_state(CoreState.not_running)
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
trace_uuids = []
|
trace_uuids = []
|
||||||
|
|
||||||
|
@ -611,9 +611,9 @@ async def test_restore_traces_overflow(
|
||||||
return trace_uuids[-1]
|
return trace_uuids[-1]
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
saved_traces = json.loads(load_fixture(f"trace/{domain}_saved_traces.json"))
|
saved_traces = json.loads(load_fixture(f"trace/{domain}_saved_traces.json"))
|
||||||
hass_storage["trace.saved_traces"] = saved_traces
|
hass_storage["trace.saved_traces"] = saved_traces
|
||||||
|
@ -682,7 +682,7 @@ async def test_restore_traces_late_overflow(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test restored traces are evicted first."""
|
"""Test restored traces are evicted first."""
|
||||||
hass.set_state(CoreState.not_running)
|
hass.set_state(CoreState.not_running)
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
trace_uuids = []
|
trace_uuids = []
|
||||||
|
|
||||||
|
@ -692,9 +692,9 @@ async def test_restore_traces_late_overflow(
|
||||||
return trace_uuids[-1]
|
return trace_uuids[-1]
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
saved_traces = json.loads(load_fixture(f"trace/{domain}_saved_traces.json"))
|
saved_traces = json.loads(load_fixture(f"trace/{domain}_saved_traces.json"))
|
||||||
hass_storage["trace.saved_traces"] = saved_traces
|
hass_storage["trace.saved_traces"] = saved_traces
|
||||||
|
@ -743,12 +743,12 @@ async def test_trace_no_traces(
|
||||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the storing traces for a script or automation can be disabled."""
|
"""Test the storing traces for a script or automation can be disabled."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
sun_config = {
|
sun_config = {
|
||||||
"id": "sun",
|
"id": "sun",
|
||||||
|
@ -810,12 +810,12 @@ async def test_list_traces(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test listing script and automation traces."""
|
"""Test listing script and automation traces."""
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
sun_config = {
|
sun_config = {
|
||||||
"id": "sun",
|
"id": "sun",
|
||||||
|
@ -943,12 +943,12 @@ async def test_nested_traces(
|
||||||
extra_trace_keys,
|
extra_trace_keys,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test nested automation and script traces."""
|
"""Test nested automation and script traces."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
sun_config = {
|
sun_config = {
|
||||||
"id": "sun",
|
"id": "sun",
|
||||||
|
@ -1003,12 +1003,12 @@ async def test_breakpoints(
|
||||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain, prefix
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain, prefix
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test script and automation breakpoints."""
|
"""Test script and automation breakpoints."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
async def assert_last_step(item_id, expected_action, expected_state):
|
async def assert_last_step(item_id, expected_action, expected_state):
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
@ -1173,12 +1173,12 @@ async def test_breakpoints_2(
|
||||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain, prefix
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain, prefix
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test execution resumes and breakpoints are removed after subscription removed."""
|
"""Test execution resumes and breakpoints are removed after subscription removed."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
async def assert_last_step(item_id, expected_action, expected_state):
|
async def assert_last_step(item_id, expected_action, expected_state):
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
@ -1278,12 +1278,12 @@ async def test_breakpoints_3(
|
||||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain, prefix
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, domain, prefix
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test breakpoints can be cleared."""
|
"""Test breakpoints can be cleared."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
async def assert_last_step(item_id, expected_action, expected_state):
|
async def assert_last_step(item_id, expected_action, expected_state):
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
@ -1434,12 +1434,12 @@ async def test_script_mode(
|
||||||
script_execution,
|
script_execution,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test overlapping runs with max_runs > 1."""
|
"""Test overlapping runs with max_runs > 1."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
flag = asyncio.Event()
|
flag = asyncio.Event()
|
||||||
|
|
||||||
|
@ -1502,12 +1502,12 @@ async def test_script_mode_2(
|
||||||
script_execution,
|
script_execution,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test overlapping runs with max_runs > 1."""
|
"""Test overlapping runs with max_runs > 1."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
flag = asyncio.Event()
|
flag = asyncio.Event()
|
||||||
|
|
||||||
|
@ -1577,12 +1577,12 @@ async def test_trace_blueprint_automation(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test trace of blueprint automation."""
|
"""Test trace of blueprint automation."""
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
domain = "automation"
|
domain = "automation"
|
||||||
sun_config = {
|
sun_config = {
|
||||||
|
|
|
@ -17,16 +17,16 @@ async def test_load_unload_entry(hass: HomeAssistant) -> None:
|
||||||
"""Validate that setup entry also configure the client."""
|
"""Validate that setup entry also configure the client."""
|
||||||
client = ClientMock()
|
client = ClientMock()
|
||||||
|
|
||||||
id = str(uuid4())
|
device_id = str(uuid4())
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=TWINKLY_DOMAIN,
|
domain=TWINKLY_DOMAIN,
|
||||||
data={
|
data={
|
||||||
CONF_HOST: TEST_HOST,
|
CONF_HOST: TEST_HOST,
|
||||||
CONF_ID: id,
|
CONF_ID: device_id,
|
||||||
CONF_NAME: TEST_NAME_ORIGINAL,
|
CONF_NAME: TEST_NAME_ORIGINAL,
|
||||||
CONF_MODEL: TEST_MODEL,
|
CONF_MODEL: TEST_MODEL,
|
||||||
},
|
},
|
||||||
entry_id=id,
|
entry_id=device_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
|
@ -37,7 +37,7 @@ class MockInput:
|
||||||
|
|
||||||
def get_mock_inputs(input_list):
|
def get_mock_inputs(input_list):
|
||||||
"""Return list of MockInput."""
|
"""Return list of MockInput."""
|
||||||
return [MockInput(input) for input in input_list]
|
return [MockInput(device_input) for device_input in input_list]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="vizio_get_unique_id", autouse=True)
|
@pytest.fixture(name="vizio_get_unique_id", autouse=True)
|
||||||
|
|
|
@ -128,7 +128,9 @@ async def test_device_diagnostics(
|
||||||
)
|
)
|
||||||
assert diagnostics_data["state"] == {
|
assert diagnostics_data["state"] == {
|
||||||
**multisensor_6.data,
|
**multisensor_6.data,
|
||||||
"values": {id: val.data for id, val in multisensor_6.values.items()},
|
"values": {
|
||||||
|
value_id: val.data for value_id, val in multisensor_6.values.items()
|
||||||
|
},
|
||||||
"endpoints": {
|
"endpoints": {
|
||||||
str(idx): endpoint.data for idx, endpoint in multisensor_6.endpoints.items()
|
str(idx): endpoint.data for idx, endpoint in multisensor_6.endpoints.items()
|
||||||
},
|
},
|
||||||
|
|
|
@ -2178,12 +2178,12 @@ def _find_run_id(traces, trace_type, item_id):
|
||||||
|
|
||||||
async def assert_automation_condition_trace(hass_ws_client, automation_id, expected):
|
async def assert_automation_condition_trace(hass_ws_client, automation_id, expected):
|
||||||
"""Test the result of automation condition."""
|
"""Test the result of automation condition."""
|
||||||
id = 1
|
msg_id = 1
|
||||||
|
|
||||||
def next_id():
|
def next_id():
|
||||||
nonlocal id
|
nonlocal msg_id
|
||||||
id += 1
|
msg_id += 1
|
||||||
return id
|
return msg_id
|
||||||
|
|
||||||
client = await hass_ws_client()
|
client = await hass_ws_client()
|
||||||
|
|
||||||
|
|
|
@ -2330,30 +2330,30 @@ async def test_cached_entity_properties(
|
||||||
|
|
||||||
async def test_cached_entity_property_delete_attr(hass: HomeAssistant) -> None:
|
async def test_cached_entity_property_delete_attr(hass: HomeAssistant) -> None:
|
||||||
"""Test deleting an _attr corresponding to a cached property."""
|
"""Test deleting an _attr corresponding to a cached property."""
|
||||||
property = "has_entity_name"
|
property_name = "has_entity_name"
|
||||||
|
|
||||||
ent = entity.Entity()
|
ent = entity.Entity()
|
||||||
assert not hasattr(ent, f"_attr_{property}")
|
assert not hasattr(ent, f"_attr_{property_name}")
|
||||||
with pytest.raises(AttributeError):
|
with pytest.raises(AttributeError):
|
||||||
delattr(ent, f"_attr_{property}")
|
delattr(ent, f"_attr_{property_name}")
|
||||||
assert getattr(ent, property) is False
|
assert getattr(ent, property_name) is False
|
||||||
|
|
||||||
with pytest.raises(AttributeError):
|
with pytest.raises(AttributeError):
|
||||||
delattr(ent, f"_attr_{property}")
|
delattr(ent, f"_attr_{property_name}")
|
||||||
assert not hasattr(ent, f"_attr_{property}")
|
assert not hasattr(ent, f"_attr_{property_name}")
|
||||||
assert getattr(ent, property) is False
|
assert getattr(ent, property_name) is False
|
||||||
|
|
||||||
setattr(ent, f"_attr_{property}", True)
|
setattr(ent, f"_attr_{property_name}", True)
|
||||||
assert getattr(ent, property) is True
|
assert getattr(ent, property_name) is True
|
||||||
|
|
||||||
delattr(ent, f"_attr_{property}")
|
delattr(ent, f"_attr_{property_name}")
|
||||||
assert not hasattr(ent, f"_attr_{property}")
|
assert not hasattr(ent, f"_attr_{property_name}")
|
||||||
assert getattr(ent, property) is False
|
assert getattr(ent, property_name) is False
|
||||||
|
|
||||||
|
|
||||||
async def test_cached_entity_property_class_attribute(hass: HomeAssistant) -> None:
|
async def test_cached_entity_property_class_attribute(hass: HomeAssistant) -> None:
|
||||||
"""Test entity properties on class level work in derived classes."""
|
"""Test entity properties on class level work in derived classes."""
|
||||||
property = "attribution"
|
property_name = "attribution"
|
||||||
values = ["abcd", "efgh"]
|
values = ["abcd", "efgh"]
|
||||||
|
|
||||||
class EntityWithClassAttribute1(entity.Entity):
|
class EntityWithClassAttribute1(entity.Entity):
|
||||||
|
@ -2408,15 +2408,15 @@ async def test_cached_entity_property_class_attribute(hass: HomeAssistant) -> No
|
||||||
]
|
]
|
||||||
|
|
||||||
for ent in entities:
|
for ent in entities:
|
||||||
assert getattr(ent[0], property) == values[0]
|
assert getattr(ent[0], property_name) == values[0]
|
||||||
assert getattr(ent[1], property) == values[0]
|
assert getattr(ent[1], property_name) == values[0]
|
||||||
|
|
||||||
# Test update
|
# Test update
|
||||||
for ent in entities:
|
for ent in entities:
|
||||||
setattr(ent[0], f"_attr_{property}", values[1])
|
setattr(ent[0], f"_attr_{property_name}", values[1])
|
||||||
for ent in entities:
|
for ent in entities:
|
||||||
assert getattr(ent[0], property) == values[1]
|
assert getattr(ent[0], property_name) == values[1]
|
||||||
assert getattr(ent[1], property) == values[0]
|
assert getattr(ent[1], property_name) == values[0]
|
||||||
|
|
||||||
|
|
||||||
async def test_cached_entity_property_override(hass: HomeAssistant) -> None:
|
async def test_cached_entity_property_override(hass: HomeAssistant) -> None:
|
||||||
|
|
|
@ -1148,11 +1148,11 @@ async def test_eventbus_filtered_listener(hass: HomeAssistant) -> None:
|
||||||
calls.append(event)
|
calls.append(event)
|
||||||
|
|
||||||
@ha.callback
|
@ha.callback
|
||||||
def filter(event_data):
|
def mock_filter(event_data):
|
||||||
"""Mock filter."""
|
"""Mock filter."""
|
||||||
return not event_data["filtered"]
|
return not event_data["filtered"]
|
||||||
|
|
||||||
unsub = hass.bus.async_listen("test", listener, event_filter=filter)
|
unsub = hass.bus.async_listen("test", listener, event_filter=mock_filter)
|
||||||
|
|
||||||
hass.bus.async_fire("test", {"filtered": True})
|
hass.bus.async_fire("test", {"filtered": True})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -3274,11 +3274,11 @@ async def test_eventbus_lazy_object_creation(hass: HomeAssistant) -> None:
|
||||||
calls.append(event)
|
calls.append(event)
|
||||||
|
|
||||||
@ha.callback
|
@ha.callback
|
||||||
def filter(event_data):
|
def mock_filter(event_data):
|
||||||
"""Mock filter."""
|
"""Mock filter."""
|
||||||
return not event_data["filtered"]
|
return not event_data["filtered"]
|
||||||
|
|
||||||
unsub = hass.bus.async_listen("test_1", listener, event_filter=filter)
|
unsub = hass.bus.async_listen("test_1", listener, event_filter=mock_filter)
|
||||||
|
|
||||||
# Test lazy creation of Event objects
|
# Test lazy creation of Event objects
|
||||||
with patch("homeassistant.core.Event") as mock_event:
|
with patch("homeassistant.core.Event") as mock_event:
|
||||||
|
@ -3343,7 +3343,7 @@ async def test_statemachine_report_state(hass: HomeAssistant) -> None:
|
||||||
"""Test report state event."""
|
"""Test report state event."""
|
||||||
|
|
||||||
@ha.callback
|
@ha.callback
|
||||||
def filter(event_data):
|
def mock_filter(event_data):
|
||||||
"""Mock filter."""
|
"""Mock filter."""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -3354,7 +3354,7 @@ async def test_statemachine_report_state(hass: HomeAssistant) -> None:
|
||||||
hass.states.async_set("light.bowl", "on", {})
|
hass.states.async_set("light.bowl", "on", {})
|
||||||
state_changed_events = async_capture_events(hass, EVENT_STATE_CHANGED)
|
state_changed_events = async_capture_events(hass, EVENT_STATE_CHANGED)
|
||||||
state_reported_events = []
|
state_reported_events = []
|
||||||
hass.bus.async_listen(EVENT_STATE_REPORTED, listener, event_filter=filter)
|
hass.bus.async_listen(EVENT_STATE_REPORTED, listener, event_filter=mock_filter)
|
||||||
|
|
||||||
hass.states.async_set("light.bowl", "on")
|
hass.states.async_set("light.bowl", "on")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -3385,7 +3385,7 @@ async def test_report_state_listener_restrictions(hass: HomeAssistant) -> None:
|
||||||
"""Mock listener."""
|
"""Mock listener."""
|
||||||
|
|
||||||
@ha.callback
|
@ha.callback
|
||||||
def filter(event_data):
|
def mock_filter(event_data):
|
||||||
"""Mock filter."""
|
"""Mock filter."""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -3394,7 +3394,7 @@ async def test_report_state_listener_restrictions(hass: HomeAssistant) -> None:
|
||||||
hass.bus.async_listen(EVENT_STATE_REPORTED, listener)
|
hass.bus.async_listen(EVENT_STATE_REPORTED, listener)
|
||||||
|
|
||||||
# Both filter and run_immediately
|
# Both filter and run_immediately
|
||||||
hass.bus.async_listen(EVENT_STATE_REPORTED, listener, event_filter=filter)
|
hass.bus.async_listen(EVENT_STATE_REPORTED, listener, event_filter=mock_filter)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
|
@ -104,77 +104,77 @@ async def test_percentage_to_ordered_list_item() -> None:
|
||||||
|
|
||||||
async def test_ranged_value_to_percentage_large() -> None:
|
async def test_ranged_value_to_percentage_large() -> None:
|
||||||
"""Test a large range of low and high values convert a single value to a percentage."""
|
"""Test a large range of low and high values convert a single value to a percentage."""
|
||||||
range = (1, 255)
|
value_range = (1, 255)
|
||||||
|
|
||||||
assert ranged_value_to_percentage(range, 255) == 100
|
assert ranged_value_to_percentage(value_range, 255) == 100
|
||||||
assert ranged_value_to_percentage(range, 127) == 49
|
assert ranged_value_to_percentage(value_range, 127) == 49
|
||||||
assert ranged_value_to_percentage(range, 10) == 3
|
assert ranged_value_to_percentage(value_range, 10) == 3
|
||||||
assert ranged_value_to_percentage(range, 1) == 0
|
assert ranged_value_to_percentage(value_range, 1) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_percentage_to_ranged_value_large() -> None:
|
async def test_percentage_to_ranged_value_large() -> None:
|
||||||
"""Test a large range of low and high values convert a percentage to a single value."""
|
"""Test a large range of low and high values convert a percentage to a single value."""
|
||||||
range = (1, 255)
|
value_range = (1, 255)
|
||||||
|
|
||||||
assert percentage_to_ranged_value(range, 100) == 255
|
assert percentage_to_ranged_value(value_range, 100) == 255
|
||||||
assert percentage_to_ranged_value(range, 50) == 127.5
|
assert percentage_to_ranged_value(value_range, 50) == 127.5
|
||||||
assert percentage_to_ranged_value(range, 4) == 10.2
|
assert percentage_to_ranged_value(value_range, 4) == 10.2
|
||||||
|
|
||||||
assert math.ceil(percentage_to_ranged_value(range, 100)) == 255
|
assert math.ceil(percentage_to_ranged_value(value_range, 100)) == 255
|
||||||
assert math.ceil(percentage_to_ranged_value(range, 50)) == 128
|
assert math.ceil(percentage_to_ranged_value(value_range, 50)) == 128
|
||||||
assert math.ceil(percentage_to_ranged_value(range, 4)) == 11
|
assert math.ceil(percentage_to_ranged_value(value_range, 4)) == 11
|
||||||
|
|
||||||
|
|
||||||
async def test_ranged_value_to_percentage_small() -> None:
|
async def test_ranged_value_to_percentage_small() -> None:
|
||||||
"""Test a small range of low and high values convert a single value to a percentage."""
|
"""Test a small range of low and high values convert a single value to a percentage."""
|
||||||
range = (1, 6)
|
value_range = (1, 6)
|
||||||
|
|
||||||
assert ranged_value_to_percentage(range, 1) == 16
|
assert ranged_value_to_percentage(value_range, 1) == 16
|
||||||
assert ranged_value_to_percentage(range, 2) == 33
|
assert ranged_value_to_percentage(value_range, 2) == 33
|
||||||
assert ranged_value_to_percentage(range, 3) == 50
|
assert ranged_value_to_percentage(value_range, 3) == 50
|
||||||
assert ranged_value_to_percentage(range, 4) == 66
|
assert ranged_value_to_percentage(value_range, 4) == 66
|
||||||
assert ranged_value_to_percentage(range, 5) == 83
|
assert ranged_value_to_percentage(value_range, 5) == 83
|
||||||
assert ranged_value_to_percentage(range, 6) == 100
|
assert ranged_value_to_percentage(value_range, 6) == 100
|
||||||
|
|
||||||
|
|
||||||
async def test_percentage_to_ranged_value_small() -> None:
|
async def test_percentage_to_ranged_value_small() -> None:
|
||||||
"""Test a small range of low and high values convert a percentage to a single value."""
|
"""Test a small range of low and high values convert a percentage to a single value."""
|
||||||
range = (1, 6)
|
value_range = (1, 6)
|
||||||
|
|
||||||
assert math.ceil(percentage_to_ranged_value(range, 16)) == 1
|
assert math.ceil(percentage_to_ranged_value(value_range, 16)) == 1
|
||||||
assert math.ceil(percentage_to_ranged_value(range, 33)) == 2
|
assert math.ceil(percentage_to_ranged_value(value_range, 33)) == 2
|
||||||
assert math.ceil(percentage_to_ranged_value(range, 50)) == 3
|
assert math.ceil(percentage_to_ranged_value(value_range, 50)) == 3
|
||||||
assert math.ceil(percentage_to_ranged_value(range, 66)) == 4
|
assert math.ceil(percentage_to_ranged_value(value_range, 66)) == 4
|
||||||
assert math.ceil(percentage_to_ranged_value(range, 83)) == 5
|
assert math.ceil(percentage_to_ranged_value(value_range, 83)) == 5
|
||||||
assert math.ceil(percentage_to_ranged_value(range, 100)) == 6
|
assert math.ceil(percentage_to_ranged_value(value_range, 100)) == 6
|
||||||
|
|
||||||
|
|
||||||
async def test_ranged_value_to_percentage_starting_at_one() -> None:
|
async def test_ranged_value_to_percentage_starting_at_one() -> None:
|
||||||
"""Test a range that starts with 1."""
|
"""Test a range that starts with 1."""
|
||||||
range = (1, 4)
|
value_range = (1, 4)
|
||||||
|
|
||||||
assert ranged_value_to_percentage(range, 1) == 25
|
assert ranged_value_to_percentage(value_range, 1) == 25
|
||||||
assert ranged_value_to_percentage(range, 2) == 50
|
assert ranged_value_to_percentage(value_range, 2) == 50
|
||||||
assert ranged_value_to_percentage(range, 3) == 75
|
assert ranged_value_to_percentage(value_range, 3) == 75
|
||||||
assert ranged_value_to_percentage(range, 4) == 100
|
assert ranged_value_to_percentage(value_range, 4) == 100
|
||||||
|
|
||||||
|
|
||||||
async def test_ranged_value_to_percentage_starting_high() -> None:
|
async def test_ranged_value_to_percentage_starting_high() -> None:
|
||||||
"""Test a range that does not start with 1."""
|
"""Test a range that does not start with 1."""
|
||||||
range = (101, 255)
|
value_range = (101, 255)
|
||||||
|
|
||||||
assert ranged_value_to_percentage(range, 101) == 0
|
assert ranged_value_to_percentage(value_range, 101) == 0
|
||||||
assert ranged_value_to_percentage(range, 139) == 25
|
assert ranged_value_to_percentage(value_range, 139) == 25
|
||||||
assert ranged_value_to_percentage(range, 178) == 50
|
assert ranged_value_to_percentage(value_range, 178) == 50
|
||||||
assert ranged_value_to_percentage(range, 217) == 75
|
assert ranged_value_to_percentage(value_range, 217) == 75
|
||||||
assert ranged_value_to_percentage(range, 255) == 100
|
assert ranged_value_to_percentage(value_range, 255) == 100
|
||||||
|
|
||||||
|
|
||||||
async def test_ranged_value_to_percentage_starting_zero() -> None:
|
async def test_ranged_value_to_percentage_starting_zero() -> None:
|
||||||
"""Test a range that starts with 0."""
|
"""Test a range that starts with 0."""
|
||||||
range = (0, 3)
|
value_range = (0, 3)
|
||||||
|
|
||||||
assert ranged_value_to_percentage(range, 0) == 25
|
assert ranged_value_to_percentage(value_range, 0) == 25
|
||||||
assert ranged_value_to_percentage(range, 1) == 50
|
assert ranged_value_to_percentage(value_range, 1) == 50
|
||||||
assert ranged_value_to_percentage(range, 2) == 75
|
assert ranged_value_to_percentage(value_range, 2) == 75
|
||||||
assert ranged_value_to_percentage(range, 3) == 100
|
assert ranged_value_to_percentage(value_range, 3) == 100
|
||||||
|
|
|
@ -568,13 +568,13 @@ def test_no_recursive_secrets(
|
||||||
|
|
||||||
def test_input_class() -> None:
|
def test_input_class() -> None:
|
||||||
"""Test input class."""
|
"""Test input class."""
|
||||||
input = yaml_loader.Input("hello")
|
yaml_input = yaml_loader.Input("hello")
|
||||||
input2 = yaml_loader.Input("hello")
|
yaml_input2 = yaml_loader.Input("hello")
|
||||||
|
|
||||||
assert input.name == "hello"
|
assert yaml_input.name == "hello"
|
||||||
assert input == input2
|
assert yaml_input == yaml_input2
|
||||||
|
|
||||||
assert len({input, input2}) == 1
|
assert len({yaml_input, yaml_input2}) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_input(try_both_loaders, try_both_dumpers) -> None:
|
def test_input(try_both_loaders, try_both_dumpers) -> None:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue