mirror of
https://github.com/home-assistant/core.git
synced 2026-05-07 00:56:50 +02:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aa67f1d023 |
@@ -323,7 +323,7 @@ jobs:
|
||||
exclude-list: '["odroid-xu","qemuarm","qemux86","raspberrypi","raspberrypi2","raspberrypi3","raspberrypi4","tinker"]'
|
||||
|
||||
publish_container:
|
||||
name: Publish to ${{ matrix.registry }}
|
||||
name: Publish meta container for ${{ matrix.registry }}
|
||||
environment: ${{ needs.init.outputs.channel }}
|
||||
if: github.repository_owner == 'home-assistant'
|
||||
needs: ["init", "build_base"]
|
||||
|
||||
Generated
+2
-2
@@ -1495,8 +1495,8 @@ CLAUDE.md @home-assistant/core
|
||||
/tests/components/roku/ @ctalkington
|
||||
/homeassistant/components/romy/ @xeniter
|
||||
/tests/components/romy/ @xeniter
|
||||
/homeassistant/components/roomba/ @pschmitt @cyr-ius @shenxn
|
||||
/tests/components/roomba/ @pschmitt @cyr-ius @shenxn
|
||||
/homeassistant/components/roomba/ @pschmitt @cyr-ius @shenxn @Orhideous
|
||||
/tests/components/roomba/ @pschmitt @cyr-ius @shenxn @Orhideous
|
||||
/homeassistant/components/roon/ @pavoni
|
||||
/tests/components/roon/ @pavoni
|
||||
/homeassistant/components/route_b_smart_meter/ @SeraphicRav
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
"documentation": "https://www.home-assistant.io/integrations/acer_projector",
|
||||
"iot_class": "local_polling",
|
||||
"quality_scale": "legacy",
|
||||
"requirements": ["serialx==1.7.1"]
|
||||
"requirements": ["serialx==1.7.0"]
|
||||
}
|
||||
|
||||
@@ -1,16 +1,36 @@
|
||||
"""Provides triggers for buttons."""
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers.automation import DomainSpec
|
||||
from homeassistant.helpers.trigger import StatelessEntityTriggerBase, Trigger
|
||||
from homeassistant.helpers.trigger import (
|
||||
ENTITY_STATE_TRIGGER_SCHEMA,
|
||||
EntityTriggerBase,
|
||||
Trigger,
|
||||
)
|
||||
|
||||
from . import DOMAIN
|
||||
|
||||
|
||||
class ButtonPressedTrigger(StatelessEntityTriggerBase):
|
||||
class ButtonPressedTrigger(EntityTriggerBase):
|
||||
"""Trigger for button entity presses."""
|
||||
|
||||
_domain_specs = {DOMAIN: DomainSpec()}
|
||||
_schema = ENTITY_STATE_TRIGGER_SCHEMA
|
||||
|
||||
def is_valid_transition(self, from_state: State, to_state: State) -> bool:
|
||||
"""Check if the origin state is valid and different from the current state."""
|
||||
|
||||
# UNKNOWN is a valid from_state, otherwise the first time the button is pressed
|
||||
# would not trigger
|
||||
if from_state.state == STATE_UNAVAILABLE:
|
||||
return False
|
||||
|
||||
return from_state.state != to_state.state
|
||||
|
||||
def is_valid_state(self, state: State) -> bool:
|
||||
"""Check if the new state is not invalid."""
|
||||
return state.state not in (STATE_UNAVAILABLE, STATE_UNKNOWN)
|
||||
|
||||
|
||||
TRIGGERS: dict[str, type[Trigger]] = {
|
||||
|
||||
@@ -6,22 +6,39 @@ from homeassistant.components.event import (
|
||||
DoorbellEventType,
|
||||
EventDeviceClass,
|
||||
)
|
||||
from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers.automation import DomainSpec
|
||||
from homeassistant.helpers.trigger import StatelessEntityTriggerBase, Trigger
|
||||
from homeassistant.helpers.trigger import (
|
||||
ENTITY_STATE_TRIGGER_SCHEMA,
|
||||
EntityTriggerBase,
|
||||
Trigger,
|
||||
)
|
||||
|
||||
|
||||
class DoorbellRangTrigger(StatelessEntityTriggerBase):
|
||||
class DoorbellRangTrigger(EntityTriggerBase):
|
||||
"""Trigger for doorbell event entity when a ring event is received."""
|
||||
|
||||
_domain_specs = {EVENT_DOMAIN: DomainSpec(device_class=EventDeviceClass.DOORBELL)}
|
||||
_schema = ENTITY_STATE_TRIGGER_SCHEMA
|
||||
|
||||
def is_valid_state(self, state: State) -> bool:
|
||||
"""Check if the entity is available and the event type is ring."""
|
||||
return super().is_valid_state(state) and (
|
||||
state.attributes.get(ATTR_EVENT_TYPE) == DoorbellEventType.RING
|
||||
return (
|
||||
state.state not in (STATE_UNAVAILABLE, STATE_UNKNOWN)
|
||||
and state.attributes.get(ATTR_EVENT_TYPE) == DoorbellEventType.RING
|
||||
)
|
||||
|
||||
def is_valid_transition(self, from_state: State, to_state: State) -> bool:
|
||||
"""Check if the origin state is valid and different from the current state."""
|
||||
|
||||
# UNKNOWN is a valid from_state, otherwise the first time the event is received
|
||||
# would not trigger
|
||||
if from_state.state == STATE_UNAVAILABLE:
|
||||
return False
|
||||
|
||||
return from_state.state != to_state.state
|
||||
|
||||
|
||||
TRIGGERS: dict[str, type[Trigger]] = {
|
||||
"rang": DoorbellRangTrigger,
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import CONF_OPTIONS
|
||||
from homeassistant.const import CONF_OPTIONS, STATE_UNAVAILABLE, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.automation import DomainSpec
|
||||
from homeassistant.helpers.trigger import (
|
||||
ENTITY_STATE_TRIGGER_SCHEMA,
|
||||
StatelessEntityTriggerBase,
|
||||
EntityTriggerBase,
|
||||
Trigger,
|
||||
TriggerConfig,
|
||||
)
|
||||
@@ -28,7 +28,7 @@ EVENT_RECEIVED_TRIGGER_SCHEMA = ENTITY_STATE_TRIGGER_SCHEMA.extend(
|
||||
)
|
||||
|
||||
|
||||
class EventReceivedTrigger(StatelessEntityTriggerBase):
|
||||
class EventReceivedTrigger(EntityTriggerBase):
|
||||
"""Trigger for event entity when it receives a matching event."""
|
||||
|
||||
_domain_specs = {DOMAIN: DomainSpec()}
|
||||
@@ -39,10 +39,21 @@ class EventReceivedTrigger(StatelessEntityTriggerBase):
|
||||
super().__init__(hass, config)
|
||||
self._event_types = set(self._options[CONF_EVENT_TYPE])
|
||||
|
||||
def is_valid_transition(self, from_state: State, to_state: State) -> bool:
|
||||
"""Check if the origin state is valid and different from the current state."""
|
||||
|
||||
# UNKNOWN is a valid from_state, otherwise the first time the event is received
|
||||
# would not trigger
|
||||
if from_state.state == STATE_UNAVAILABLE:
|
||||
return False
|
||||
|
||||
return from_state.state != to_state.state
|
||||
|
||||
def is_valid_state(self, state: State) -> bool:
|
||||
"""Check if the event type matches one of the configured types."""
|
||||
return super().is_valid_state(state) and (
|
||||
state.attributes.get(ATTR_EVENT_TYPE) in self._event_types
|
||||
"""Check if the event type is valid and matches one of the configured types."""
|
||||
return (
|
||||
state.state not in (STATE_UNAVAILABLE, STATE_UNKNOWN)
|
||||
and state.attributes.get(ATTR_EVENT_TYPE) in self._event_types
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import voluptuous as vol
|
||||
from homeassistant.auth.models import User
|
||||
from homeassistant.auth.providers import homeassistant as auth_ha
|
||||
from homeassistant.components.http import KEY_HASS, KEY_HASS_USER, HomeAssistantView
|
||||
from homeassistant.components.http.const import is_supervisor_unix_socket_request
|
||||
from homeassistant.components.http.data_validator import RequestDataValidator
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
@@ -42,18 +41,14 @@ class HassIOBaseAuth(HomeAssistantView):
|
||||
|
||||
def _check_access(self, request: web.Request) -> None:
|
||||
"""Check if this call is from Supervisor."""
|
||||
# Requests over the Supervisor Unix socket are authenticated by the
|
||||
# http auth middleware as the Supervisor user, so the caller-IP check
|
||||
# below does not apply (and would crash, since `peername` is empty for
|
||||
# Unix sockets). The user-ID check still runs to ensure only the
|
||||
# Supervisor user can reach this endpoint.
|
||||
if not is_supervisor_unix_socket_request(request):
|
||||
hassio_ip = os.environ["SUPERVISOR"].split(":")[0]
|
||||
assert request.transport
|
||||
peername = request.transport.get_extra_info("peername")
|
||||
if not peername or ip_address(peername[0]) != ip_address(hassio_ip):
|
||||
_LOGGER.error("Invalid auth request from %s", request.remote)
|
||||
raise HTTPUnauthorized
|
||||
# Check caller IP
|
||||
hassio_ip = os.environ["SUPERVISOR"].split(":")[0]
|
||||
assert request.transport
|
||||
if ip_address(request.transport.get_extra_info("peername")[0]) != ip_address(
|
||||
hassio_ip
|
||||
):
|
||||
_LOGGER.error("Invalid auth request from %s", request.remote)
|
||||
raise HTTPUnauthorized
|
||||
|
||||
# Check caller token
|
||||
if request[KEY_HASS_USER].id != self.user.id:
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/holiday",
|
||||
"iot_class": "local_polling",
|
||||
"requirements": ["holidays==0.96", "babel==2.15.0"]
|
||||
"requirements": ["holidays==0.95", "babel==2.15.0"]
|
||||
}
|
||||
|
||||
@@ -7,5 +7,5 @@
|
||||
"integration_type": "hub",
|
||||
"iot_class": "cloud_push",
|
||||
"loggers": ["homematicip"],
|
||||
"requirements": ["homematicip==2.10.0"]
|
||||
"requirements": ["homematicip==2.9.0"]
|
||||
}
|
||||
|
||||
@@ -76,12 +76,14 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
vol.Optional(CONF_SEARCH, default="UnSeen UnDeleted"): str,
|
||||
# The default for new entries is to not include text and headers
|
||||
vol.Optional(CONF_EVENT_MESSAGE_DATA, default=[]): EVENT_MESSAGE_DATA_SELECTOR,
|
||||
vol.Optional(
|
||||
CONF_SSL_CIPHER_LIST, default=SSLCipherList.PYTHON_DEFAULT
|
||||
): CIPHER_SELECTOR,
|
||||
vol.Optional(CONF_VERIFY_SSL, default=True): BOOLEAN_SELECTOR,
|
||||
}
|
||||
)
|
||||
CONFIG_SCHEMA_ADVANCED = {
|
||||
vol.Optional(
|
||||
CONF_SSL_CIPHER_LIST, default=SSLCipherList.PYTHON_DEFAULT
|
||||
): CIPHER_SELECTOR,
|
||||
vol.Optional(CONF_VERIFY_SSL, default=True): BOOLEAN_SELECTOR,
|
||||
}
|
||||
|
||||
OPTIONS_SCHEMA = vol.Schema(
|
||||
{
|
||||
@@ -91,15 +93,18 @@ OPTIONS_SCHEMA = vol.Schema(
|
||||
vol.Optional(
|
||||
CONF_EVENT_MESSAGE_DATA, default=MESSAGE_DATA_OPTIONS
|
||||
): EVENT_MESSAGE_DATA_SELECTOR,
|
||||
vol.Optional(CONF_CUSTOM_EVENT_DATA_TEMPLATE): TEMPLATE_SELECTOR,
|
||||
vol.Optional(CONF_MAX_MESSAGE_SIZE, default=DEFAULT_MAX_MESSAGE_SIZE): vol.All(
|
||||
cv.positive_int,
|
||||
vol.Range(min=DEFAULT_MAX_MESSAGE_SIZE, max=MAX_MESSAGE_SIZE_LIMIT),
|
||||
),
|
||||
vol.Optional(CONF_ENABLE_PUSH, default=True): BOOLEAN_SELECTOR,
|
||||
}
|
||||
)
|
||||
|
||||
OPTIONS_SCHEMA_ADVANCED = {
|
||||
vol.Optional(CONF_CUSTOM_EVENT_DATA_TEMPLATE): TEMPLATE_SELECTOR,
|
||||
vol.Optional(CONF_MAX_MESSAGE_SIZE, default=DEFAULT_MAX_MESSAGE_SIZE): vol.All(
|
||||
cv.positive_int,
|
||||
vol.Range(min=DEFAULT_MAX_MESSAGE_SIZE, max=MAX_MESSAGE_SIZE_LIMIT),
|
||||
),
|
||||
vol.Optional(CONF_ENABLE_PUSH, default=True): BOOLEAN_SELECTOR,
|
||||
}
|
||||
|
||||
|
||||
async def validate_input(
|
||||
hass: HomeAssistant, user_input: dict[str, Any]
|
||||
@@ -146,6 +151,8 @@ class IMAPConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle the initial step."""
|
||||
|
||||
schema = CONFIG_SCHEMA
|
||||
if self.show_advanced_options:
|
||||
schema = schema.extend(CONFIG_SCHEMA_ADVANCED)
|
||||
|
||||
if user_input is None:
|
||||
return self.async_show_form(step_id="user", data_schema=schema)
|
||||
@@ -243,6 +250,8 @@ class ImapOptionsFlow(OptionsFlow):
|
||||
return self.async_create_entry(data={})
|
||||
|
||||
schema = OPTIONS_SCHEMA
|
||||
if self.show_advanced_options:
|
||||
schema = schema.extend(OPTIONS_SCHEMA_ADVANCED)
|
||||
schema = self.add_suggested_values_to_schema(schema, entry_data)
|
||||
|
||||
return self.async_show_form(step_id="init", data_schema=schema, errors=errors)
|
||||
|
||||
@@ -5,30 +5,31 @@ from datetime import timedelta
|
||||
from mill import Mill
|
||||
from mill_local import Mill as MillLocal
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, CONF_USERNAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import CLOUD, CONNECTION_TYPE, DOMAIN, LOCAL
|
||||
from .coordinator import MillDataUpdateCoordinator, MillHistoricDataUpdateCoordinator
|
||||
from .coordinator import (
|
||||
MillConfigEntry,
|
||||
MillDataUpdateCoordinator,
|
||||
MillHistoricDataUpdateCoordinator,
|
||||
)
|
||||
|
||||
PLATFORMS = [Platform.CLIMATE, Platform.NUMBER, Platform.SENSOR]
|
||||
|
||||
__all__ = ["CLOUD", "CONNECTION_TYPE", "DOMAIN", "LOCAL"]
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: MillConfigEntry) -> bool:
|
||||
"""Set up the Mill heater."""
|
||||
hass.data.setdefault(DOMAIN, {LOCAL: {}, CLOUD: {}})
|
||||
|
||||
if entry.data.get(CONNECTION_TYPE) == LOCAL:
|
||||
mill_data_connection = MillLocal(
|
||||
entry.data[CONF_IP_ADDRESS],
|
||||
websession=async_get_clientsession(hass),
|
||||
)
|
||||
update_interval = timedelta(seconds=15)
|
||||
key = entry.data[CONF_IP_ADDRESS]
|
||||
conn_type = LOCAL
|
||||
else:
|
||||
mill_data_connection = Mill(
|
||||
entry.data[CONF_USERNAME],
|
||||
@@ -36,8 +37,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
websession=async_get_clientsession(hass),
|
||||
)
|
||||
update_interval = timedelta(seconds=30)
|
||||
key = entry.data[CONF_USERNAME]
|
||||
conn_type = CLOUD
|
||||
|
||||
historic_data_coordinator = MillHistoricDataUpdateCoordinator(
|
||||
hass,
|
||||
@@ -56,14 +55,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
)
|
||||
|
||||
await data_coordinator.async_config_entry_first_refresh()
|
||||
# Uses legacy hass.data[DOMAIN] pattern
|
||||
# pylint: disable-next=hass-use-runtime-data
|
||||
hass.data[DOMAIN][conn_type][key] = data_coordinator
|
||||
entry.runtime_data = data_coordinator
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: MillConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
"""Support for mill wifi-enabled home heaters."""
|
||||
# pylint: disable=hass-use-runtime-data # Uses legacy hass.data[DOMAIN] pattern
|
||||
|
||||
from typing import Any
|
||||
|
||||
@@ -14,14 +13,7 @@ from homeassistant.components.climate import (
|
||||
HVACAction,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
CONF_IP_ADDRESS,
|
||||
CONF_USERNAME,
|
||||
PRECISION_TENTHS,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
|
||||
@@ -33,7 +25,6 @@ from .const import (
|
||||
ATTR_COMFORT_TEMP,
|
||||
ATTR_ROOM_NAME,
|
||||
ATTR_SLEEP_TEMP,
|
||||
CLOUD,
|
||||
CONNECTION_TYPE,
|
||||
DOMAIN,
|
||||
LOCAL,
|
||||
@@ -42,7 +33,7 @@ from .const import (
|
||||
MIN_TEMP,
|
||||
SERVICE_SET_ROOM_TEMP,
|
||||
)
|
||||
from .coordinator import MillDataUpdateCoordinator
|
||||
from .coordinator import MillConfigEntry, MillDataUpdateCoordinator
|
||||
from .entity import MillBaseEntity
|
||||
|
||||
SET_ROOM_TEMP_SCHEMA = vol.Schema(
|
||||
@@ -57,17 +48,16 @@ SET_ROOM_TEMP_SCHEMA = vol.Schema(
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: MillConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Mill climate."""
|
||||
mill_data_coordinator = entry.runtime_data
|
||||
|
||||
if entry.data.get(CONNECTION_TYPE) == LOCAL:
|
||||
mill_data_coordinator = hass.data[DOMAIN][LOCAL][entry.data[CONF_IP_ADDRESS]]
|
||||
async_add_entities([LocalMillHeater(mill_data_coordinator)])
|
||||
return
|
||||
|
||||
mill_data_coordinator = hass.data[DOMAIN][CLOUD][entry.data[CONF_USERNAME]]
|
||||
|
||||
entities = [
|
||||
MillHeater(mill_data_coordinator, mill_device)
|
||||
for mill_device in mill_data_coordinator.data.values()
|
||||
|
||||
@@ -57,6 +57,9 @@ class MillDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
)
|
||||
|
||||
|
||||
type MillConfigEntry = ConfigEntry[MillDataUpdateCoordinator]
|
||||
|
||||
|
||||
class MillHistoricDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
"""Class to manage fetching Mill historic data."""
|
||||
|
||||
|
||||
@@ -3,28 +3,23 @@
|
||||
from mill import Heater, MillDevice
|
||||
|
||||
from homeassistant.components.number import NumberDeviceClass, NumberEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_USERNAME, UnitOfPower
|
||||
from homeassistant.const import UnitOfPower
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .const import CLOUD, CONNECTION_TYPE, DOMAIN
|
||||
from .coordinator import MillDataUpdateCoordinator
|
||||
from .const import CLOUD, CONNECTION_TYPE
|
||||
from .coordinator import MillConfigEntry, MillDataUpdateCoordinator
|
||||
from .entity import MillBaseEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: MillConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Mill Number."""
|
||||
if entry.data.get(CONNECTION_TYPE) == CLOUD:
|
||||
# Uses legacy hass.data[DOMAIN] pattern
|
||||
# pylint: disable-next=hass-use-runtime-data
|
||||
mill_data_coordinator: MillDataUpdateCoordinator = hass.data[DOMAIN][CLOUD][
|
||||
entry.data[CONF_USERNAME]
|
||||
]
|
||||
mill_data_coordinator = entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
MillNumber(mill_data_coordinator, mill_device)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
"""Support for mill wifi-enabled home heaters."""
|
||||
# pylint: disable=hass-use-runtime-data # Uses legacy hass.data[DOMAIN] pattern
|
||||
|
||||
import mill
|
||||
|
||||
@@ -9,12 +8,9 @@ from homeassistant.components.sensor import (
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_PARTS_PER_BILLION,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
CONF_IP_ADDRESS,
|
||||
CONF_USERNAME,
|
||||
PERCENTAGE,
|
||||
EntityCategory,
|
||||
UnitOfEnergy,
|
||||
@@ -29,11 +25,9 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import (
|
||||
BATTERY,
|
||||
CLOUD,
|
||||
CONNECTION_TYPE,
|
||||
CONSUMPTION_TODAY,
|
||||
CONSUMPTION_YEAR,
|
||||
DOMAIN,
|
||||
ECO2,
|
||||
HUMIDITY,
|
||||
LOCAL,
|
||||
@@ -41,7 +35,7 @@ from .const import (
|
||||
TEMPERATURE,
|
||||
TVOC,
|
||||
)
|
||||
from .coordinator import MillDataUpdateCoordinator
|
||||
from .coordinator import MillConfigEntry, MillDataUpdateCoordinator
|
||||
from .entity import MillBaseEntity
|
||||
|
||||
HEATER_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||
@@ -146,13 +140,13 @@ SOCKET_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: MillConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Mill sensor."""
|
||||
if entry.data.get(CONNECTION_TYPE) == LOCAL:
|
||||
mill_data_coordinator = hass.data[DOMAIN][LOCAL][entry.data[CONF_IP_ADDRESS]]
|
||||
mill_data_coordinator = entry.runtime_data
|
||||
|
||||
if entry.data.get(CONNECTION_TYPE) == LOCAL:
|
||||
async_add_entities(
|
||||
LocalMillSensor(
|
||||
mill_data_coordinator,
|
||||
@@ -162,8 +156,6 @@ async def async_setup_entry(
|
||||
)
|
||||
return
|
||||
|
||||
mill_data_coordinator = hass.data[DOMAIN][CLOUD][entry.data[CONF_USERNAME]]
|
||||
|
||||
entities = [
|
||||
MillSensor(
|
||||
mill_data_coordinator,
|
||||
|
||||
@@ -16,8 +16,6 @@ from typing import TYPE_CHECKING, Any
|
||||
from uuid import uuid4
|
||||
|
||||
import certifi
|
||||
import paho.mqtt.client as mqtt
|
||||
from paho.mqtt.matcher import MQTTMatcher
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
@@ -49,7 +47,6 @@ from homeassistant.setup import SetupPhases, async_pause_setup
|
||||
from homeassistant.util.collection import chunked_or_all
|
||||
from homeassistant.util.logging import catch_log_exception, log_exception
|
||||
|
||||
from .async_client import AsyncMQTTClient
|
||||
from .const import (
|
||||
CONF_BIRTH_MESSAGE,
|
||||
CONF_BROKER,
|
||||
@@ -89,6 +86,13 @@ from .models import (
|
||||
)
|
||||
from .util import EnsureJobAfterCooldown, get_file_path, mqtt_config_entry_enabled
|
||||
|
||||
if TYPE_CHECKING:
|
||||
# Only import for paho-mqtt type checking here, imports are done locally
|
||||
# because integrations should be able to optionally rely on MQTT.
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
from .async_client import AsyncMQTTClient
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
MIN_BUFFER_SIZE = 131072 # Minimum buffer size to use if preferred size fails
|
||||
@@ -319,6 +323,12 @@ class MqttClientSetup:
|
||||
The setup of the MQTT client should be run in an executor job,
|
||||
because it accesses files, so it does IO.
|
||||
"""
|
||||
# We don't import on the top because some integrations
|
||||
# should be able to optionally rely on MQTT.
|
||||
from paho.mqtt import client as mqtt # noqa: PLC0415
|
||||
|
||||
from .async_client import AsyncMQTTClient # noqa: PLC0415
|
||||
|
||||
config = self._config
|
||||
clean_session: bool | None = None
|
||||
# If no protocol setting is set in the config entry data
|
||||
@@ -551,6 +561,7 @@ class MQTT:
|
||||
"""Start the misc periodic."""
|
||||
assert self._misc_timer is None, "Misc periodic already started"
|
||||
_LOGGER.debug("%s: Starting client misc loop", self.config_entry.title)
|
||||
import paho.mqtt.client as mqtt # noqa: PLC0415
|
||||
|
||||
# Inner function to avoid having to check late import
|
||||
# each time the function is called.
|
||||
@@ -694,6 +705,7 @@ class MQTT:
|
||||
|
||||
async def async_connect(self, client_available: asyncio.Future[bool]) -> None:
|
||||
"""Connect to the host. Does not process messages yet."""
|
||||
import paho.mqtt.client as mqtt # noqa: PLC0415
|
||||
|
||||
result: int | None = None
|
||||
self._available_future = client_available
|
||||
@@ -751,6 +763,7 @@ class MQTT:
|
||||
|
||||
async def _reconnect_loop(self) -> None:
|
||||
"""Reconnect to the MQTT server."""
|
||||
import paho.mqtt.client as mqtt # noqa: PLC0415
|
||||
|
||||
while True:
|
||||
if not self.connected:
|
||||
@@ -1252,6 +1265,9 @@ class MQTT:
|
||||
@callback
|
||||
def _async_handle_callback_exception(self, status: mqtt.MQTTErrorCode) -> None:
|
||||
"""Handle a callback exception."""
|
||||
# We don't import on the top because some integrations
|
||||
# should be able to optionally rely on MQTT.
|
||||
import paho.mqtt.client as mqtt # noqa: PLC0415
|
||||
|
||||
_LOGGER.warning(
|
||||
"Error returned from MQTT server: %s",
|
||||
@@ -1296,6 +1312,8 @@ class MQTT:
|
||||
) -> None:
|
||||
"""Wait for ACK from broker or raise on error."""
|
||||
if result_code != 0:
|
||||
import paho.mqtt.client as mqtt # noqa: PLC0415
|
||||
|
||||
raise HomeAssistantError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="mqtt_broker_error",
|
||||
@@ -1342,6 +1360,8 @@ class MQTT:
|
||||
|
||||
|
||||
def _matcher_for_topic(subscription: str) -> Callable[[str], bool]:
|
||||
from paho.mqtt.matcher import MQTTMatcher # noqa: PLC0415
|
||||
|
||||
matcher = MQTTMatcher() # type: ignore[no-untyped-call]
|
||||
matcher[subscription] = True
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ from cryptography.hazmat.primitives.serialization import (
|
||||
load_pem_private_key,
|
||||
)
|
||||
from cryptography.x509 import load_der_x509_certificate, load_pem_x509_certificate
|
||||
import paho.mqtt.client as mqtt
|
||||
import voluptuous as vol
|
||||
import yaml
|
||||
|
||||
@@ -5480,6 +5479,10 @@ def try_connection(
|
||||
user_input: dict[str, Any],
|
||||
) -> bool:
|
||||
"""Test if we can connect to an MQTT broker."""
|
||||
# We don't import on the top because some integrations
|
||||
# should be able to optionally rely on MQTT.
|
||||
import paho.mqtt.client as mqtt # noqa: PLC0415
|
||||
|
||||
mqtt_client_setup = MqttClientSetup(user_input)
|
||||
mqtt_client_setup.setup()
|
||||
client = mqtt_client_setup.client
|
||||
|
||||
@@ -9,8 +9,6 @@ from enum import StrEnum
|
||||
import logging
|
||||
from typing import TYPE_CHECKING, Any, TypedDict
|
||||
|
||||
from paho.mqtt.client import MQTTMessage
|
||||
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_NAME, Platform
|
||||
from homeassistant.core import CALLBACK_TYPE, callback
|
||||
from homeassistant.exceptions import ServiceValidationError, TemplateError
|
||||
@@ -26,6 +24,8 @@ from homeassistant.helpers.typing import (
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from paho.mqtt.client import MQTTMessage
|
||||
|
||||
from .client import MQTT, Subscription
|
||||
from .debug_info import TimestampedPublishMessage
|
||||
from .device_trigger import Trigger
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"domain": "roomba",
|
||||
"name": "iRobot Roomba and Braava",
|
||||
"codeowners": ["@pschmitt", "@cyr-ius", "@shenxn"],
|
||||
"codeowners": ["@pschmitt", "@cyr-ius", "@shenxn", "@Orhideous"],
|
||||
"config_flow": true,
|
||||
"dhcp": [
|
||||
{
|
||||
|
||||
@@ -1,16 +1,36 @@
|
||||
"""Provides triggers for scenes."""
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers.automation import DomainSpec
|
||||
from homeassistant.helpers.trigger import StatelessEntityTriggerBase, Trigger
|
||||
from homeassistant.helpers.trigger import (
|
||||
ENTITY_STATE_TRIGGER_SCHEMA,
|
||||
EntityTriggerBase,
|
||||
Trigger,
|
||||
)
|
||||
|
||||
from . import DOMAIN
|
||||
|
||||
|
||||
class SceneActivatedTrigger(StatelessEntityTriggerBase):
|
||||
class SceneActivatedTrigger(EntityTriggerBase):
|
||||
"""Trigger for scene entity activations."""
|
||||
|
||||
_domain_specs = {DOMAIN: DomainSpec()}
|
||||
_schema = ENTITY_STATE_TRIGGER_SCHEMA
|
||||
|
||||
def is_valid_transition(self, from_state: State, to_state: State) -> bool:
|
||||
"""Check if the origin state is valid and different from the current state."""
|
||||
|
||||
# UNKNOWN is a valid from_state, otherwise the first time the scene is activated
|
||||
# it would not trigger
|
||||
if from_state.state == STATE_UNAVAILABLE:
|
||||
return False
|
||||
|
||||
return from_state.state != to_state.state
|
||||
|
||||
def is_valid_state(self, state: State) -> bool:
|
||||
"""Check if the new state is not invalid."""
|
||||
return state.state not in (STATE_UNAVAILABLE, STATE_UNKNOWN)
|
||||
|
||||
|
||||
TRIGGERS: dict[str, type[Trigger]] = {
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
"codeowners": ["@fabaff"],
|
||||
"documentation": "https://www.home-assistant.io/integrations/serial",
|
||||
"iot_class": "local_polling",
|
||||
"requirements": ["serialx==1.7.1"]
|
||||
"requirements": ["serialx==1.7.0"]
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ from typing import TYPE_CHECKING, cast, override
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_OPTIONS, CONF_TARGET
|
||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_TARGET
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback, split_entity_id
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
@@ -25,7 +25,6 @@ from .const import DATA_COMPONENT, DOMAIN, TodoItemStatus
|
||||
ITEM_TRIGGER_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_TARGET): cv.TARGET_FIELDS,
|
||||
vol.Required(CONF_OPTIONS, default={}): {},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -7,5 +7,5 @@
|
||||
"integration_type": "system",
|
||||
"iot_class": "local_push",
|
||||
"quality_scale": "internal",
|
||||
"requirements": ["aiousbwatcher==1.1.2", "serialx==1.7.1"]
|
||||
"requirements": ["aiousbwatcher==1.1.2", "serialx==1.7.0"]
|
||||
}
|
||||
|
||||
@@ -8,5 +8,5 @@
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["holidays"],
|
||||
"quality_scale": "internal",
|
||||
"requirements": ["holidays==0.96"]
|
||||
"requirements": ["holidays==0.95"]
|
||||
}
|
||||
|
||||
@@ -626,30 +626,6 @@ class EntityOriginStateTriggerBase(EntityTriggerBase):
|
||||
)
|
||||
|
||||
|
||||
class StatelessEntityTriggerBase(EntityTriggerBase):
|
||||
"""Trigger for entities that don't carry meaningful state.
|
||||
|
||||
Used for stateless entities (buttons, scenes, doorbells, events)
|
||||
whose `state.state` is just a timestamp of the last activation.
|
||||
"""
|
||||
|
||||
_schema: vol.Schema = ENTITY_STATE_TRIGGER_SCHEMA
|
||||
|
||||
def is_valid_transition(self, from_state: State, to_state: State) -> bool:
|
||||
"""Check if the origin state is available and the state has changed.
|
||||
|
||||
STATE_UNKNOWN is allowed as the origin state so the first
|
||||
activation fires.
|
||||
"""
|
||||
if from_state.state == STATE_UNAVAILABLE:
|
||||
return False
|
||||
return from_state.state != to_state.state
|
||||
|
||||
def is_valid_state(self, state: State) -> bool:
|
||||
"""Check that the entity has been activated at least once."""
|
||||
return state.state not in self._excluded_states
|
||||
|
||||
|
||||
NUMERICAL_ATTRIBUTE_CHANGED_TRIGGER_SCHEMA = ENTITY_STATE_TRIGGER_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_OPTIONS, default={}): vol.All(
|
||||
|
||||
@@ -63,7 +63,7 @@ PyTurboJPEG==1.8.3
|
||||
PyYAML==6.0.3
|
||||
requests==2.33.1
|
||||
securetar==2026.4.1
|
||||
serialx==1.7.1
|
||||
serialx==1.7.0
|
||||
SQLAlchemy==2.0.49
|
||||
standard-aifc==3.13.0
|
||||
standard-telnetlib==3.13.0
|
||||
|
||||
Generated
+3
-3
@@ -1245,7 +1245,7 @@ hole==0.9.0
|
||||
|
||||
# homeassistant.components.holiday
|
||||
# homeassistant.components.workday
|
||||
holidays==0.96
|
||||
holidays==0.95
|
||||
|
||||
# homeassistant.components.frontend
|
||||
home-assistant-frontend==20260429.3
|
||||
@@ -1260,7 +1260,7 @@ homekit-audio-proxy==1.2.1
|
||||
homelink-integration-api==0.0.1
|
||||
|
||||
# homeassistant.components.homematicip_cloud
|
||||
homematicip==2.10.0
|
||||
homematicip==2.9.0
|
||||
|
||||
# homeassistant.components.homevolt
|
||||
homevolt==0.5.0
|
||||
@@ -2951,7 +2951,7 @@ sentry-sdk==2.48.0
|
||||
# homeassistant.components.acer_projector
|
||||
# homeassistant.components.serial
|
||||
# homeassistant.components.usb
|
||||
serialx==1.7.1
|
||||
serialx==1.7.0
|
||||
|
||||
# homeassistant.components.sfr_box
|
||||
sfrbox-api==0.1.1
|
||||
|
||||
Generated
+3
-3
@@ -1109,7 +1109,7 @@ hole==0.9.0
|
||||
|
||||
# homeassistant.components.holiday
|
||||
# homeassistant.components.workday
|
||||
holidays==0.96
|
||||
holidays==0.95
|
||||
|
||||
# homeassistant.components.frontend
|
||||
home-assistant-frontend==20260429.3
|
||||
@@ -1124,7 +1124,7 @@ homekit-audio-proxy==1.2.1
|
||||
homelink-integration-api==0.0.1
|
||||
|
||||
# homeassistant.components.homematicip_cloud
|
||||
homematicip==2.10.0
|
||||
homematicip==2.9.0
|
||||
|
||||
# homeassistant.components.homevolt
|
||||
homevolt==0.5.0
|
||||
@@ -2517,7 +2517,7 @@ sentry-sdk==2.48.0
|
||||
# homeassistant.components.acer_projector
|
||||
# homeassistant.components.serial
|
||||
# homeassistant.components.usb
|
||||
serialx==1.7.1
|
||||
serialx==1.7.0
|
||||
|
||||
# homeassistant.components.sfr_box
|
||||
sfrbox-api==0.1.1
|
||||
|
||||
+5
-1
@@ -29,7 +29,6 @@ from unittest.mock import AsyncMock, Mock, patch
|
||||
from aiohttp.test_utils import unused_port as get_test_instance_port
|
||||
from annotatedyaml import load_yaml_dict, loader as yaml_loader
|
||||
import attr
|
||||
from paho.mqtt.client import MQTTMessage
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
import voluptuous as vol
|
||||
@@ -454,6 +453,11 @@ def async_fire_mqtt_message(
|
||||
retain: bool = False,
|
||||
) -> None:
|
||||
"""Fire the MQTT message."""
|
||||
# Local import to avoid processing MQTT modules when running a testcase
|
||||
# which does not use MQTT.
|
||||
|
||||
from paho.mqtt.client import MQTTMessage # noqa: PLC0415
|
||||
|
||||
from homeassistant.components.mqtt import MqttData # noqa: PLC0415
|
||||
|
||||
if isinstance(payload, str):
|
||||
|
||||
@@ -63,9 +63,6 @@ async def test_battery_conditions_gated_by_labs_flag(
|
||||
await assert_condition_gated_by_labs_flag(hass, caplog, condition)
|
||||
|
||||
|
||||
_LEVEL_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 50}}}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("condition_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
@@ -74,7 +71,6 @@ _LEVEL_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 50}}}
|
||||
("battery.is_not_low", {}, True, True),
|
||||
("battery.is_charging", {}, True, True),
|
||||
("battery.is_not_charging", {}, True, True),
|
||||
("battery.is_level", _LEVEL_THRESHOLD, True, True),
|
||||
],
|
||||
)
|
||||
async def test_battery_condition_options_validation(
|
||||
|
||||
@@ -63,10 +63,6 @@ async def test_battery_triggers_gated_by_labs_flag(
|
||||
await assert_trigger_gated_by_labs_flag(hass, caplog, trigger_key)
|
||||
|
||||
|
||||
_LEVEL_CHANGED_THRESHOLD = {"threshold": {"type": "any"}}
|
||||
_LEVEL_CROSSED_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 50}}}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("trigger_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
@@ -75,8 +71,6 @@ _LEVEL_CROSSED_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 5
|
||||
("battery.not_low", {}, True, True),
|
||||
("battery.started_charging", {}, True, True),
|
||||
("battery.stopped_charging", {}, True, True),
|
||||
("battery.level_changed", _LEVEL_CHANGED_THRESHOLD, False, False),
|
||||
("battery.level_crossed_threshold", _LEVEL_CROSSED_THRESHOLD, True, True),
|
||||
],
|
||||
)
|
||||
async def test_battery_trigger_options_validation(
|
||||
|
||||
@@ -56,35 +56,10 @@ from tests.common import (
|
||||
async_mock_service,
|
||||
mock_device_registry,
|
||||
)
|
||||
from tests.components.common import assert_trigger_options_supported
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("trigger_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
[
|
||||
("calendar.event_started", {}, False, False),
|
||||
("calendar.event_ended", {}, False, False),
|
||||
],
|
||||
)
|
||||
async def test_calendar_trigger_options_validation(
|
||||
hass: HomeAssistant,
|
||||
trigger_key: str,
|
||||
base_options: dict[str, Any] | None,
|
||||
supports_behavior: bool,
|
||||
supports_duration: bool,
|
||||
) -> None:
|
||||
"""Test that calendar triggers support the expected options."""
|
||||
await assert_trigger_options_supported(
|
||||
hass,
|
||||
trigger_key,
|
||||
base_options,
|
||||
supports_behavior=supports_behavior,
|
||||
supports_duration=supports_duration,
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class TriggerFormat:
|
||||
"""Abstraction for different trigger configuration formats."""
|
||||
|
||||
@@ -60,15 +60,6 @@ async def test_climate_conditions_gated_by_labs_flag(
|
||||
await assert_condition_gated_by_labs_flag(hass, caplog, condition)
|
||||
|
||||
|
||||
_HUMIDITY_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 50}}}
|
||||
_TEMPERATURE_THRESHOLD = {
|
||||
"threshold": {
|
||||
"type": "above",
|
||||
"value": {"number": 20, "unit_of_measurement": UnitOfTemperature.CELSIUS},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("condition_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
@@ -78,9 +69,6 @@ _TEMPERATURE_THRESHOLD = {
|
||||
("climate.is_cooling", {}, True, True),
|
||||
("climate.is_drying", {}, True, True),
|
||||
("climate.is_heating", {}, True, True),
|
||||
("climate.is_hvac_mode", {"hvac_mode": [HVACMode.HEAT]}, True, True),
|
||||
("climate.target_humidity", _HUMIDITY_THRESHOLD, True, True),
|
||||
("climate.target_temperature", _TEMPERATURE_THRESHOLD, True, True),
|
||||
],
|
||||
)
|
||||
async def test_climate_condition_options_validation(
|
||||
|
||||
@@ -67,16 +67,6 @@ async def test_climate_triggers_gated_by_labs_flag(
|
||||
await assert_trigger_gated_by_labs_flag(hass, caplog, trigger_key)
|
||||
|
||||
|
||||
_CHANGED_THRESHOLD = {"threshold": {"type": "any"}}
|
||||
_HUMIDITY_CROSSED_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 50}}}
|
||||
_TEMPERATURE_CROSSED_THRESHOLD = {
|
||||
"threshold": {
|
||||
"type": "above",
|
||||
"value": {"number": 20, "unit_of_measurement": UnitOfTemperature.CELSIUS},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("trigger_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
@@ -86,21 +76,6 @@ _TEMPERATURE_CROSSED_THRESHOLD = {
|
||||
("climate.started_heating", {}, True, True),
|
||||
("climate.turned_off", {}, True, True),
|
||||
("climate.turned_on", {}, True, True),
|
||||
("climate.hvac_mode_changed", {"hvac_mode": [HVACMode.HEAT]}, True, True),
|
||||
("climate.target_humidity_changed", _CHANGED_THRESHOLD, False, False),
|
||||
(
|
||||
"climate.target_humidity_crossed_threshold",
|
||||
_HUMIDITY_CROSSED_THRESHOLD,
|
||||
True,
|
||||
True,
|
||||
),
|
||||
("climate.target_temperature_changed", _CHANGED_THRESHOLD, False, False),
|
||||
(
|
||||
"climate.target_temperature_crossed_threshold",
|
||||
_TEMPERATURE_CROSSED_THRESHOLD,
|
||||
True,
|
||||
True,
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_climate_trigger_options_validation(
|
||||
|
||||
@@ -25,17 +25,11 @@ async def target_counters(hass: HomeAssistant) -> dict[str, list[str]]:
|
||||
return await target_entities(hass, "counter")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"condition",
|
||||
[
|
||||
"counter.is_value",
|
||||
],
|
||||
)
|
||||
async def test_counter_conditions_gated_by_labs_flag(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, condition: str
|
||||
async def test_counter_condition_gated_by_labs_flag(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test the counter conditions are gated by the labs flag."""
|
||||
await assert_condition_gated_by_labs_flag(hass, caplog, condition)
|
||||
"""Test the counter condition is gated by the labs flag."""
|
||||
await assert_condition_gated_by_labs_flag(hass, caplog, "counter.is_value")
|
||||
|
||||
|
||||
_PLAIN_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 50}}}
|
||||
|
||||
@@ -39,16 +39,9 @@ async def target_covers(hass: HomeAssistant) -> dict[str, list[str]]:
|
||||
@pytest.mark.parametrize(
|
||||
"condition",
|
||||
[
|
||||
"cover.awning_is_closed",
|
||||
"cover.awning_is_open",
|
||||
"cover.blind_is_closed",
|
||||
"cover.blind_is_open",
|
||||
"cover.curtain_is_closed",
|
||||
"cover.curtain_is_open",
|
||||
"cover.shade_is_closed",
|
||||
"cover.shade_is_open",
|
||||
"cover.shutter_is_closed",
|
||||
"cover.shutter_is_open",
|
||||
condition
|
||||
for _, is_open, is_closed in DEVICE_CLASS_CONDITIONS
|
||||
for condition in (is_open, is_closed)
|
||||
],
|
||||
)
|
||||
async def test_cover_conditions_gated_by_labs_flag(
|
||||
|
||||
@@ -38,16 +38,9 @@ async def target_covers(hass: HomeAssistant) -> dict[str, list[str]]:
|
||||
@pytest.mark.parametrize(
|
||||
"trigger_key",
|
||||
[
|
||||
"cover.awning_closed",
|
||||
"cover.awning_opened",
|
||||
"cover.blind_closed",
|
||||
"cover.blind_opened",
|
||||
"cover.curtain_closed",
|
||||
"cover.curtain_opened",
|
||||
"cover.shade_closed",
|
||||
"cover.shade_opened",
|
||||
"cover.shutter_closed",
|
||||
"cover.shutter_opened",
|
||||
trigger
|
||||
for _, opened, closed in DEVICE_CLASS_TRIGGERS
|
||||
for trigger in (opened, closed)
|
||||
],
|
||||
)
|
||||
async def test_cover_triggers_gated_by_labs_flag(
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
"""The tests for the hassio component."""
|
||||
|
||||
from contextlib import AbstractContextManager, ExitStack as DefaultContext
|
||||
from http import HTTPStatus
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from aiohttp.test_utils import TestClient
|
||||
from aiohttp.web_exceptions import HTTPUnauthorized
|
||||
import pytest
|
||||
|
||||
from homeassistant.auth.providers.homeassistant import InvalidAuth
|
||||
from homeassistant.components.hassio.auth import HassIOBaseAuth
|
||||
from homeassistant.components.hassio.const import DATA_CONFIG_STORE
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
async def test_auth_success(hassio_client_supervisor: TestClient) -> None:
|
||||
@@ -168,45 +162,6 @@ async def test_password_fails_no_auth(hassio_noauth_client: TestClient) -> None:
|
||||
assert resp.status == HTTPStatus.UNAUTHORIZED
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("peername", "unix_socket", "expectation"),
|
||||
[
|
||||
# Unix socket transports report an empty string for peername. Before
|
||||
# the fix this raised IndexError on `peername[0]`.
|
||||
("", True, DefaultContext()),
|
||||
# Defensive: a TCP transport with no peername at all should be
|
||||
# rejected, not crash.
|
||||
(None, False, pytest.raises(HTTPUnauthorized)),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("hassio_stubs")
|
||||
async def test_check_access_unix_socket_or_missing_peername(
|
||||
hass: HomeAssistant,
|
||||
peername: str | None,
|
||||
unix_socket: bool,
|
||||
expectation: AbstractContextManager,
|
||||
) -> None:
|
||||
"""Test _check_access handles Unix socket requests and missing peername."""
|
||||
hassio_user_id = hass.data[DATA_CONFIG_STORE].data.hassio_user
|
||||
assert hassio_user_id is not None
|
||||
user = await hass.auth.async_get_user(hassio_user_id)
|
||||
assert user is not None
|
||||
|
||||
auth_view = HassIOBaseAuth(hass, user)
|
||||
request = MagicMock()
|
||||
request.transport.get_extra_info.return_value = peername
|
||||
request.__getitem__.return_value = user
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.hassio.auth.is_supervisor_unix_socket_request",
|
||||
return_value=unix_socket,
|
||||
),
|
||||
expectation,
|
||||
):
|
||||
auth_view._check_access(request)
|
||||
|
||||
|
||||
async def test_password_no_user(hassio_client_supervisor: TestClient) -> None:
|
||||
"""Test changing password for invalid user."""
|
||||
resp = await hassio_client_supervisor.post(
|
||||
|
||||
@@ -64,9 +64,6 @@ async def test_humidifier_conditions_gated_by_labs_flag(
|
||||
await assert_condition_gated_by_labs_flag(hass, caplog, condition)
|
||||
|
||||
|
||||
_HUMIDITY_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 50}}}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("condition_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
@@ -75,8 +72,6 @@ _HUMIDITY_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 50}}}
|
||||
("humidifier.is_on", {}, True, True),
|
||||
("humidifier.is_drying", {}, True, True),
|
||||
("humidifier.is_humidifying", {}, True, True),
|
||||
("humidifier.is_mode", {"mode": ["normal"]}, True, True),
|
||||
("humidifier.is_target_humidity", _HUMIDITY_THRESHOLD, True, True),
|
||||
],
|
||||
)
|
||||
async def test_humidifier_condition_options_validation(
|
||||
|
||||
@@ -68,7 +68,6 @@ async def test_humidifier_triggers_gated_by_labs_flag(
|
||||
("humidifier.started_humidifying", {}, True, True),
|
||||
("humidifier.turned_on", {}, True, True),
|
||||
("humidifier.turned_off", {}, True, True),
|
||||
("humidifier.mode_changed", {"mode": ["normal"]}, True, True),
|
||||
],
|
||||
)
|
||||
async def test_humidifier_trigger_options_validation(
|
||||
|
||||
@@ -56,16 +56,12 @@ async def test_illuminance_conditions_gated_by_labs_flag(
|
||||
await assert_condition_gated_by_labs_flag(hass, caplog, condition)
|
||||
|
||||
|
||||
_ILLUMINANCE_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 50}}}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("condition_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
[
|
||||
("illuminance.is_detected", {}, True, True),
|
||||
("illuminance.is_not_detected", {}, True, True),
|
||||
("illuminance.is_value", _ILLUMINANCE_THRESHOLD, True, True),
|
||||
],
|
||||
)
|
||||
async def test_illuminance_condition_options_validation(
|
||||
|
||||
@@ -58,18 +58,12 @@ async def test_illuminance_triggers_gated_by_labs_flag(
|
||||
await assert_trigger_gated_by_labs_flag(hass, caplog, trigger_key)
|
||||
|
||||
|
||||
_CHANGED_THRESHOLD = {"threshold": {"type": "any"}}
|
||||
_CROSSED_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 50}}}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("trigger_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
[
|
||||
("illuminance.detected", {}, True, True),
|
||||
("illuminance.cleared", {}, True, True),
|
||||
("illuminance.changed", _CHANGED_THRESHOLD, False, False),
|
||||
("illuminance.crossed_threshold", _CROSSED_THRESHOLD, True, True),
|
||||
],
|
||||
)
|
||||
async def test_illuminance_trigger_options_validation(
|
||||
|
||||
@@ -30,8 +30,6 @@ MOCK_CONFIG = {
|
||||
"folder": "INBOX",
|
||||
"search": "UnSeen UnDeleted",
|
||||
"event_message_data": ["text", "headers"],
|
||||
"ssl_cipher_list": "python_default",
|
||||
"verify_ssl": True,
|
||||
}
|
||||
|
||||
MOCK_OPTIONS = {
|
||||
@@ -303,7 +301,7 @@ async def test_reauth_failed_conn_error(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
async def test_options_form(hass: HomeAssistant) -> None:
|
||||
"""Test the options form."""
|
||||
"""Test we show the options form."""
|
||||
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG)
|
||||
entry.add_to_hass(hass)
|
||||
@@ -383,7 +381,7 @@ async def test_key_options_in_options_form(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("test_options", "assert_result"),
|
||||
("advanced_options", "assert_result"),
|
||||
[
|
||||
({"max_message_size": 8192}, FlowResultType.CREATE_ENTRY),
|
||||
({"max_message_size": 1024}, FlowResultType.FORM),
|
||||
@@ -409,12 +407,12 @@ async def test_key_options_in_options_form(hass: HomeAssistant) -> None:
|
||||
"enable_push_false",
|
||||
],
|
||||
)
|
||||
async def test_options_flow_when_connection_fails(
|
||||
async def test_advanced_options_form(
|
||||
hass: HomeAssistant,
|
||||
test_options: dict[str, str],
|
||||
advanced_options: dict[str, str],
|
||||
assert_result: FlowResultType,
|
||||
) -> None:
|
||||
"""Test the options flow when the connection fails."""
|
||||
"""Test we show the advanced options."""
|
||||
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG)
|
||||
entry.add_to_hass(hass)
|
||||
@@ -422,14 +420,14 @@ async def test_options_flow_when_connection_fails(
|
||||
|
||||
result = await hass.config_entries.options.async_init(
|
||||
entry.entry_id,
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
context={"source": config_entries.SOURCE_USER, "show_advanced_options": True},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
new_config = MOCK_OPTIONS.copy()
|
||||
new_config.update(test_options)
|
||||
new_config.update(advanced_options)
|
||||
|
||||
try:
|
||||
with patch(
|
||||
@@ -464,7 +462,7 @@ async def test_config_flow_with_cipherlist_and_ssl_verify(
|
||||
config["verify_ssl"] = verify_ssl
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
context={"source": config_entries.SOURCE_USER, "show_advanced_options": True},
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] is None
|
||||
@@ -496,7 +494,7 @@ async def test_config_flow_with_event_message_data(
|
||||
config["event_message_data"] = event_message_data
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
context={"source": config_entries.SOURCE_USER, "show_advanced_options": False},
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] is None
|
||||
@@ -519,14 +517,16 @@ async def test_config_flow_with_event_message_data(
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_cipher_settings_in_config_flow(
|
||||
async def test_config_flow_from_with_advanced_settings(
|
||||
hass: HomeAssistant, mock_setup_entry: AsyncMock
|
||||
) -> None:
|
||||
"""Test cipher settings in config flow."""
|
||||
"""Test if advanced settings show correctly."""
|
||||
config = MOCK_CONFIG.copy()
|
||||
config["ssl_cipher_list"] = "python_default"
|
||||
config["verify_ssl"] = True
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
context={"source": config_entries.SOURCE_USER, "show_advanced_options": True},
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] is None
|
||||
|
||||
@@ -72,8 +72,6 @@ async def test_entry_diagnostics(
|
||||
],
|
||||
"search": "UnSeen UnDeleted",
|
||||
"custom_event_data_template": "{{ 4 * 4 }}",
|
||||
"ssl_cipher_list": "python_default",
|
||||
"verify_ssl": True,
|
||||
}
|
||||
expected_event_data = {
|
||||
"date": "2023-03-24T13:52:00+01:00",
|
||||
|
||||
@@ -47,16 +47,12 @@ async def test_light_conditions_gated_by_labs_flag(
|
||||
await assert_condition_gated_by_labs_flag(hass, caplog, condition)
|
||||
|
||||
|
||||
_BRIGHTNESS_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 50}}}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("condition_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
[
|
||||
("light.is_off", {}, True, True),
|
||||
("light.is_on", {}, True, True),
|
||||
("light.is_brightness", _BRIGHTNESS_THRESHOLD, True, True),
|
||||
],
|
||||
)
|
||||
async def test_light_condition_options_validation(
|
||||
|
||||
@@ -53,25 +53,12 @@ async def test_light_triggers_gated_by_labs_flag(
|
||||
await assert_trigger_gated_by_labs_flag(hass, caplog, trigger_key)
|
||||
|
||||
|
||||
_CHANGED_THRESHOLD = {"threshold": {"type": "any"}}
|
||||
_BRIGHTNESS_CROSSED_THRESHOLD = {
|
||||
"threshold": {"type": "above", "value": {"number": 50}}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("trigger_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
[
|
||||
("light.turned_on", {}, True, True),
|
||||
("light.turned_off", {}, True, True),
|
||||
("light.brightness_changed", _CHANGED_THRESHOLD, False, False),
|
||||
(
|
||||
"light.brightness_crossed_threshold",
|
||||
_BRIGHTNESS_CROSSED_THRESHOLD,
|
||||
True,
|
||||
True,
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_light_trigger_options_validation(
|
||||
|
||||
@@ -4,6 +4,7 @@ import asyncio
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components import mill
|
||||
from homeassistant.components.mill.coordinator import MillDataUpdateCoordinator
|
||||
from homeassistant.components.recorder import Recorder
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -156,7 +157,9 @@ async def test_unload_entry(recorder_mock: Recorder, hass: HomeAssistant) -> Non
|
||||
):
|
||||
assert await async_setup_component(hass, "mill", {})
|
||||
|
||||
assert isinstance(entry.runtime_data, MillDataUpdateCoordinator)
|
||||
|
||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
assert unload_entry.call_count == 3
|
||||
assert entry.entry_id not in hass.data[mill.DOMAIN]
|
||||
assert not hasattr(entry, "runtime_data")
|
||||
|
||||
@@ -56,16 +56,12 @@ async def test_moisture_conditions_gated_by_labs_flag(
|
||||
await assert_condition_gated_by_labs_flag(hass, caplog, condition)
|
||||
|
||||
|
||||
_MOISTURE_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 50}}}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("condition_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
[
|
||||
("moisture.is_detected", {}, True, True),
|
||||
("moisture.is_not_detected", {}, True, True),
|
||||
("moisture.is_value", _MOISTURE_THRESHOLD, True, True),
|
||||
],
|
||||
)
|
||||
async def test_moisture_condition_options_validation(
|
||||
|
||||
@@ -58,18 +58,12 @@ async def test_moisture_triggers_gated_by_labs_flag(
|
||||
await assert_trigger_gated_by_labs_flag(hass, caplog, trigger_key)
|
||||
|
||||
|
||||
_CHANGED_THRESHOLD = {"threshold": {"type": "any"}}
|
||||
_CROSSED_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 50}}}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("trigger_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
[
|
||||
("moisture.detected", {}, True, True),
|
||||
("moisture.cleared", {}, True, True),
|
||||
("moisture.changed", _CHANGED_THRESHOLD, False, False),
|
||||
("moisture.crossed_threshold", _CROSSED_THRESHOLD, True, True),
|
||||
],
|
||||
)
|
||||
async def test_moisture_trigger_options_validation(
|
||||
|
||||
@@ -88,7 +88,9 @@ async def test_mqtt_await_ack_at_disconnect(hass: HomeAssistant) -> None:
|
||||
mid = 100
|
||||
rc = 0
|
||||
|
||||
with patch("homeassistant.components.mqtt.client.AsyncMQTTClient") as mock_client:
|
||||
with patch(
|
||||
"homeassistant.components.mqtt.async_client.AsyncMQTTClient"
|
||||
) as mock_client:
|
||||
mqtt_client = mock_client.return_value
|
||||
mqtt_client.connect = MagicMock(
|
||||
return_value=0,
|
||||
@@ -1303,7 +1305,9 @@ async def test_publish_error(
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
# simulate an Out of memory error
|
||||
with patch("homeassistant.components.mqtt.client.AsyncMQTTClient") as mock_client:
|
||||
with patch(
|
||||
"homeassistant.components.mqtt.async_client.AsyncMQTTClient"
|
||||
) as mock_client:
|
||||
mock_client().connect = lambda **kwargs: 1
|
||||
mock_client().publish().rc = 1
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
@@ -1400,7 +1404,9 @@ async def test_setup_mqtt_client_clean_session_and_protocol(
|
||||
clean_session: bool | None,
|
||||
) -> None:
|
||||
"""Test MQTT client clean_session and protocol setup."""
|
||||
with patch("homeassistant.components.mqtt.client.AsyncMQTTClient") as mock_client:
|
||||
with patch(
|
||||
"homeassistant.components.mqtt.async_client.AsyncMQTTClient"
|
||||
) as mock_client:
|
||||
await mqtt_mock_entry()
|
||||
|
||||
# check if clean_session was correctly
|
||||
@@ -1464,7 +1470,9 @@ async def test_handle_mqtt_timeout_on_callback(
|
||||
mid = 102
|
||||
rc = 0
|
||||
|
||||
with patch("homeassistant.components.mqtt.client.AsyncMQTTClient") as mock_client:
|
||||
with patch(
|
||||
"homeassistant.components.mqtt.async_client.AsyncMQTTClient"
|
||||
) as mock_client:
|
||||
|
||||
def _mock_ack(topic: str, qos: int = 0) -> tuple[int, int]:
|
||||
# Handle ACK for subscribe normally
|
||||
@@ -1531,7 +1539,9 @@ async def test_setup_raises_config_entry_not_ready_if_no_connect_broker(
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
with patch("homeassistant.components.mqtt.client.AsyncMQTTClient") as mock_client:
|
||||
with patch(
|
||||
"homeassistant.components.mqtt.async_client.AsyncMQTTClient"
|
||||
) as mock_client:
|
||||
mock_client().connect = MagicMock(side_effect=exception)
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
@@ -1566,7 +1576,9 @@ async def test_setup_uses_certificate_on_certificate_set_to_auto_and_insecure(
|
||||
def mock_tls_insecure_set(insecure_param) -> None:
|
||||
insecure_check["insecure"] = insecure_param
|
||||
|
||||
with patch("homeassistant.components.mqtt.client.AsyncMQTTClient") as mock_client:
|
||||
with patch(
|
||||
"homeassistant.components.mqtt.async_client.AsyncMQTTClient"
|
||||
) as mock_client:
|
||||
mock_client().tls_set = mock_tls_set
|
||||
mock_client().tls_insecure_set = mock_tls_insecure_set
|
||||
await mqtt_mock_entry()
|
||||
@@ -1606,7 +1618,7 @@ async def test_client_id_is_set(
|
||||
) -> None:
|
||||
"""Test setup defaults for tls."""
|
||||
with patch(
|
||||
"homeassistant.components.mqtt.client.AsyncMQTTClient"
|
||||
"homeassistant.components.mqtt.async_client.AsyncMQTTClient"
|
||||
) as async_client_mock:
|
||||
await mqtt_mock_entry()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -254,7 +254,9 @@ def mock_try_connection_success() -> Generator[MqttMockPahoClient]:
|
||||
mock_client().on_unsubscribe(mock_client, 0, mid, [MockMqttReasonCode()], None)
|
||||
return (0, mid)
|
||||
|
||||
with patch("homeassistant.components.mqtt.client.AsyncMQTTClient") as mock_client:
|
||||
with patch(
|
||||
"homeassistant.components.mqtt.async_client.AsyncMQTTClient"
|
||||
) as mock_client:
|
||||
mock_client().loop_start = loop_start
|
||||
mock_client().subscribe = _subscribe
|
||||
mock_client().unsubscribe = _unsubscribe
|
||||
@@ -268,7 +270,9 @@ def mock_try_connection_time_out() -> Generator[MagicMock]:
|
||||
|
||||
# Patch prevent waiting 5 sec for a timeout
|
||||
with (
|
||||
patch("homeassistant.components.mqtt.client.AsyncMQTTClient") as mock_client,
|
||||
patch(
|
||||
"homeassistant.components.mqtt.async_client.AsyncMQTTClient"
|
||||
) as mock_client,
|
||||
patch("homeassistant.components.mqtt.config_flow.MQTT_TIMEOUT", 0),
|
||||
):
|
||||
mock_client().loop_start = lambda *args: 1
|
||||
|
||||
@@ -10,7 +10,6 @@ from typing import Any, TypedDict
|
||||
from unittest.mock import ANY, MagicMock, Mock, mock_open, patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
from paho.mqtt.client import MQTTMessage
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
@@ -701,6 +700,11 @@ async def test_receiving_message_with_non_utf8_topic_gets_logged(
|
||||
await mqtt_mock_entry()
|
||||
await mqtt.async_subscribe(hass, "test-topic", record_calls)
|
||||
|
||||
# Local import to avoid processing MQTT modules when running a testcase
|
||||
# which does not use MQTT.
|
||||
|
||||
from paho.mqtt.client import MQTTMessage # noqa: PLC0415
|
||||
|
||||
from homeassistant.components.mqtt.models import MqttData # noqa: PLC0415
|
||||
|
||||
msg = MQTTMessage(topic=b"tasmota/discovery/18FE34E0B760\xcc\x02")
|
||||
@@ -1906,7 +1910,7 @@ async def test_link_config_entry(
|
||||
assert _check_entities() == 2
|
||||
|
||||
# reload entry and assert again
|
||||
with patch("homeassistant.components.mqtt.client.AsyncMQTTClient"):
|
||||
with patch("homeassistant.components.mqtt.async_client.AsyncMQTTClient"):
|
||||
await hass.config_entries.async_reload(mqtt_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@@ -39,15 +39,11 @@ async def test_todo_conditions_gated_by_labs_flag(
|
||||
await assert_condition_gated_by_labs_flag(hass, caplog, condition)
|
||||
|
||||
|
||||
_TODO_THRESHOLD = {"threshold": {"type": "above", "value": {"number": 5}}}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("condition_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
[
|
||||
("todo.all_completed", {}, True, True),
|
||||
("todo.incomplete", _TODO_THRESHOLD, True, True),
|
||||
],
|
||||
)
|
||||
async def test_todo_condition_options_validation(
|
||||
|
||||
@@ -36,10 +36,6 @@ from homeassistant.setup import async_setup_component
|
||||
from . import MockTodoListEntity, create_mock_platform
|
||||
|
||||
from tests.common import async_mock_service, mock_device_registry
|
||||
from tests.components.common import (
|
||||
assert_trigger_gated_by_labs_flag,
|
||||
assert_trigger_options_supported,
|
||||
)
|
||||
|
||||
TODO_ENTITY_ID1 = "todo.list_one"
|
||||
TODO_ENTITY_ID2 = "todo.list_two"
|
||||
@@ -126,47 +122,6 @@ def service_calls(hass: HomeAssistant) -> list[ServiceCall]:
|
||||
return async_mock_service(hass, "test", "item_added")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"trigger_key",
|
||||
[
|
||||
"todo.item_added",
|
||||
"todo.item_completed",
|
||||
"todo.item_removed",
|
||||
],
|
||||
)
|
||||
async def test_todo_triggers_gated_by_labs_flag(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, trigger_key: str
|
||||
) -> None:
|
||||
"""Test the todo triggers are gated by the labs flag."""
|
||||
await assert_trigger_gated_by_labs_flag(hass, caplog, trigger_key)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("trigger_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
[
|
||||
("todo.item_added", None, False, False),
|
||||
("todo.item_completed", None, False, False),
|
||||
("todo.item_removed", None, False, False),
|
||||
],
|
||||
)
|
||||
async def test_todo_trigger_options_validation(
|
||||
hass: HomeAssistant,
|
||||
trigger_key: str,
|
||||
base_options: dict[str, Any] | None,
|
||||
supports_behavior: bool,
|
||||
supports_duration: bool,
|
||||
) -> None:
|
||||
"""Test that todo triggers support the expected options."""
|
||||
await assert_trigger_options_supported(
|
||||
hass,
|
||||
trigger_key,
|
||||
base_options,
|
||||
supports_behavior=supports_behavior,
|
||||
supports_duration=supports_duration,
|
||||
)
|
||||
|
||||
|
||||
def _assert_service_calls(
|
||||
service_calls: list[ServiceCall], expected_calls: list[dict[str, Any]]
|
||||
) -> None:
|
||||
|
||||
@@ -72,27 +72,12 @@ async def test_water_heater_conditions_gated_by_labs_flag(
|
||||
await assert_condition_gated_by_labs_flag(hass, caplog, condition)
|
||||
|
||||
|
||||
_TEMPERATURE_THRESHOLD = {
|
||||
"threshold": {
|
||||
"type": "above",
|
||||
"value": {"number": 20, "unit_of_measurement": UnitOfTemperature.CELSIUS},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("condition_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
[
|
||||
("water_heater.is_off", {}, True, True),
|
||||
("water_heater.is_on", {}, True, True),
|
||||
(
|
||||
"water_heater.is_operation_mode",
|
||||
{"operation_mode": [STATE_ECO]},
|
||||
True,
|
||||
True,
|
||||
),
|
||||
("water_heater.is_target_temperature", _TEMPERATURE_THRESHOLD, True, True),
|
||||
],
|
||||
)
|
||||
async def test_water_heater_condition_options_validation(
|
||||
|
||||
@@ -65,39 +65,12 @@ async def test_water_heater_triggers_gated_by_labs_flag(
|
||||
await assert_trigger_gated_by_labs_flag(hass, caplog, trigger_key)
|
||||
|
||||
|
||||
_CHANGED_THRESHOLD = {"threshold": {"type": "any"}}
|
||||
_CROSSED_THRESHOLD = {
|
||||
"threshold": {
|
||||
"type": "above",
|
||||
"value": {"number": 20, "unit_of_measurement": UnitOfTemperature.CELSIUS},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
("trigger_key", "base_options", "supports_behavior", "supports_duration"),
|
||||
[
|
||||
("water_heater.turned_off", {}, True, True),
|
||||
("water_heater.turned_on", {}, True, True),
|
||||
(
|
||||
"water_heater.operation_mode_changed",
|
||||
{"operation_mode": [STATE_ECO]},
|
||||
True,
|
||||
True,
|
||||
),
|
||||
(
|
||||
"water_heater.target_temperature_changed",
|
||||
_CHANGED_THRESHOLD,
|
||||
False,
|
||||
False,
|
||||
),
|
||||
(
|
||||
"water_heater.target_temperature_crossed_threshold",
|
||||
_CROSSED_THRESHOLD,
|
||||
True,
|
||||
True,
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_water_heater_trigger_options_validation(
|
||||
|
||||
+3
-1
@@ -1057,7 +1057,9 @@ def mqtt_client_mock(hass: HomeAssistant) -> Generator[MqttMockPahoClient]:
|
||||
self.mid = mid
|
||||
self.rc = 0
|
||||
|
||||
with patch("homeassistant.components.mqtt.client.AsyncMQTTClient") as mock_client:
|
||||
with patch(
|
||||
"homeassistant.components.mqtt.async_client.AsyncMQTTClient"
|
||||
) as mock_client:
|
||||
# The below use a call_soon for the on_publish/on_subscribe/on_unsubscribe
|
||||
# callbacks to simulate the behavior of the real MQTT client which will
|
||||
# not be synchronous.
|
||||
|
||||
@@ -57,7 +57,6 @@ from homeassistant.helpers.trigger import (
|
||||
EntityNumericalStateCrossedThresholdTriggerWithUnitBase,
|
||||
EntityTriggerBase,
|
||||
PluggableAction,
|
||||
StatelessEntityTriggerBase,
|
||||
Trigger,
|
||||
TriggerActionRunner,
|
||||
TriggerConfig,
|
||||
@@ -3099,88 +3098,6 @@ async def test_make_entity_origin_state_trigger(
|
||||
assert not trig.is_valid_state(from_state)
|
||||
|
||||
|
||||
class _ActivatedTrigger(StatelessEntityTriggerBase):
|
||||
"""Test trigger leaf for StatelessEntityTriggerBase."""
|
||||
|
||||
_domain_specs = {"test": DomainSpec()}
|
||||
|
||||
|
||||
async def _arm_activated_trigger(
|
||||
hass: HomeAssistant,
|
||||
entity_ids: list[str],
|
||||
calls: list[dict[str, Any]],
|
||||
) -> CALLBACK_TYPE:
|
||||
"""Set up _ActivatedTrigger via async_initialize_triggers."""
|
||||
|
||||
async def async_get_triggers(
|
||||
hass: HomeAssistant,
|
||||
) -> dict[str, type[Trigger]]:
|
||||
return {"activated": _ActivatedTrigger}
|
||||
|
||||
mock_integration(hass, MockModule("test"))
|
||||
mock_platform(hass, "test.trigger", Mock(async_get_triggers=async_get_triggers))
|
||||
|
||||
trigger_config = {
|
||||
CONF_PLATFORM: "test.activated",
|
||||
CONF_TARGET: {CONF_ENTITY_ID: entity_ids},
|
||||
}
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@callback
|
||||
def action(run_variables: dict[str, Any], context: Context | None = None) -> None:
|
||||
calls.append(run_variables["trigger"])
|
||||
|
||||
validated_config = await async_validate_trigger_config(hass, [trigger_config])
|
||||
return await async_initialize_triggers(
|
||||
hass,
|
||||
validated_config,
|
||||
action,
|
||||
domain="test",
|
||||
name="test_activated",
|
||||
log_cb=log.log,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("initial_state", "sequence", "expected_calls"),
|
||||
[
|
||||
(STATE_UNKNOWN, ["2026-05-06T12:00:00+00:00", "2026-05-06T12:00:01+00:00"], 2),
|
||||
(STATE_UNAVAILABLE, ["2026-05-06T12:00:00+00:00"], 0),
|
||||
("2026-05-06T12:00:00+00:00", [STATE_UNAVAILABLE], 0),
|
||||
("2026-05-06T12:00:00+00:00", [STATE_UNKNOWN], 0),
|
||||
("2026-05-06T12:00:00+00:00", ["2026-05-06T12:00:00+00:00"], 0),
|
||||
],
|
||||
)
|
||||
async def test_stateless_entity_trigger(
|
||||
hass: HomeAssistant,
|
||||
initial_state: str,
|
||||
sequence: list[str],
|
||||
expected_calls: int,
|
||||
) -> None:
|
||||
"""Test StatelessEntityTriggerBase end-to-end via a mocked platform.
|
||||
|
||||
StatelessEntityTriggerBase covers entities (buttons, scenes,
|
||||
doorbells, events) that have no meaningful prior state — STATE_UNKNOWN
|
||||
must be a valid origin so the first activation after startup fires,
|
||||
but UNAVAILABLE/UNKNOWN are never valid target states.
|
||||
"""
|
||||
entity_id = "test.bell"
|
||||
hass.states.async_set(entity_id, initial_state)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
calls: list[dict[str, Any]] = []
|
||||
unsub = await _arm_activated_trigger(hass, [entity_id], calls)
|
||||
|
||||
for state in sequence:
|
||||
hass.states.async_set(entity_id, state)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == expected_calls
|
||||
|
||||
unsub()
|
||||
|
||||
|
||||
class _OffToOnTrigger(EntityTriggerBase):
|
||||
"""Test trigger that fires when state becomes 'on'."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user