diff --git a/homeassistant/components/accuweather/weather.py b/homeassistant/components/accuweather/weather.py index c97cc44aea3..00726f6db38 100644 --- a/homeassistant/components/accuweather/weather.py +++ b/homeassistant/components/accuweather/weather.py @@ -62,6 +62,9 @@ class AccuWeatherEntity(CoordinatorEntity, WeatherEntity): """Initialize.""" super().__init__(coordinator) self._unit_system = API_METRIC if coordinator.is_metric else API_IMPERIAL + self._attr_wind_speed_unit = self.coordinator.data["Wind"]["Speed"][ + self._unit_system + ]["Unit"] self._attr_name = name self._attr_unique_id = coordinator.location_key self._attr_temperature_unit = ( diff --git a/homeassistant/components/dnsip/config_flow.py b/homeassistant/components/dnsip/config_flow.py index bedcc5f821c..2db0034b697 100644 --- a/homeassistant/components/dnsip/config_flow.py +++ b/homeassistant/components/dnsip/config_flow.py @@ -33,6 +33,13 @@ DATA_SCHEMA = vol.Schema( vol.Required(CONF_HOSTNAME, default=DEFAULT_HOSTNAME): cv.string, } ) +DATA_SCHEMA_ADV = vol.Schema( + { + vol.Required(CONF_HOSTNAME, default=DEFAULT_HOSTNAME): cv.string, + vol.Optional(CONF_RESOLVER, default=DEFAULT_RESOLVER): cv.string, + vol.Optional(CONF_RESOLVER_IPV6, default=DEFAULT_RESOLVER_IPV6): cv.string, + } +) async def async_validate_hostname( @@ -94,8 +101,8 @@ class DnsIPConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): hostname = user_input[CONF_HOSTNAME] name = DEFAULT_NAME if hostname == DEFAULT_HOSTNAME else hostname - resolver = DEFAULT_RESOLVER - resolver_ipv6 = DEFAULT_RESOLVER_IPV6 + resolver = user_input.get(CONF_RESOLVER, DEFAULT_RESOLVER) + resolver_ipv6 = user_input.get(CONF_RESOLVER_IPV6, DEFAULT_RESOLVER_IPV6) validate = await async_validate_hostname(hostname, resolver, resolver_ipv6) @@ -119,6 +126,12 @@ class DnsIPConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): }, ) + if self.show_advanced_options is True: + return self.async_show_form( + step_id="user", + data_schema=DATA_SCHEMA_ADV, + errors=errors, + ) return self.async_show_form( step_id="user", data_schema=DATA_SCHEMA, diff --git a/homeassistant/components/dnsip/strings.json b/homeassistant/components/dnsip/strings.json index 06672e6fb68..cd95c9db27f 100644 --- a/homeassistant/components/dnsip/strings.json +++ b/homeassistant/components/dnsip/strings.json @@ -3,7 +3,9 @@ "step": { "user": { "data": { - "hostname": "The hostname for which to perform the DNS query" + "hostname": "The hostname for which to perform the DNS query", + "resolver": "Resolver for IPV4 lookup", + "resolver_ipv6": "Resolver for IPV6 lookup" } } }, diff --git a/homeassistant/components/dnsip/translations/en.json b/homeassistant/components/dnsip/translations/en.json index 7b2e2f9e6c7..2c773375860 100644 --- a/homeassistant/components/dnsip/translations/en.json +++ b/homeassistant/components/dnsip/translations/en.json @@ -6,7 +6,9 @@ "step": { "user": { "data": { - "hostname": "The hostname for which to perform the DNS query" + "hostname": "The hostname for which to perform the DNS query", + "resolver": "Resolver for IPV4 lookup", + "resolver_ipv6": "Resolver for IPV6 lookup" } } } diff --git a/homeassistant/components/flunearyou/__init__.py b/homeassistant/components/flunearyou/__init__.py index bb07e9ccc73..9a2ef2d4465 100644 --- a/homeassistant/components/flunearyou/__init__.py +++ b/homeassistant/components/flunearyou/__init__.py @@ -59,7 +59,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: update_interval=DEFAULT_UPDATE_INTERVAL, update_method=partial(async_update, api_category), ) - data_init_tasks.append(coordinator.async_refresh()) + data_init_tasks.append(coordinator.async_config_entry_first_refresh()) await asyncio.gather(*data_init_tasks) hass.data.setdefault(DOMAIN, {}) diff --git a/homeassistant/components/fritz/common.py b/homeassistant/components/fritz/common.py index dede4b82c02..2cd6616f134 100644 --- a/homeassistant/components/fritz/common.py +++ b/homeassistant/components/fritz/common.py @@ -220,8 +220,8 @@ class FritzBoxTools(update_coordinator.DataUpdateCoordinator): """Update FritzboxTools data.""" try: await self.async_scan_devices() - except (FritzSecurityError, FritzConnectionException) as ex: - raise update_coordinator.UpdateFailed from ex + except FRITZ_EXCEPTIONS as ex: + raise update_coordinator.UpdateFailed(ex) from ex @property def unique_id(self) -> str: @@ -294,11 +294,19 @@ class FritzBoxTools(update_coordinator.DataUpdateCoordinator): def _get_wan_access(self, ip_address: str) -> bool | None: """Get WAN access rule for given IP address.""" - return not self.connection.call_action( - "X_AVM-DE_HostFilter:1", - "GetWANAccessByIP", - NewIPv4Address=ip_address, - ).get("NewDisallow") + try: + return not self.connection.call_action( + "X_AVM-DE_HostFilter:1", + "GetWANAccessByIP", + NewIPv4Address=ip_address, + ).get("NewDisallow") + except FRITZ_EXCEPTIONS as ex: + _LOGGER.debug( + "could not get WAN access rule for client device with IP '%s', error: %s", + ip_address, + ex, + ) + return None async def async_scan_devices(self, now: datetime | None = None) -> None: """Wrap up FritzboxTools class scan.""" @@ -566,6 +574,13 @@ class AvmWrapper(FritzBoxTools): partial(self.get_wan_dsl_interface_config) ) + async def async_get_wan_link_properties(self) -> dict[str, Any]: + """Call WANCommonInterfaceConfig service.""" + + return await self.hass.async_add_executor_job( + partial(self.get_wan_link_properties) + ) + async def async_get_port_mapping(self, con_type: str, index: int) -> dict[str, Any]: """Call GetGenericPortMappingEntry action.""" @@ -668,6 +683,13 @@ class AvmWrapper(FritzBoxTools): return self._service_call_action("WANDSLInterfaceConfig", "1", "GetInfo") + def get_wan_link_properties(self) -> dict[str, Any]: + """Call WANCommonInterfaceConfig service.""" + + return self._service_call_action( + "WANCommonInterfaceConfig", "1", "GetCommonLinkProperties" + ) + def set_wlan_configuration(self, index: int, turn_on: bool) -> dict[str, Any]: """Call SetEnable action from WLANConfiguration service.""" diff --git a/homeassistant/components/fritz/diagnostics.py b/homeassistant/components/fritz/diagnostics.py index 4305ee4d7cb..f35eca6b914 100644 --- a/homeassistant/components/fritz/diagnostics.py +++ b/homeassistant/components/fritz/diagnostics.py @@ -29,6 +29,19 @@ async def async_get_config_entry_diagnostics( "mesh_role": avm_wrapper.mesh_role, "last_update success": avm_wrapper.last_update_success, "last_exception": avm_wrapper.last_exception, + "discovered_services": list(avm_wrapper.connection.services), + "client_devices": [ + { + "connected_to": device.connected_to, + "connection_type": device.connection_type, + "hostname": device.hostname, + "is_connected": device.is_connected, + "last_activity": device.last_activity, + "wan_access": device.wan_access, + } + for _, device in avm_wrapper.devices.items() + ], + "wan_link_properties": await avm_wrapper.async_get_wan_link_properties(), }, } diff --git a/homeassistant/components/frontend/manifest.json b/homeassistant/components/frontend/manifest.json index 4f1e6eff032..8a9b13648e9 100644 --- a/homeassistant/components/frontend/manifest.json +++ b/homeassistant/components/frontend/manifest.json @@ -3,7 +3,7 @@ "name": "Home Assistant Frontend", "documentation": "https://www.home-assistant.io/integrations/frontend", "requirements": [ - "home-assistant-frontend==20220202.0" + "home-assistant-frontend==20220203.0" ], "dependencies": [ "api", diff --git a/homeassistant/components/mqtt/sensor.py b/homeassistant/components/mqtt/sensor.py index 59f124155d3..fa949009a0d 100644 --- a/homeassistant/components/mqtt/sensor.py +++ b/homeassistant/components/mqtt/sensor.py @@ -236,7 +236,7 @@ class MqttSensor(MqttEntity, SensorEntity, RestoreEntity): self.hass, self._value_is_expired, expiration_at ) - payload = self._template(msg.payload) + payload = self._template(msg.payload, default=self._state) if payload is not None and self.device_class in ( SensorDeviceClass.DATE, diff --git a/homeassistant/components/openuv/__init__.py b/homeassistant/components/openuv/__init__.py index 2f186af2ffe..774cd05fd9f 100644 --- a/homeassistant/components/openuv/__init__.py +++ b/homeassistant/components/openuv/__init__.py @@ -70,7 +70,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: try: await openuv.async_update() - except OpenUvError as err: + except HomeAssistantError as err: LOGGER.error("Config entry failed: %s", err) raise ConfigEntryNotReady from err diff --git a/homeassistant/components/pvoutput/manifest.json b/homeassistant/components/pvoutput/manifest.json index 378ad399ffe..042c6b9aa99 100644 --- a/homeassistant/components/pvoutput/manifest.json +++ b/homeassistant/components/pvoutput/manifest.json @@ -4,7 +4,7 @@ "documentation": "https://www.home-assistant.io/integrations/pvoutput", "config_flow": true, "codeowners": ["@fabaff", "@frenck"], - "requirements": ["pvo==0.2.0"], + "requirements": ["pvo==0.2.1"], "iot_class": "cloud_polling", "quality_scale": "platinum" } diff --git a/homeassistant/components/shodan/sensor.py b/homeassistant/components/shodan/sensor.py index 6fc73f40096..bdef681fdd2 100644 --- a/homeassistant/components/shodan/sensor.py +++ b/homeassistant/components/shodan/sensor.py @@ -67,7 +67,7 @@ class ShodanSensor(SensorEntity): def update(self) -> None: """Get the latest data and updates the states.""" data = self.data.update() - self._attr_native_value = data.details["total"] + self._attr_native_value = data["total"] class ShodanData: diff --git a/homeassistant/components/sia/const.py b/homeassistant/components/sia/const.py index 82ef6ad9429..537c106fefa 100644 --- a/homeassistant/components/sia/const.py +++ b/homeassistant/components/sia/const.py @@ -38,3 +38,4 @@ KEY_MOISTURE: Final = "moisture" KEY_POWER: Final = "power" PREVIOUS_STATE: Final = "previous_state" +AVAILABILITY_EVENT_CODE: Final = "RP" diff --git a/homeassistant/components/sia/sia_entity_base.py b/homeassistant/components/sia/sia_entity_base.py index fee3c0b2262..311728ad578 100644 --- a/homeassistant/components/sia/sia_entity_base.py +++ b/homeassistant/components/sia/sia_entity_base.py @@ -14,7 +14,7 @@ from homeassistant.helpers.event import async_call_later from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.typing import StateType -from .const import DOMAIN, SIA_EVENT, SIA_HUB_ZONE +from .const import AVAILABILITY_EVENT_CODE, DOMAIN, SIA_EVENT, SIA_HUB_ZONE from .utils import get_attr_from_sia_event, get_unavailability_interval _LOGGER = logging.getLogger(__name__) @@ -105,7 +105,7 @@ class SIABaseEntity(RestoreEntity): return self._attr_extra_state_attributes.update(get_attr_from_sia_event(sia_event)) state_changed = self.update_state(sia_event) - if state_changed: + if state_changed or sia_event.code == AVAILABILITY_EVENT_CODE: self.async_reset_availability_cb() self.async_write_ha_state() diff --git a/homeassistant/components/simplisafe/__init__.py b/homeassistant/components/simplisafe/__init__.py index a8cdb853749..a133ec6c2dc 100644 --- a/homeassistant/components/simplisafe/__init__.py +++ b/homeassistant/components/simplisafe/__init__.py @@ -820,17 +820,6 @@ class SimpliSafeEntity(CoordinatorEntity): ): return - if event.event_type in (EVENT_CONNECTION_LOST, EVENT_POWER_OUTAGE): - self._online = False - elif event.event_type in (EVENT_CONNECTION_RESTORED, EVENT_POWER_RESTORED): - self._online = True - - # It's uncertain whether SimpliSafe events will still propagate down the - # websocket when the base station is offline. Just in case, we guard against - # further action until connection is restored: - if not self._online: - return - sensor_type: str | None if event.sensor_type: sensor_type = event.sensor_type.name @@ -846,6 +835,19 @@ class SimpliSafeEntity(CoordinatorEntity): } ) + # It's unknown whether these events reach the base station (since the connection + # is lost); we include this for completeness and coverage: + if event.event_type in (EVENT_CONNECTION_LOST, EVENT_POWER_OUTAGE): + self._online = False + return + + # If the base station comes back online, set entities to available, but don't + # instruct the entities to update their state (since there won't be anything new + # until the next websocket event or REST API update: + if event.event_type in (EVENT_CONNECTION_RESTORED, EVENT_POWER_RESTORED): + self._online = True + return + self.async_update_from_websocket_event(event) self.async_write_ha_state() diff --git a/homeassistant/components/sonos/speaker.py b/homeassistant/components/sonos/speaker.py index 7777265a124..e40fe901b09 100644 --- a/homeassistant/components/sonos/speaker.py +++ b/homeassistant/components/sonos/speaker.py @@ -400,7 +400,12 @@ class SonosSpeaker: ) for result in results: if isinstance(result, Exception): - _LOGGER.debug("Unsubscribe failed for %s: %s", self.zone_name, result) + _LOGGER.debug( + "Unsubscribe failed for %s: %s", + self.zone_name, + result, + exc_info=result, + ) self._subscriptions = [] @callback @@ -701,7 +706,7 @@ class SonosSpeaker: """Handle callback for topology change event.""" if xml := event.variables.get("zone_group_state"): zgs = ET.fromstring(xml) - for vanished_device in zgs.find("VanishedDevices"): + for vanished_device in zgs.find("VanishedDevices") or []: if (reason := vanished_device.get("Reason")) != "sleeping": _LOGGER.debug( "Ignoring %s marked %s as vanished with reason: %s", diff --git a/homeassistant/components/tile/manifest.json b/homeassistant/components/tile/manifest.json index 1b30e0483f7..b8e1e14ac8b 100644 --- a/homeassistant/components/tile/manifest.json +++ b/homeassistant/components/tile/manifest.json @@ -3,7 +3,7 @@ "name": "Tile", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/tile", - "requirements": ["pytile==2022.01.0"], + "requirements": ["pytile==2022.02.0"], "codeowners": ["@bachya"], "iot_class": "cloud_polling" } diff --git a/homeassistant/components/tuya/base.py b/homeassistant/components/tuya/base.py index ac9a9c83be2..15e57f223e9 100644 --- a/homeassistant/components/tuya/base.py +++ b/homeassistant/components/tuya/base.py @@ -72,9 +72,11 @@ class IntegerTypeData: return remap_value(value, from_min, from_max, self.min, self.max, reverse) @classmethod - def from_json(cls, dpcode: DPCode, data: str) -> IntegerTypeData: + def from_json(cls, dpcode: DPCode, data: str) -> IntegerTypeData | None: """Load JSON string and return a IntegerTypeData object.""" - parsed = json.loads(data) + if not (parsed := json.loads(data)): + return None + return cls( dpcode, min=int(parsed["min"]), @@ -94,9 +96,11 @@ class EnumTypeData: range: list[str] @classmethod - def from_json(cls, dpcode: DPCode, data: str) -> EnumTypeData: + def from_json(cls, dpcode: DPCode, data: str) -> EnumTypeData | None: """Load JSON string and return a EnumTypeData object.""" - return cls(dpcode, **json.loads(data)) + if not (parsed := json.loads(data)): + return None + return cls(dpcode, **parsed) @dataclass @@ -222,17 +226,25 @@ class TuyaEntity(Entity): dptype == DPType.ENUM and getattr(self.device, key)[dpcode].type == DPType.ENUM ): - return EnumTypeData.from_json( - dpcode, getattr(self.device, key)[dpcode].values - ) + if not ( + enum_type := EnumTypeData.from_json( + dpcode, getattr(self.device, key)[dpcode].values + ) + ): + continue + return enum_type if ( dptype == DPType.INTEGER and getattr(self.device, key)[dpcode].type == DPType.INTEGER ): - return IntegerTypeData.from_json( - dpcode, getattr(self.device, key)[dpcode].values - ) + if not ( + integer_type := IntegerTypeData.from_json( + dpcode, getattr(self.device, key)[dpcode].values + ) + ): + continue + return integer_type if dptype not in (DPType.ENUM, DPType.INTEGER): return dpcode diff --git a/homeassistant/components/tuya/climate.py b/homeassistant/components/tuya/climate.py index cbb778e34b1..a97a27a7453 100644 --- a/homeassistant/components/tuya/climate.py +++ b/homeassistant/components/tuya/climate.py @@ -223,7 +223,9 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity): # Determine fan modes if enum_type := self.find_dpcode( - DPCode.FAN_SPEED_ENUM, dptype=DPType.ENUM, prefer_function=True + (DPCode.FAN_SPEED_ENUM, DPCode.WINDSPEED), + dptype=DPType.ENUM, + prefer_function=True, ): self._attr_supported_features |= SUPPORT_FAN_MODE self._attr_fan_modes = enum_type.range diff --git a/homeassistant/components/tuya/const.py b/homeassistant/components/tuya/const.py index 5093745a0bf..6d6a2aa2937 100644 --- a/homeassistant/components/tuya/const.py +++ b/homeassistant/components/tuya/const.py @@ -360,6 +360,7 @@ class DPCode(StrEnum): WATER_SET = "water_set" # Water level WATERSENSOR_STATE = "watersensor_state" WET = "wet" # Humidification + WINDSPEED = "windspeed" WIRELESS_BATTERYLOCK = "wireless_batterylock" WIRELESS_ELECTRICITY = "wireless_electricity" WORK_MODE = "work_mode" # Working mode diff --git a/homeassistant/components/tuya/vacuum.py b/homeassistant/components/tuya/vacuum.py index 832128a8b3e..70e1691af92 100644 --- a/homeassistant/components/tuya/vacuum.py +++ b/homeassistant/components/tuya/vacuum.py @@ -37,6 +37,7 @@ TUYA_MODE_RETURN_HOME = "chargego" TUYA_STATUS_TO_HA = { "charge_done": STATE_DOCKED, "chargecompleted": STATE_DOCKED, + "chargego": STATE_DOCKED, "charging": STATE_DOCKED, "cleaning": STATE_CLEANING, "docking": STATE_RETURNING, @@ -48,11 +49,14 @@ TUYA_STATUS_TO_HA = { "pick_zone_clean": STATE_CLEANING, "pos_arrived": STATE_CLEANING, "pos_unarrive": STATE_CLEANING, + "random": STATE_CLEANING, "sleep": STATE_IDLE, "smart_clean": STATE_CLEANING, + "smart": STATE_CLEANING, "spot_clean": STATE_CLEANING, "standby": STATE_IDLE, "wall_clean": STATE_CLEANING, + "wall_follow": STATE_CLEANING, "zone_clean": STATE_CLEANING, } diff --git a/homeassistant/components/unifiprotect/config_flow.py b/homeassistant/components/unifiprotect/config_flow.py index 0890a962e5b..39e255bb715 100644 --- a/homeassistant/components/unifiprotect/config_flow.py +++ b/homeassistant/components/unifiprotect/config_flow.py @@ -24,6 +24,7 @@ from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers.aiohttp_client import async_create_clientsession from homeassistant.helpers.typing import DiscoveryInfoType from homeassistant.loader import async_get_integration +from homeassistant.util.network import is_ip_address from .const import ( CONF_ALL_UPDATES, @@ -105,7 +106,11 @@ class ProtectFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): and entry_host != direct_connect_domain ): new_host = direct_connect_domain - elif not entry_has_direct_connect and entry_host != source_ip: + elif ( + not entry_has_direct_connect + and is_ip_address(entry_host) + and entry_host != source_ip + ): new_host = source_ip if new_host: self.hass.config_entries.async_update_entry( diff --git a/homeassistant/const.py b/homeassistant/const.py index c6403514ac9..17f0d651eab 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -7,7 +7,7 @@ from .backports.enum import StrEnum MAJOR_VERSION: Final = 2022 MINOR_VERSION: Final = 2 -PATCH_VERSION: Final = "0" +PATCH_VERSION: Final = "1" __short_version__: Final = f"{MAJOR_VERSION}.{MINOR_VERSION}" __version__: Final = f"{__short_version__}.{PATCH_VERSION}" REQUIRED_PYTHON_VER: Final[tuple[int, int, int]] = (3, 9, 0) diff --git a/homeassistant/helpers/script.py b/homeassistant/helpers/script.py index 8e54e294f4b..5a80691fa46 100644 --- a/homeassistant/helpers/script.py +++ b/homeassistant/helpers/script.py @@ -742,7 +742,7 @@ class _ScriptRun: if saved_repeat_vars: self._variables["repeat"] = saved_repeat_vars else: - del self._variables["repeat"] + self._variables.pop("repeat", None) # Not set if count = 0 async def _async_choose_step(self) -> None: """Choose a sequence.""" diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 438fa0eba8d..3f0b9516ead 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -15,7 +15,7 @@ ciso8601==2.2.0 cryptography==35.0.0 emoji==1.6.3 hass-nabucasa==0.52.0 -home-assistant-frontend==20220202.0 +home-assistant-frontend==20220203.0 httpx==0.21.3 ifaddr==0.1.7 jinja2==3.0.3 diff --git a/requirements_all.txt b/requirements_all.txt index 213388b0f3c..42800f50eec 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -842,7 +842,7 @@ hole==0.7.0 holidays==0.12 # homeassistant.components.frontend -home-assistant-frontend==20220202.0 +home-assistant-frontend==20220203.0 # homeassistant.components.zwave homeassistant-pyozw==0.1.10 @@ -1310,7 +1310,7 @@ pushbullet.py==0.11.0 pushover_complete==1.1.1 # homeassistant.components.pvoutput -pvo==0.2.0 +pvo==0.2.1 # homeassistant.components.rpi_gpio_pwm pwmled==1.6.7 @@ -1999,7 +1999,7 @@ python_opendata_transport==0.3.0 pythonegardia==1.0.40 # homeassistant.components.tile -pytile==2022.01.0 +pytile==2022.02.0 # homeassistant.components.touchline pytouchline==0.7 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 7aba9ba5fa7..83fed2a14e3 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -543,7 +543,7 @@ hole==0.7.0 holidays==0.12 # homeassistant.components.frontend -home-assistant-frontend==20220202.0 +home-assistant-frontend==20220203.0 # homeassistant.components.zwave homeassistant-pyozw==0.1.10 @@ -814,7 +814,7 @@ pure-python-adb[async]==0.3.0.dev0 pushbullet.py==0.11.0 # homeassistant.components.pvoutput -pvo==0.2.0 +pvo==0.2.1 # homeassistant.components.canary py-canary==0.5.1 @@ -1230,7 +1230,7 @@ python-twitch-client==0.6.0 python_awair==0.2.1 # homeassistant.components.tile -pytile==2022.01.0 +pytile==2022.02.0 # homeassistant.components.traccar pytraccar==0.10.0 diff --git a/setup.cfg b/setup.cfg index 970a736b68f..8f180fe2a6b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = homeassistant -version = 2022.2.0 +version = 2022.2.1 author = The Home Assistant Authors author_email = hello@home-assistant.io license = Apache-2.0 diff --git a/tests/components/accuweather/test_weather.py b/tests/components/accuweather/test_weather.py index 6c1bc76e9b1..02ace5d3f1d 100644 --- a/tests/components/accuweather/test_weather.py +++ b/tests/components/accuweather/test_weather.py @@ -46,7 +46,7 @@ async def test_weather_without_forecast(hass): assert state.attributes.get(ATTR_WEATHER_TEMPERATURE) == 22.6 assert state.attributes.get(ATTR_WEATHER_VISIBILITY) == 16.1 assert state.attributes.get(ATTR_WEATHER_WIND_BEARING) == 180 - assert state.attributes.get(ATTR_WEATHER_WIND_SPEED) == 14.5 + assert state.attributes.get(ATTR_WEATHER_WIND_SPEED) == 4.03 assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION entry = registry.async_get("weather.home") @@ -68,7 +68,7 @@ async def test_weather_with_forecast(hass): assert state.attributes.get(ATTR_WEATHER_TEMPERATURE) == 22.6 assert state.attributes.get(ATTR_WEATHER_VISIBILITY) == 16.1 assert state.attributes.get(ATTR_WEATHER_WIND_BEARING) == 180 - assert state.attributes.get(ATTR_WEATHER_WIND_SPEED) == 14.5 + assert state.attributes.get(ATTR_WEATHER_WIND_SPEED) == 4.03 assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION forecast = state.attributes.get(ATTR_FORECAST)[0] assert forecast.get(ATTR_FORECAST_CONDITION) == "lightning-rainy" @@ -78,7 +78,7 @@ async def test_weather_with_forecast(hass): assert forecast.get(ATTR_FORECAST_TEMP_LOW) == 15.4 assert forecast.get(ATTR_FORECAST_TIME) == "2020-07-26T05:00:00+00:00" assert forecast.get(ATTR_FORECAST_WIND_BEARING) == 166 - assert forecast.get(ATTR_FORECAST_WIND_SPEED) == 13.0 + assert forecast.get(ATTR_FORECAST_WIND_SPEED) == 3.61 entry = registry.async_get("weather.home") assert entry diff --git a/tests/components/dnsip/test_config_flow.py b/tests/components/dnsip/test_config_flow.py index 59dcb81aa94..f4684eb1cc4 100644 --- a/tests/components/dnsip/test_config_flow.py +++ b/tests/components/dnsip/test_config_flow.py @@ -7,6 +7,7 @@ from aiodns.error import DNSError import pytest from homeassistant import config_entries +from homeassistant.components.dnsip.config_flow import DATA_SCHEMA, DATA_SCHEMA_ADV from homeassistant.components.dnsip.const import ( CONF_HOSTNAME, CONF_IPV4, @@ -47,6 +48,7 @@ async def test_form(hass: HomeAssistant) -> None: DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" + assert result["data_schema"] == DATA_SCHEMA assert result["errors"] == {} with patch( @@ -79,6 +81,48 @@ async def test_form(hass: HomeAssistant) -> None: assert len(mock_setup_entry.mock_calls) == 1 +async def test_form_adv(hass: HomeAssistant) -> None: + """Test we get the form with advanced options on.""" + + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_USER, "show_advanced_options": True}, + ) + + assert result["data_schema"] == DATA_SCHEMA_ADV + + with patch( + "homeassistant.components.dnsip.config_flow.aiodns.DNSResolver", + return_value=RetrieveDNS(), + ), patch( + "homeassistant.components.dnsip.async_setup_entry", + return_value=True, + ) as mock_setup_entry: + result2 = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_HOSTNAME: "home-assistant.io", + CONF_RESOLVER: "8.8.8.8", + CONF_RESOLVER_IPV6: "2620:0:ccc::2", + }, + ) + await hass.async_block_till_done() + + assert result2["type"] == RESULT_TYPE_CREATE_ENTRY + assert result2["title"] == "home-assistant.io" + assert result2["data"] == { + "hostname": "home-assistant.io", + "name": "home-assistant.io", + "ipv4": True, + "ipv6": True, + } + assert result2["options"] == { + "resolver": "8.8.8.8", + "resolver_ipv6": "2620:0:ccc::2", + } + assert len(mock_setup_entry.mock_calls) == 1 + + async def test_form_error(hass: HomeAssistant) -> None: """Test validate url fails.""" result = await hass.config_entries.flow.async_init( diff --git a/tests/components/mqtt/test_sensor.py b/tests/components/mqtt/test_sensor.py index ad43a7b2353..c758b670b3d 100644 --- a/tests/components/mqtt/test_sensor.py +++ b/tests/components/mqtt/test_sensor.py @@ -268,6 +268,38 @@ async def test_setting_sensor_value_via_mqtt_json_message(hass, mqtt_mock): assert state.state == "100" +async def test_setting_sensor_value_via_mqtt_json_message_and_default_current_state( + hass, mqtt_mock +): + """Test the setting of the value via MQTT with fall back to current state.""" + assert await async_setup_component( + hass, + sensor.DOMAIN, + { + sensor.DOMAIN: { + "platform": "mqtt", + "name": "test", + "state_topic": "test-topic", + "unit_of_measurement": "fav unit", + "value_template": "{{ value_json.val | is_defined }}-{{ value_json.par }}", + } + }, + ) + await hass.async_block_till_done() + + async_fire_mqtt_message( + hass, "test-topic", '{ "val": "valcontent", "par": "parcontent" }' + ) + state = hass.states.get("sensor.test") + + assert state.state == "valcontent-parcontent" + + async_fire_mqtt_message(hass, "test-topic", '{ "par": "invalidcontent" }') + state = hass.states.get("sensor.test") + + assert state.state == "valcontent-parcontent" + + async def test_setting_sensor_last_reset_via_mqtt_message(hass, mqtt_mock, caplog): """Test the setting of the last_reset property via MQTT.""" assert await async_setup_component( diff --git a/tests/components/unifiprotect/test_config_flow.py b/tests/components/unifiprotect/test_config_flow.py index a1609984be3..68d90ff82eb 100644 --- a/tests/components/unifiprotect/test_config_flow.py +++ b/tests/components/unifiprotect/test_config_flow.py @@ -418,6 +418,37 @@ async def test_discovered_by_unifi_discovery_direct_connect_updated_but_not_usin assert mock_config.data[CONF_HOST] == "127.0.0.1" +async def test_discovered_host_not_updated_if_existing_is_a_hostname( + hass: HomeAssistant, mock_nvr: NVR +) -> None: + """Test we only update the host if its an ip address from discovery.""" + mock_config = MockConfigEntry( + domain=DOMAIN, + data={ + "host": "a.hostname", + "username": "test-username", + "password": "test-password", + "id": "UnifiProtect", + "port": 443, + "verify_ssl": True, + }, + unique_id=DEVICE_MAC_ADDRESS.upper().replace(":", ""), + ) + mock_config.add_to_hass(hass) + + with _patch_discovery(): + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_DISCOVERY}, + data=UNIFI_DISCOVERY_DICT, + ) + await hass.async_block_till_done() + + assert result["type"] == RESULT_TYPE_ABORT + assert result["reason"] == "already_configured" + assert mock_config.data[CONF_HOST] == "a.hostname" + + async def test_discovered_by_unifi_discovery( hass: HomeAssistant, mock_nvr: NVR ) -> None: diff --git a/tests/helpers/test_script.py b/tests/helpers/test_script.py index 2ee4213a688..5bb4833a796 100644 --- a/tests/helpers/test_script.py +++ b/tests/helpers/test_script.py @@ -1742,6 +1742,44 @@ async def test_repeat_count(hass, caplog, count): ) +async def test_repeat_count_0(hass, caplog): + """Test repeat action w/ count option.""" + event = "test_event" + events = async_capture_events(hass, event) + count = 0 + + alias = "condition step" + sequence = cv.SCRIPT_SCHEMA( + { + "alias": alias, + "repeat": { + "count": count, + "sequence": { + "event": event, + "event_data_template": { + "first": "{{ repeat.first }}", + "index": "{{ repeat.index }}", + "last": "{{ repeat.last }}", + }, + }, + }, + } + ) + + script_obj = script.Script(hass, sequence, "Test Name", "test_domain") + + await script_obj.async_run(context=Context()) + await hass.async_block_till_done() + + assert len(events) == count + assert caplog.text.count(f"Repeating {alias}") == count + assert_action_trace( + { + "0": [{}], + } + ) + + @pytest.mark.parametrize("condition", ["while", "until"]) async def test_repeat_condition_warning(hass, caplog, condition): """Test warning on repeat conditions."""