Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .core_files.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ base_platforms: &base_platforms
- homeassistant/components/humidifier/**
- homeassistant/components/image/**
- homeassistant/components/image_processing/**
- homeassistant/components/infrared/**
- homeassistant/components/lawn_mower/**
- homeassistant/components/light/**
- homeassistant/components/lock/**
Expand Down
1 change: 1 addition & 0 deletions .strict-typing
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ homeassistant.components.imgw_pib.*
homeassistant.components.immich.*
homeassistant.components.incomfort.*
homeassistant.components.inels.*
homeassistant.components.infrared.*
homeassistant.components.input_button.*
homeassistant.components.input_select.*
homeassistant.components.input_text.*
Expand Down
2 changes: 2 additions & 0 deletions CODEOWNERS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ coverage:
target: auto
threshold: 1
paths:
- homeassistant/components/*/backup.py
- homeassistant/components/*/config_flow.py
- homeassistant/components/*/device_action.py
- homeassistant/components/*/device_condition.py
Expand All @@ -28,6 +29,7 @@ coverage:
target: 100
threshold: 0
paths:
- homeassistant/components/*/backup.py
- homeassistant/components/*/config_flow.py
- homeassistant/components/*/device_action.py
- homeassistant/components/*/device_condition.py
Expand Down
9 changes: 3 additions & 6 deletions homeassistant/components/alexa_devices/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
ATTR_TEXT_COMMAND = "text_command"
ATTR_SOUND = "sound"
ATTR_INFO_SKILL = "info_skill"
SERVICE_TEXT_COMMAND = "send_text_command"
SERVICE_SOUND_NOTIFICATION = "send_sound"
SERVICE_INFO_SKILL = "send_info_skill"

SCHEMA_SOUND_SERVICE = vol.Schema(
{
Expand Down Expand Up @@ -128,17 +125,17 @@ def async_setup_services(hass: HomeAssistant) -> None:
"""Set up the services for the Amazon Devices integration."""
for service_name, method, schema in (
(
SERVICE_SOUND_NOTIFICATION,
"send_sound",
async_send_sound_notification,
SCHEMA_SOUND_SERVICE,
),
(
SERVICE_TEXT_COMMAND,
"send_text_command",
async_send_text_command,
SCHEMA_CUSTOM_COMMAND,
),
(
SERVICE_INFO_SKILL,
"send_info_skill",
async_send_info_skill,
SCHEMA_INFO_SKILL,
),
Expand Down
34 changes: 11 additions & 23 deletions homeassistant/components/amcrest/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@

STREAM_SOURCE_LIST = ["snapshot", "mjpeg", "rtsp"]

_SRV_EN_REC = "enable_recording"
_SRV_DS_REC = "disable_recording"
_SRV_EN_AUD = "enable_audio"
_SRV_DS_AUD = "disable_audio"
_SRV_EN_MOT_REC = "enable_motion_recording"
_SRV_DS_MOT_REC = "disable_motion_recording"
_SRV_GOTO = "goto_preset"
_SRV_CBW = "set_color_bw"
_SRV_TOUR_ON = "start_tour"
_SRV_TOUR_OFF = "stop_tour"

_SRV_PTZ_CTRL = "ptz_control"
_ATTR_PTZ_TT = "travel_time"
_ATTR_PTZ_MOV = "movement"
_MOV = [
Expand Down Expand Up @@ -103,17 +91,17 @@
)

CAMERA_SERVICES = {
_SRV_EN_REC: (_SRV_SCHEMA, "async_enable_recording", ()),
_SRV_DS_REC: (_SRV_SCHEMA, "async_disable_recording", ()),
_SRV_EN_AUD: (_SRV_SCHEMA, "async_enable_audio", ()),
_SRV_DS_AUD: (_SRV_SCHEMA, "async_disable_audio", ()),
_SRV_EN_MOT_REC: (_SRV_SCHEMA, "async_enable_motion_recording", ()),
_SRV_DS_MOT_REC: (_SRV_SCHEMA, "async_disable_motion_recording", ()),
_SRV_GOTO: (_SRV_GOTO_SCHEMA, "async_goto_preset", (_ATTR_PRESET,)),
_SRV_CBW: (_SRV_CBW_SCHEMA, "async_set_color_bw", (_ATTR_COLOR_BW,)),
_SRV_TOUR_ON: (_SRV_SCHEMA, "async_start_tour", ()),
_SRV_TOUR_OFF: (_SRV_SCHEMA, "async_stop_tour", ()),
_SRV_PTZ_CTRL: (
"enable_recording": (_SRV_SCHEMA, "async_enable_recording", ()),
"disable_recording": (_SRV_SCHEMA, "async_disable_recording", ()),
"enable_audio": (_SRV_SCHEMA, "async_enable_audio", ()),
"disable_audio": (_SRV_SCHEMA, "async_disable_audio", ()),
"enable_motion_recording": (_SRV_SCHEMA, "async_enable_motion_recording", ()),
"disable_motion_recording": (_SRV_SCHEMA, "async_disable_motion_recording", ()),
"goto_preset": (_SRV_GOTO_SCHEMA, "async_goto_preset", (_ATTR_PRESET,)),
"set_color_bw": (_SRV_CBW_SCHEMA, "async_set_color_bw", (_ATTR_COLOR_BW,)),
"start_tour": (_SRV_SCHEMA, "async_start_tour", ()),
"stop_tour": (_SRV_SCHEMA, "async_stop_tour", ()),
"ptz_control": (
_SRV_PTZ_SCHEMA,
"async_ptz_control",
(_ATTR_PTZ_MOV, _ATTR_PTZ_TT),
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/backup/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
"title": "The backup location {agent_id} is unavailable"
},
"automatic_backup_failed_addons": {
"description": "Add-ons {failed_addons} could not be included in automatic backup. Please check the Supervisor logs for more information. Another attempt will be made at the next scheduled time if a backup schedule is configured.",
"title": "Not all add-ons could be included in automatic backup"
"description": "Apps {failed_addons} could not be included in automatic backup. Please check the Supervisor logs for more information. Another attempt will be made at the next scheduled time if a backup schedule is configured.",
"title": "Not all apps could be included in automatic backup"
},
"automatic_backup_failed_agents_addons_folders": {
"description": "The automatic backup was created with errors:\n* Locations which the backup could not be uploaded to: {failed_agents}\n* Add-ons which could not be backed up: {failed_addons}\n* Folders which could not be backed up: {failed_folders}\n\nPlease check the Core and Supervisor logs for more information. Another attempt will be made at the next scheduled time if a backup schedule is configured.",
"description": "The automatic backup was created with errors:\n* Locations which the backup could not be uploaded to: {failed_agents}\n* Apps which could not be backed up: {failed_addons}\n* Folders which could not be backed up: {failed_folders}\n\nPlease check the Core and Supervisor logs for more information. Another attempt will be made at the next scheduled time if a backup schedule is configured.",
"title": "Automatic backup was created with errors"
},
"automatic_backup_failed_create": {
Expand Down
16 changes: 15 additions & 1 deletion homeassistant/components/history_stats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
)
from homeassistant.helpers.template import Template

from .const import CONF_DURATION, CONF_END, CONF_START, PLATFORMS
from .const import (
CONF_DURATION,
CONF_END,
CONF_MIN_STATE_DURATION,
CONF_START,
PLATFORMS,
SECTION_ADVANCED_SETTINGS,
)
from .coordinator import HistoryStatsUpdateCoordinator
from .data import HistoryStats

Expand All @@ -36,8 +43,14 @@ async def async_setup_entry(
end: str | None = entry.options.get(CONF_END)

duration: timedelta | None = None
min_state_duration: timedelta
if duration_dict := entry.options.get(CONF_DURATION):
duration = timedelta(**duration_dict)
advanced_settings = entry.options.get(SECTION_ADVANCED_SETTINGS, {})
if min_state_duration_dict := advanced_settings.get(CONF_MIN_STATE_DURATION):
min_state_duration = timedelta(**min_state_duration_dict)
else:
min_state_duration = timedelta(0)

history_stats = HistoryStats(
hass,
Expand All @@ -46,6 +59,7 @@ async def async_setup_entry(
Template(start, hass) if start else None,
Template(end, hass) if end else None,
duration,
min_state_duration,
)
coordinator = HistoryStatsUpdateCoordinator(hass, history_stats, entry, entry.title)
await coordinator.async_config_entry_first_refresh()
Expand Down
20 changes: 19 additions & 1 deletion homeassistant/components/history_stats/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from homeassistant.components.sensor import CONF_STATE_CLASS, SensorStateClass
from homeassistant.const import CONF_ENTITY_ID, CONF_NAME, CONF_STATE, CONF_TYPE
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import section
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.schema_config_entry_flow import (
SchemaCommonFlowHandler,
Expand All @@ -37,13 +38,15 @@
from .const import (
CONF_DURATION,
CONF_END,
CONF_MIN_STATE_DURATION,
CONF_PERIOD_KEYS,
CONF_START,
CONF_TYPE_KEYS,
CONF_TYPE_RATIO,
CONF_TYPE_TIME,
DEFAULT_NAME,
DOMAIN,
SECTION_ADVANCED_SETTINGS,
)
from .coordinator import HistoryStatsUpdateCoordinator
from .data import HistoryStats
Expand Down Expand Up @@ -139,7 +142,7 @@ def _get_options_schema_with_entity_id(entity_id: str, type: str) -> vol.Schema:
vol.Optional(CONF_START): TemplateSelector(),
vol.Optional(CONF_END): TemplateSelector(),
vol.Optional(CONF_DURATION): DurationSelector(
DurationSelectorConfig(enable_day=True, allow_negative=False)
DurationSelectorConfig(enable_day=True, allow_negative=False),
),
vol.Optional(CONF_STATE_CLASS): SelectSelector(
SelectSelectorConfig(
Expand All @@ -148,6 +151,18 @@ def _get_options_schema_with_entity_id(entity_id: str, type: str) -> vol.Schema:
mode=SelectSelectorMode.DROPDOWN,
),
),
vol.Optional(SECTION_ADVANCED_SETTINGS): section(
vol.Schema(
{
vol.Optional(CONF_MIN_STATE_DURATION): DurationSelector(
DurationSelectorConfig(
enable_day=True, allow_negative=False
)
),
}
),
{"collapsed": True},
),
}
)

Expand Down Expand Up @@ -275,6 +290,8 @@ def async_preview_updated(
start = validated_data.get(CONF_START)
end = validated_data.get(CONF_END)
duration = validated_data.get(CONF_DURATION)
advanced_settings = validated_data.get(SECTION_ADVANCED_SETTINGS, {})
min_state_duration = advanced_settings.get(CONF_MIN_STATE_DURATION)
state_class = validated_data.get(CONF_STATE_CLASS)

history_stats = HistoryStats(
Expand All @@ -284,6 +301,7 @@ def async_preview_updated(
Template(start, hass) if start else None,
Template(end, hass) if end else None,
timedelta(**duration) if duration else None,
timedelta(**min_state_duration) if min_state_duration else timedelta(0),
True,
)
coordinator = HistoryStatsUpdateCoordinator(hass, history_stats, None, name, True)
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/history_stats/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
CONF_START = "start"
CONF_END = "end"
CONF_DURATION = "duration"
CONF_MIN_STATE_DURATION = "min_state_duration"
CONF_PERIOD_KEYS = [CONF_START, CONF_END, CONF_DURATION]

CONF_TYPE_TIME = "time"
Expand All @@ -16,3 +17,5 @@
CONF_TYPE_KEYS = [CONF_TYPE_TIME, CONF_TYPE_RATIO, CONF_TYPE_COUNT]

DEFAULT_NAME = "unnamed statistics"

SECTION_ADVANCED_SETTINGS = "advanced_settings"
34 changes: 28 additions & 6 deletions homeassistant/components/history_stats/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(
start: Template | None,
end: Template | None,
duration: datetime.timedelta | None,
min_state_duration: datetime.timedelta,
preview: bool = False,
) -> None:
"""Init the history stats manager."""
Expand All @@ -58,6 +59,7 @@ def __init__(
self._has_recorder_data = False
self._entity_states = set(entity_states)
self._duration = duration
self._min_state_duration = min_state_duration.total_seconds()
self._start = start
self._end = end
self._preview = preview
Expand Down Expand Up @@ -243,18 +245,38 @@ def _async_compute_seconds_and_changes(
)
break

if previous_state_matches:
elapsed += state_change_timestamp - last_state_change_timestamp
elif current_state_matches:
match_count += 1
if not previous_state_matches and current_state_matches:
# We are entering a matching state.
# This marks the start of a new candidate block that may later
# qualify if it lasts at least min_state_duration.
last_state_change_timestamp = max(
start_timestamp, state_change_timestamp
)
elif previous_state_matches and not current_state_matches:
# We are leaving a matching state.
# This closes the current matching block and allows to
# evaluate its total duration.
block_duration = state_change_timestamp - last_state_change_timestamp
if block_duration >= self._min_state_duration:
# The block lasted long enough so we increment match count
# and accumulate its duration.
elapsed += block_duration
match_count += 1

previous_state_matches = current_state_matches
last_state_change_timestamp = max(start_timestamp, state_change_timestamp)

# Count time elapsed between last history state and end of measure
if previous_state_matches:
# We are still inside a matching block at the end of the
# measurement window. This block has not been closed by a
# transition, so we evaluate it up to measure_end.
measure_end = min(end_timestamp, now_timestamp)
elapsed += measure_end - last_state_change_timestamp
last_state_duration = max(0, measure_end - last_state_change_timestamp)
if last_state_duration >= self._min_state_duration:
# The open block lasted long enough so we increment match count
# and accumulate its duration.
elapsed += last_state_duration
match_count += 1

# Save value in seconds
seconds_matched = elapsed
Expand Down
11 changes: 10 additions & 1 deletion homeassistant/components/history_stats/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from .const import (
CONF_DURATION,
CONF_END,
CONF_MIN_STATE_DURATION,
CONF_PERIOD_KEYS,
CONF_START,
CONF_TYPE_COUNT,
Expand All @@ -63,6 +64,8 @@
}
ICON = "mdi:chart-line"

DEFAULT_MIN_STATE_DURATION = datetime.timedelta(0)


def exactly_two_period_keys[_T: dict[str, Any]](conf: _T) -> _T:
"""Ensure exactly 2 of CONF_PERIOD_KEYS are provided."""
Expand Down Expand Up @@ -91,6 +94,9 @@ def no_ratio_total[_T: dict[str, Any]](conf: _T) -> _T:
vol.Optional(CONF_START): cv.template,
vol.Optional(CONF_END): cv.template,
vol.Optional(CONF_DURATION): cv.time_period,
vol.Optional(
CONF_MIN_STATE_DURATION, default=DEFAULT_MIN_STATE_DURATION
): cv.time_period,
vol.Optional(CONF_TYPE, default=CONF_TYPE_TIME): vol.In(CONF_TYPE_KEYS),
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_UNIQUE_ID): cv.string,
Expand Down Expand Up @@ -120,14 +126,17 @@ async def async_setup_platform(
start: Template | None = config.get(CONF_START)
end: Template | None = config.get(CONF_END)
duration: datetime.timedelta | None = config.get(CONF_DURATION)
min_state_duration: datetime.timedelta = config[CONF_MIN_STATE_DURATION]
sensor_type: str = config[CONF_TYPE]
name: str = config[CONF_NAME]
unique_id: str | None = config.get(CONF_UNIQUE_ID)
state_class: SensorStateClass | None = config.get(
CONF_STATE_CLASS, SensorStateClass.MEASUREMENT
)

history_stats = HistoryStats(hass, entity_id, entity_states, start, end, duration)
history_stats = HistoryStats(
hass, entity_id, entity_states, start, end, duration, min_state_duration
)
coordinator = HistoryStatsUpdateCoordinator(hass, history_stats, None, name)
await coordinator.async_refresh()
if not coordinator.last_update_success:
Expand Down
Loading
Loading