Skip to content

Commit

Permalink
Merge branch 'dev' into downloader-fix-2
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Apr 5, 2024
2 parents 48660cc + 24f83c5 commit 919a116
Show file tree
Hide file tree
Showing 133 changed files with 1,052 additions and 543 deletions.
3 changes: 1 addition & 2 deletions homeassistant/components/alert/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
STATE_OFF,
STATE_ON,
)
from homeassistant.core import Event, HassJob, HomeAssistant
from homeassistant.core import Event, EventStateChangedData, HassJob, HomeAssistant
from homeassistant.exceptions import ServiceNotFound
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.event import (
EventStateChangedData,
async_track_point_in_time,
async_track_state_change_event,
)
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/apache_kafka/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
STATE_UNAVAILABLE,
STATE_UNKNOWN,
)
from homeassistant.core import Event, HomeAssistant
from homeassistant.core import Event, EventStateChangedData, HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entityfilter import FILTER_SCHEMA, EntityFilter
from homeassistant.helpers.event import EventStateChangedData
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import ssl as ssl_util

Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
URL_API_TEMPLATE,
)
import homeassistant.core as ha
from homeassistant.core import Event, HomeAssistant
from homeassistant.core import Event, EventStateChangedData, HomeAssistant
from homeassistant.exceptions import (
InvalidEntityFormatError,
InvalidStateError,
Expand All @@ -46,7 +46,6 @@
Unauthorized,
)
from homeassistant.helpers import config_validation as cv, template
from homeassistant.helpers.event import EventStateChangedData
from homeassistant.helpers.json import json_dumps, json_fragment
from homeassistant.helpers.service import async_get_all_descriptions
from homeassistant.helpers.typing import ConfigType
Expand Down
21 changes: 20 additions & 1 deletion homeassistant/components/august/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import datetime
from functools import partial
import logging
from time import monotonic

from aiohttp import ClientError
from yalexs.activity import Activity, ActivityType
Expand All @@ -26,9 +27,11 @@
ACTIVITY_STREAM_FETCH_LIMIT = 10
ACTIVITY_CATCH_UP_FETCH_LIMIT = 2500

INITIAL_LOCK_RESYNC_TIME = 60

# If there is a storm of activity (ie lock, unlock, door open, door close, etc)
# we want to debounce the updates so we don't hammer the activity api too much.
ACTIVITY_DEBOUNCE_COOLDOWN = 3
ACTIVITY_DEBOUNCE_COOLDOWN = 4


@callback
Expand Down Expand Up @@ -62,6 +65,7 @@ def __init__(
self.pubnub = pubnub
self._update_debounce: dict[str, Debouncer] = {}
self._update_debounce_jobs: dict[str, HassJob] = {}
self._start_time: float | None = None

@callback
def _async_update_house_id_later(self, debouncer: Debouncer, _: datetime) -> None:
Expand All @@ -70,6 +74,7 @@ def _async_update_house_id_later(self, debouncer: Debouncer, _: datetime) -> Non

async def async_setup(self) -> None:
"""Token refresh check and catch up the activity stream."""
self._start_time = monotonic()
update_debounce = self._update_debounce
update_debounce_jobs = self._update_debounce_jobs
for house_id in self._house_ids:
Expand Down Expand Up @@ -140,11 +145,25 @@ def async_schedule_house_id_refresh(self, house_id: str) -> None:

debouncer = self._update_debounce[house_id]
debouncer.async_schedule_call()

# Schedule two updates past the debounce time
# to ensure we catch the case where the activity
# api does not update right away and we need to poll
# it again. Sometimes the lock operator or a doorbell
# will not show up in the activity stream right away.
# Only do additional polls if we are past
# the initial lock resync time to avoid a storm
# of activity at setup.
if (
not self._start_time
or monotonic() - self._start_time < INITIAL_LOCK_RESYNC_TIME
):
_LOGGER.debug(
"Skipping additional updates due to ongoing initial lock resync time"
)
return

_LOGGER.debug("Scheduling additional updates for house id %s", house_id)
job = self._update_debounce_jobs[house_id]
for step in (1, 2):
future_updates.append(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/august/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# Limit battery, online, and hardware updates to hourly
# in order to reduce the number of api requests and
# avoid hitting rate limits
MIN_TIME_BETWEEN_DETAIL_UPDATES = timedelta(hours=1)
MIN_TIME_BETWEEN_DETAIL_UPDATES = timedelta(hours=24)

# Activity needs to be checked more frequently as the
# doorbell motion and rings are included here
Expand Down
33 changes: 15 additions & 18 deletions homeassistant/components/august/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,30 @@ def _async_scheduled_refresh(self, now: datetime) -> None:
"""Call the refresh method."""
self._hass.async_create_task(self._async_refresh(now), eager_start=True)

@callback
def _async_cancel_update_interval(self, _: Event | None = None) -> None:
"""Cancel the scheduled update."""
if self._unsub_interval:
self._unsub_interval()
self._unsub_interval = None

@callback
def _async_setup_listeners(self) -> None:
"""Create interval and stop listeners."""
self._async_cancel_update_interval()
self._unsub_interval = async_track_time_interval(
self._hass,
self._async_scheduled_refresh,
self._update_interval,
name="august refresh",
)

@callback
def _async_cancel_update_interval(_: Event) -> None:
self._stop_interval = None
if self._unsub_interval:
self._unsub_interval()

self._stop_interval = self._hass.bus.async_listen(
EVENT_HOMEASSISTANT_STOP,
_async_cancel_update_interval,
run_immediately=True,
)
if not self._stop_interval:
self._stop_interval = self._hass.bus.async_listen(
EVENT_HOMEASSISTANT_STOP,
self._async_cancel_update_interval,
run_immediately=True,
)

@callback
def async_unsubscribe_device_id(
Expand All @@ -82,13 +85,7 @@ def async_unsubscribe_device_id(

if self._subscriptions:
return

if self._unsub_interval:
self._unsub_interval()
self._unsub_interval = None
if self._stop_interval:
self._stop_interval()
self._stop_interval = None
self._async_cancel_update_interval()

@callback
def async_signal_device_id_update(self, device_id: str) -> None:
Expand Down
16 changes: 8 additions & 8 deletions homeassistant/components/axis/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(self, hub: AxisHub) -> None:
mjpeg_url=self.mjpeg_source,
still_image_url=self.image_source,
authentication=HTTP_DIGEST_AUTHENTICATION,
verify_ssl=False,
unique_id=f"{hub.unique_id}-camera",
)

Expand All @@ -74,16 +75,18 @@ def _generate_sources(self) -> None:
Additionally used when device change IP address.
"""
proto = self.hub.config.protocol
host = self.hub.config.host
port = self.hub.config.port

image_options = self.generate_options(skip_stream_profile=True)
self._still_image_url = (
f"http://{self.hub.config.host}:{self.hub.config.port}/axis-cgi"
f"/jpg/image.cgi{image_options}"
f"{proto}://{host}:{port}/axis-cgi/jpg/image.cgi{image_options}"
)

mjpeg_options = self.generate_options()
self._mjpeg_url = (
f"http://{self.hub.config.host}:{self.hub.config.port}/axis-cgi"
f"/mjpg/video.cgi{mjpeg_options}"
f"{proto}://{host}:{port}/axis-cgi/mjpg/video.cgi{mjpeg_options}"
)

stream_options = self.generate_options(add_video_codec_h264=True)
Expand All @@ -95,10 +98,7 @@ def _generate_sources(self) -> None:
self.hub.additional_diagnostics["camera_sources"] = {
"Image": self._still_image_url,
"MJPEG": self._mjpeg_url,
"Stream": (
f"rtsp://user:pass@{self.hub.config.host}/axis-media"
f"/media.amp{stream_options}"
),
"Stream": (f"rtsp://user:pass@{host}/axis-media/media.amp{stream_options}"),
}

@property
Expand Down
11 changes: 4 additions & 7 deletions homeassistant/components/axis/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,13 @@ async def _redo_configuration(
self, entry_data: Mapping[str, Any], keep_password: bool
) -> ConfigFlowResult:
"""Re-run configuration step."""
protocol = entry_data.get(CONF_PROTOCOL, "http")
password = entry_data[CONF_PASSWORD] if keep_password else ""
self.discovery_schema = {
vol.Required(
CONF_PROTOCOL, default=entry_data.get(CONF_PROTOCOL, "http")
): str,
vol.Required(CONF_PROTOCOL, default=protocol): vol.In(PROTOCOL_CHOICES),
vol.Required(CONF_HOST, default=entry_data[CONF_HOST]): str,
vol.Required(CONF_USERNAME, default=entry_data[CONF_USERNAME]): str,
vol.Required(
CONF_PASSWORD,
default=entry_data[CONF_PASSWORD] if keep_password else "",
): str,
vol.Required(CONF_PASSWORD, default=password): str,
vol.Required(CONF_PORT, default=entry_data[CONF_PORT]): int,
}

Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/axis/hub/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
CONF_NAME,
CONF_PASSWORD,
CONF_PORT,
CONF_PROTOCOL,
CONF_TRIGGER_TIME,
CONF_USERNAME,
)
Expand All @@ -31,6 +32,7 @@ class AxisConfig:

entry: ConfigEntry

protocol: str
host: str
port: int
username: str
Expand All @@ -54,6 +56,7 @@ def from_config_entry(cls, config_entry: ConfigEntry) -> Self:
options = config_entry.options
return cls(
entry=config_entry,
protocol=config.get(CONF_PROTOCOL, "http"),
host=config[CONF_HOST],
username=config[CONF_USERNAME],
password=config[CONF_PASSWORD],
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/bayesian/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
STATE_UNAVAILABLE,
STATE_UNKNOWN,
)
from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.core import Event, EventStateChangedData, HomeAssistant, callback
from homeassistant.exceptions import ConditionError, TemplateError
from homeassistant.helpers import condition
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import (
EventStateChangedData,
TrackTemplate,
TrackTemplateResult,
TrackTemplateResultInfo,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/cloud/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"integration_type": "system",
"iot_class": "cloud_push",
"loggers": ["hass_nabucasa"],
"requirements": ["hass-nabucasa==0.79.0"]
"requirements": ["hass-nabucasa==0.80.0"]
}
11 changes: 7 additions & 4 deletions homeassistant/components/compensation/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
CONF_UNIT_OF_MEASUREMENT,
STATE_UNKNOWN,
)
from homeassistant.core import Event, HomeAssistant, State, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import (
from homeassistant.core import (
Event,
EventStateChangedData,
async_track_state_change_event,
HomeAssistant,
State,
callback,
)
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

from .const import (
Expand Down
37 changes: 27 additions & 10 deletions homeassistant/components/conversation/default_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@
translation,
)
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.event import (
EventStateChangedData,
async_track_state_added_domain,
)
from homeassistant.helpers.event import async_track_state_added_domain
from homeassistant.util.json import JsonObjectType, json_loads_object

from .const import DEFAULT_EXPOSED_ATTRIBUTES, DOMAIN
Expand Down Expand Up @@ -134,7 +131,9 @@ async def async_setup_default_agent(
async_should_expose(hass, DOMAIN, entity_id)

@core.callback
def async_entity_state_listener(event: core.Event[EventStateChangedData]) -> None:
def async_entity_state_listener(
event: core.Event[core.EventStateChangedData],
) -> None:
"""Set expose flag on new entities."""
async_should_expose(hass, DOMAIN, event.data["entity_id"])

Expand Down Expand Up @@ -269,20 +268,38 @@ async def async_process(self, user_input: ConversationInput) -> ConversationResu
for trigger_id, trigger_result in result.matched_triggers.items()
]

# Use last non-empty result as response.
# Use first non-empty result as response.
#
# There may be multiple copies of a trigger running when editing in
# the UI, so it's critical that we filter out empty responses here.
response_text: str | None = None
response_set_by_trigger = False
for trigger_future in asyncio.as_completed(trigger_callbacks):
if trigger_response := await trigger_future:
response_text = trigger_response
break
trigger_response = await trigger_future
if trigger_response is None:
continue

response_text = trigger_response
response_set_by_trigger = True
break

# Convert to conversation result
response = intent.IntentResponse(language=language)
response.response_type = intent.IntentResponseType.ACTION_DONE
response.async_set_speech(response_text or "Done")

if response_set_by_trigger:
# Response was explicitly set to empty
response_text = response_text or ""
elif not response_text:
# Use translated acknowledgment for pipeline language
translations = await translation.async_get_translations(
self.hass, language, DOMAIN, [DOMAIN]
)
response_text = translations.get(
f"component.{DOMAIN}.agent.done", "Done"
)

response.async_set_speech(response_text)

return ConversationResult(response=response)

Expand Down
5 changes: 5 additions & 0 deletions homeassistant/components/conversation/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@
}
}
}
},
"conversation": {
"agent": {
"done": "Done"
}
}
}
Loading

0 comments on commit 919a116

Please sign in to comment.