Commit Graph

1629 Commits (9758b080366dccb7eff30ddeec4df56605cf1562)

Author SHA1 Message Date
J. Nick Koston 982c8f8f4a
Fix incorrect scope on checking files to load in translations (#112457)
discovered in https://github.com/home-assistant/core/pull/112295#discussion_r1513505710

We only checked if the last language had files to load
instead of all of them. The checks for each language
are the same because the only reason we would skip
a language is a missing/broken integration or the integration
is a single file. Both of these loop conditions are always
the same reguardless of the language so the check worked
2024-03-05 23:46:24 -05:00
J. Nick Koston fbabbc8f92
Limit legacy state translations to custom components (#112295)
* Limit legacy state translations to custom components

We were trying to load **thousands** of `*.light.json`, `*.switch.json` files at run time that did not exist.

There have been replaced with entity translations: https://github.com/home-assistant/developers.home-assistant/pull/1557 https://github.com/home-assistant/core/pull/82701

https://github.com/home-assistant/core/pull/112023 will completely remove them, but
for now we will only load them for custom components to reduce the number
of files having to be examined

* reduce

* reduce

* reduce

* reduce

* comment

* coverage

* try to remove empty dict in loaded_translations fallback when missing
2024-03-05 17:27:45 -05:00
Erik Montnemery 3d3e9900c3
Add TypeVar default for FlowResult (#112345)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
2024-03-05 22:52:11 +01:00
J. Nick Koston f3eb292c2d
Remove async_entity_ids and get_entity_ids from entity registry (#112311)
added in #112277 but not used yet.
2024-03-05 14:50:41 +01:00
J. Nick Koston 8b017016b0
Refactor integration platforms to import in the executor (#112168)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-03-04 19:21:18 -10:00
J. Nick Koston 2c179dc5fb
Reduce some linear searches to cleanup the device registry (#112277)
Some of the data we had to search for was already available
in a dict or underlying data structure. Make it available
instead of having to build it every time.

There are more places these can be used, but I only did
the device registry cleanup for now
2024-03-04 20:59:12 -05:00
RoboMagus b381922a20
Issues template function (#95206)
* Add 'issues' template function for listing active issues.

* Add issue template function test

* Add 'issue' template function for getting specific issue by domain and issue_id

* Remove comment

* Fix function description

* Remove reduntant function,
Fix tests

* remove pass_context

* remove issues filter

Co-authored-by: Erik Montnemery <erik@montnemery.com>

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-03-04 14:22:14 +01:00
J. Nick Koston 331989de4c
Migrate condition/state/trigger helper to use async_get_platform (#112144)
Currently these would always load the platform in the loop
if it was not already loaded
2024-03-03 21:20:47 -05:00
J. Nick Koston 6421a08ba8
Avoid expensive inspect calls in config validators (#112085)
* Avoid expensive inspect calls in config validators

inspect has a performance problem https://github.com/python/cpython/issues/92041

We now avoid calling inspect unless we are going to log

* remove unused

* reduce

* get_integration_logger
2024-03-02 21:50:35 -05:00
Jan-Philipp Benecke 196089e8b7
Remove deprecated `hass.components.hassio` usage (#111878) 2024-03-02 15:38:31 +01:00
Erik Montnemery a0e558c457
Add generic classes BaseFlowHandler and BaseFlowManager (#111814)
* Add generic classes BaseFlowHandler and BaseFlowManager

* Migrate zwave_js

* Update tests

* Update tests

* Address review comments
2024-02-29 16:52:39 +01:00
J. Nick Koston f59268b2ee
Include filename in exception when loading a json file fails (#111802)
* Include filename in exception when loading a json file fails

* fix
2024-02-29 10:30:29 -05:00
Jan-Philipp Benecke bc6b4d01c8
Deprecate `hass.components` and log warning if used inside custom component (#111508)
* Deprecate @bind_hass and log error if used inside custom component

* Log also when accessing `hass.components`

* Log warning only when `hass.components` is used

* Change version

* Process code review
2024-02-29 12:25:46 +01:00
Jan-Philipp Benecke f31244bac4
Add normalized name registry items base class (#111666)
* Add normalized name base registry items class

* Add tests
2024-02-29 01:31:33 +01:00
Erik Montnemery b336095239
Allow translating device names (#110711)
* Allow translating device names

* Don't keep a reference to translations in config entry

* Update kitchen_sink tests

* Add tests
2024-02-28 15:59:59 +01:00
Jan-Philipp Benecke ebfba7258e
Revert "Drop `@bind_hass` use from hassio component (#111522)" (#111705)
This reverts commit 4e4345f04e.
2024-02-28 10:51:37 +01:00
J. Nick Koston 78bb6dbe75
Reduce latency in storage by making the tasks eager (#111500)
* Reduce latancy to load storage by making the task eager

This changes the semantics a bit under the hood because it
can raise sooner which means we do not store the task
as _load_task if it raises right away. That means
concurrent calls that result in failure are likely to try
again now which will be a tiny performance hit for this
case.

* fix

* will now finish in time
2024-02-27 23:27:37 -05:00
Jan-Philipp Benecke 4e4345f04e
Drop `@bind_hass` use from hassio component (#111522)
* Drop `@bind_hass` use from hassio component

* Add comment why we import locally

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-02-28 00:25:46 +01:00
J. Nick Koston dd80157dc7
Load translations at setup time if they were not loaded at bootstrap (#110921) 2024-02-24 11:31:25 -10:00
J. Nick Koston 5b8591ec7e
Avoid reschedule churn in Storage.async_delay_save (#111091)
* Avoid circular import in Storage.async_delay_save

We call Storage.async_delay_save for every entity being added or removed
from the registry. The late import took more time than everything else
in the function.

* Avoid reschedule churn in Storage.async_delay_save

When we are adding or removing entities we will call async_delay_save
quite often which has to add and remove a TimerHandle on the event loop
which can add up when there are a lot of registry items changing.

If the timer handle still has 80% of the time remaining on it
we will avoid resceduling and let it fire at the time the
original async_delay_save call was made. This ensures we
do not force the event loop to rebuild its heapq because
too many timer handlers were cancelled at once

* div0

* add coverage for 0 since we had none

* fix bad conflict

* tweaks

* tweaks

* tweaks

* tweaks

* tweaks

* tweaks

* more test fixes

* mqtt tests rely on event loop overhead
2024-02-24 08:46:00 +01:00
J. Nick Koston ff0e0b3e77
Convert debouncer async_shutdown to be a normal function (#111257)
* Convert debouncer async_shutdown to be a normal function

nothing was being awaited here and the shutdown call was only used
in integrations marked internal and other internals. Its possible
that a custom component might have been using the method but it
seemed uncommon enough that it did not warrent marking as a breaking
change. The update coordinator is no longer awaiting anything in
async_shutdown either now but it seemed likely that this use
would get subclassed.

* fix
2024-02-24 08:37:33 +01:00
J. Nick Koston d9addc45f9
Avoid scheduling a task to add each entity when not using update_before_add (#110951)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-02-23 10:49:26 -10:00
J. Nick Koston 776a9b8691
Make device registry cleanup a callback function (#111052)
* Add async_schedule_call to the Debouncer

async_schedule_call allows the Debouncer to schedule a call
from a callback without having to create tasks to run
async_call

* Update homeassistant/helpers/debounce.py

* Make device registry cleanup all callback function

* fix typing, code supported callback functions, but typing did not

* fixes

* fixes

* fix

* we had no coverage for other job types

* we had no coverage for other job types
2024-02-21 09:34:49 +01:00
J. Nick Koston 490c03d248
Add async_schedule_call to the Debouncer (#111051) 2024-02-21 00:09:45 -06:00
J. Nick Koston 9ce1ec414e
Reduce overhead to load multiple languages in translations (#111028)
* Reduce overhead to load multiple languages in translations

Instead of loading in a task, we now group everything
to be loaded into a single executor job

* fixes

* fixes

* fixes

* fixes

* fixes

* update tests

* add missing coverage (was existing)
2024-02-20 21:52:28 -05:00
J. Nick Koston 9c145b5faa
Fix race in removing entities from the registry (#110978) 2024-02-20 20:48:31 -06:00
J. Nick Koston dc4008c518
Avoid creating tasks to shutdown entity platforms (#111026)
* Avoid creating tasks to shutdown entity platforms

Nothing needed to be awaited here

* fix mocking

* missed one test
2024-02-20 21:10:25 -05:00
J. Nick Koston 98d5f2fc01
Reduce registry overhead in tests (#110955)
* Avoid scheduling registry loads as tasks in tests

Since we patch out async_load in Store, these will not yield
to the event loop so it makes sense to await them instead
of creating tasks

This reduced my local test run times ~2.5% on average

* mock out save as well so we do not schedule tasks to save empty data

* tweaks

* fix lingering files

* another one

* too much for one PR, reduce

* fix targets
2024-02-20 21:01:50 -05:00
Michael Hansen ec4bd9a421
Add new intents for cover, valve, vacuum, and media player (#110757)
* Add valve to HassTurnOn/Off

* Add set position for valves

* Add set position to covers

* Add HassTurnOn/Off for vacuums

* Add media player intents

* Split out vacuum intents

* Address comments

* Extra test
2024-02-19 22:28:42 -05:00
Franck Nijhof e0a9dcd996
Add label registry (#110821) 2024-02-19 11:59:08 +01:00
Franck Nijhof 67ac60d042
Add hex color validator (#110846) 2024-02-18 16:03:21 +01:00
J. Nick Koston 16653ff5d0
Group loading of translations for integrations to reduce executor jobs at startup (#110674) 2024-02-17 21:08:55 -06:00
J. Nick Koston 9bc130c131
Ensure translations for other integrations can be loaded if one integration fails (#110748)
* load failure

* merge
2024-02-17 21:01:36 -05:00
J. Nick Koston 33ff6b5b6e
Avoid creating tasks for checking integrations platforms (#110795)
* Avoid creating tasks for checking integrations platforms

This is a followup to #110743 to avoid creating a task to check
if the integration platform exists. We created tasks because
we needed to await async_get_integrations but since its always
called from EVENT_COMPONENT_LOADED firing, we can use the
async_get_loaded_integration version which does not need
to be awaited. This eliminates one task for every loaded
component

* there is no more race risk

* reduce

* coro or callback

* reduce

* tweak

* race safe

* fix type

* fixes

* use built-in helper to make it smaller

* use built-in helper to make it smaller

* use built-in helper to make it smaller

* add coverage to ensure exceptions are logged

* improve readability a bit

* platforms
2024-02-18 01:07:18 +01:00
Franck Nijhof 4570eed6f6
Add floor registry (#110741)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-02-17 21:21:15 +01:00
Franck Nijhof aa8d8402b4
Cleanups in entity registry tests (#110788)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-02-17 19:07:46 +01:00
Franck Nijhof 0fbadc274a
Cleanups in device registry tests (#110786) 2024-02-17 14:06:53 +01:00
Franck Nijhof df3556f0d8
Cleanups in area registry tests (#110785)
* Cleanups in area registry tests

* Adjust typing
2024-02-17 13:20:33 +01:00
J. Nick Koston 2cb0249f0a
Add filter to translation event listeners to avoid creating tasks (#110732) 2024-02-16 12:13:23 -06:00
J. Nick Koston 37897ee384
Move late import of config flows in loader to load time (#110688)
* Move late import of config flows in loader to load time

There does not seem to be any reason to import the
generated flows late. Import them at load time
with the rest of the generated files

* tests
2024-02-16 07:55:12 +01:00
J. Nick Koston e605b96d84
Ensure config entry oauth2 tests add config entry before updating it (#110421) 2024-02-12 22:59:17 +01:00
Marc Mueller 2ef2172b01
Convert test helpers to get hass instance to contextmanagers (#109990)
* Convert get_test_home_assistant helper to contextmanager

* Convert async_test_home_assistant helper to contextmanager

* Move timezone reset to async_test_home_assistant helper
2024-02-11 21:23:51 +01:00
chammp a5cc0ae890
Improve package schema validation (#108125)
* Add failing tests for package config validation error wrapping

* Wrap package schema validation errors in HomeAssistantError

* Fix yamllint errors

* Rework package merge validation

Ignore invalid package definitions instead of failing startup.
Output error messages with locations if possible when a package
definition has errors.

* Ruff format

* Fix linter errors

* Move package_definition_schema to module scope

* Move inner function to module level

* Merge exception handlers

Merge exception handlers for config schema validation and package merge
to avoid untested code branches

* Fix long lines and doc strings

* More minor changes to exception handler

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-10 20:16:20 +01:00
Piotr Machowski a2f4e99994
Add state_translated function to jinja templates (#96906)
* Add state_translated jinja function

* Add tests for load_state_translations_to_cache and get_cached_translations

* Cleanup state_translated template

* Add tests for state_translated jinja function

* Apply black formatting

* Improve code quality

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Apply suggestions from code review

* Prevent invalid components from loading translations

* Refactor loading translations to cache

* Adjust code issues

* Update homeassistant/helpers/translation.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Refactor listeners that trigger translation loading

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Apply suggestions from code review

* Adjust invalid function calls, fix code styling

* Adjust code quality

* Extract async_translate_state function

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Apply suggestions from code review

* Fix tests

* Fix tests

---------

Co-authored-by: Piotr Machowski <PiotrMachowski@users.noreply.github.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-10 10:47:56 +01:00
J. Nick Koston f6d4617c7a
Avoid directly changing config entry state in tests (part 2) (#110115)
followup to #110048 for more places
2024-02-10 07:20:15 +01:00
Joost Lekkerkerker 59e9010b65
Show domain in oauth2 error log (#109708)
* Show token url in oauth2 error log

* Fix tests

* Use domain
2024-02-06 23:03:35 +01:00
J. Nick Koston 09c609459d
Fix entity services targeting entities outside the platform when using areas/devices (#109810) 2024-02-06 12:41:57 -06:00
Marc Mueller cd0ee98dba
Use builtin TimeoutError [core + helpers] (#109684) 2024-02-05 12:09:54 +01:00
J. Nick Koston 9fef1938b4
Make get_entries_for_device_id skip disabled devices by default (#109645) 2024-02-04 23:11:56 +01:00
Erik Montnemery 09ba46ddb9
Mask sensitive data in google_assistant logs (#109366)
* Mask sensitive data in google_assistant logs

* Move common code to homeassistant/util/redact.py

* Move to helpers

* Add tests

* Tweak

* Redact additional logs

* Fix stale docstring

* Don't reveal the length of masked data

* Update test
2024-02-02 22:10:30 +01:00
J. Nick Koston ed726db974
Fix race in loading service descriptions (#109316) 2024-02-01 12:34:23 -06:00
Bram Kragten d361d47516
Add qr code selector (#109214) 2024-01-31 19:27:03 +01:00
Martijn van der Pol b386960661
Add default parameter to as_datetime template function/filter (#107229)
* improve as_datetime

* Improve `as_datetime` Jinja filter/function

* review

* resolve more review items

* change test for datetime input

* Update docstring

* update docstrings for tests

* remove whitespace

* only_default

* Update do string and comment

* improve comment

* Adjust comment

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-01-29 18:05:44 +01:00
Erik Montnemery 8abb4e5f52
Improve display of errors with no message in script trace (#108735) 2024-01-28 19:27:14 +01:00
karwosts a2d707442a
Fix error when passing a whole number to location selector (#108952)
* Fix error when passing an integer to location selector

* fix tests

* more fix tests

* don't mutate original dict

* remove string testcase
2024-01-28 14:13:00 +01:00
Erik Montnemery 909e58066d
Fix changed_variables in automation and script traces (#108788) 2024-01-24 19:12:45 +01:00
Erik Montnemery 9c727e5ea8
Add icon to areas (#108650) 2024-01-24 19:11:03 +01:00
Erik Montnemery 431e4b38ac
Improve tests of script trace (#108733) 2024-01-24 15:29:35 +01:00
Daniel a67113a95a
Parse template result in async_render_with_possible_json_value (#99670)
* Optionally parse templates rendered with possible json

* Remove duplicate strip

* Add tests for parsing template result
2024-01-24 12:12:28 +01:00
Erik Montnemery 069c2b7e38
Improve tests of script trace (#108717)
* Improve tests of script trace

* Update tests after rebase

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Apply suggestions from code review

* Adjust

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-01-23 19:53:09 +01:00
Erik Montnemery 9bff039d17
Add set_conversation_response script action (#108233)
* Add set_conversation_response script action

* Update homeassistant/components/conversation/trigger.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Revert accidental change

* Add test

* Ignore mypy

* Remove incorrect callback decorator

* Update homeassistant/helpers/script.py

* Add test with templated set_conversation_response

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-01-23 09:13:42 -05:00
Franck Nijhof 01372024f5
Add icon translations support (#103294)
Co-authored-by: Robert Resch <robert@resch.dev>
Co-authored-by: Paul Bottein <paul.bottein@gmail.com>
2024-01-19 16:56:56 +01:00
J. Nick Koston c399cab427
Small speed up to checking core state (#107845) 2024-01-18 08:41:32 -10:00
J. Nick Koston 454c62b5b4
Avoid total_seconds conversion every state write when context is set (#107617) 2024-01-13 21:04:32 -05:00
J. Nick Koston 4b7a313ece
Use identity checks for CoreState (#107846)
Some of the checks used ==, and some used is. Switch
everything to is as its faster
2024-01-12 10:21:26 +01:00
Erik Montnemery 8a9f9b94ef
Fix call to async_setup_component in translation test (#107807) 2024-01-11 10:09:32 -10:00
Lars R bf6b9175a1
Add 'bitwise_xor' filter to jinja templates (#104942)
Co-authored-by: Robert Resch <robert@resch.dev>
2024-01-10 09:40:52 +01:00
Erik Montnemery 9859306718
Prevent overriding cached attribute as property (#107657)
* Prevent overriding cached attribute as property

* Remove debug
2024-01-09 19:16:45 +01:00
Marc Mueller fde7a6e9ef
Improve dispatcher typing (#106872) 2024-01-08 09:45:37 +01:00
J. Nick Koston d260ed938a
Reduce overhead to call entity services (#106908) 2024-01-08 09:30:52 +01:00
J. Nick Koston d04e2d56da
Add support for JSON fragments (#107213) 2024-01-07 17:36:31 -10:00
Erik Montnemery c805ea7b4f
Include deprecated constants in wildcard imports (#107114) 2024-01-05 11:46:45 +01:00
Michael Hansen 269500cb29
Report missing entities/areas instead of failing to match in Assist (#107151)
* Report missing entities/areas instead of failing

* Fix test

* Update assist pipeline test snapshots

* Test complete match failure

* Fix conflict
2024-01-04 17:09:20 -06:00
J. Nick Koston 0695bf8988
Move group helpers into their own module (#106924)
This gets rid of the legacy need to use bind_hass, and
the expand function no longer looses typing.
2024-01-04 17:34:56 +01:00
Erik Montnemery 9eefd95e91
Deduplicate handling of duplicated constants (#107074)
* Deduplicate handling of duplicated constants

* Use DeprecatedConstant + DeprecatedConstantEnum

* Fixup

* Remove test cases with unnamed tuples
2024-01-04 13:25:09 +01:00
Michael eb01998395
Add support for placeholders in entity name translations (#104453)
* add placeholder support to entity name translation

* add negativ tests

* make property also available via description

* fix doc string in translation_placeholders()

* fix detection of placeholder

* validate placeholders for localized strings

* add test

* Cache translation_placeholders property

* Make translation_placeholders uncondotionally return dict

* Fall back to unsubstituted name in case of mismatch

* Only replace failing translations with English

* Update snapshots

* Blow up on non stable releases

* Fix test

* Update entity.py

---------

Co-authored-by: Erik <erik@montnemery.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-01-03 17:34:47 +01:00
J. Nick Koston 09b65f14b9
Index entities by domain for entity services (#106759) 2024-01-02 15:28:58 +01:00
Erik Montnemery 599271fdc0
Don't use entity_id in __repr__ of not added entity (#106861) 2024-01-02 11:35:16 +01:00
Erik Montnemery c1f1b5c50b
Ensure it's safe to call Entity.__repr__ on non added entity (#106032) 2023-12-31 18:54:34 +01:00
Erik Montnemery 461dad3039
Fix changed_variables in automation traces (#106665) 2023-12-30 08:34:21 +01:00
Erik Montnemery 56a58f9285
Improve tests of inheriting entity descriptions (#106647) 2023-12-29 13:22:52 +01:00
J. Nick Koston a46fe94216
Add helper to report deprecated entity supported features magic numbers (#106602) 2023-12-28 12:24:36 -10:00
Martijn van der Pol a823edf1c2
Jinja filter and function for `median` and `statistical_mode` (#105554)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-12-27 15:14:20 +01:00
Robert Resch fbcb31b103
Deprecate deprecated unit of measurement constants (#106455) 2023-12-27 09:04:25 +01:00
Marc Mueller c6d1f1ccc8
Fix pytest test collection warning (#106405) 2023-12-26 16:23:19 +01:00
Robert Resch ebdf7b9c8c
Deprecate some deprecated const constants (#106230)
* Deprecate some deprecated const constants

* Improve code

* fix typing

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-12-23 20:18:51 +01:00
Erik Montnemery 3a744d374b
Add support for caching entity properties (#100601) 2023-12-22 09:02:55 -10:00
Robert Resch e18d2b8873
Deprecate deprecated device_registry helper constants (#106227) 2023-12-22 11:21:45 +01:00
Robert Resch c4c422de79
Skip logging deprecated constant if the calling integration couldn't be indentified (#106181)
* Add option to log only if a integreation is detected for a deprecated constant

* Require param

* Add test that log entry is not created

* typo
2023-12-21 23:19:40 +01:00
Erik Montnemery 0534b0dee4
Improve entity tests (#106175) 2023-12-21 15:32:25 +01:00
Ville Skyttä 24b1e01d71
Update Ruff to 0.1.8, avoid linter/formatter conflicts (#106080)
* Disable Ruff rules that may conflict with the formatter

* Upgrade Ruff to 0.1.8

- https://github.com/astral-sh/ruff/releases/tag/v0.1.7
- https://github.com/astral-sh/ruff/releases/tag/v0.1.8

* Format with Ruff 0.1.8
2023-12-20 23:55:09 +01:00
Robert Resch 5a3db078d5
Use patch.dict in deprecation test "test_check_if_deprecated_constant" (#106117) 2023-12-20 16:06:26 +01:00
Robert Resch 0e0fd39603
Add dir_with_deprecated_constants function to deprecation helper (#106059) 2023-12-19 16:37:21 +01:00
Robert Resch a4ccd6e13b
Deprecate binary sensor device class constants (#105736)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-12-19 12:45:32 +01:00
Michael 29e30e796a
Add significant change helper check_valid_float (#106005) 2023-12-18 21:59:30 +01:00
Erik Montnemery 2515e520c1
Allow step size any for number selector in slider mode (#105978) 2023-12-18 15:30:59 +01:00
J. Nick Koston 47f8e08261
Reduce overhead to connect dispatcher (#105715)
Reduce overhead connect dispatcher

- We tend to have 1000s (or 10000s) of connected dispatchers which
  makes these prime targets to reduce overhead/memory

- Instead of creating new functions to wrap log exceptions each time
  use partials which reuses the function body and only create new
  arguments

Previous optimizations #103307 #93602
2023-12-16 10:16:58 +01:00
Erik Montnemery 9020dbb093
Remove context_recent_time property from entity base class (#105652) 2023-12-14 08:33:31 +01:00
Erik Montnemery dd5a48996a
Keep capabilities up to date in the entity registry (#101748)
* Keep capabilities up to date in the entity registry

* Warn if entities update their capabilities very often

* Fix updating of device class

* Stop tracking capability updates once flooding is logged

* Only sync registry if state changed

* Improve test

* Revert "Only sync registry if state changed"

This reverts commit 1c52571596c06444df234d4b088242b494b630f2.

* Avoid calculating device class twice

* Address review comments

* Revert using dataclass

* Fix unintended revert

* Add helper method
2023-12-13 17:27:26 +01:00
Erik Montnemery 22c3847c0e
Allow inheriting `FrozenOrThawed` with custom init (#105624) 2023-12-13 10:13:34 +01:00
Erik Montnemery 5bd0833f49
Improve FrozenOrThawed (#105541) 2023-12-12 21:19:41 +01:00
Erik Montnemery dd338799d4
Make it possible to inherit EntityDescription in frozen and mutable dataclasses (#105211) 2023-12-11 20:00:55 +01:00
Jan Bouwhuis 4bb0e13cda
Workaround `to_json` template filter in parsing dict key (#105327)
* Work-a-round orjson for `to_json` fiter in case dict key is str subclass

* Add option instead

* Remove json.dumps work-a-round

* Update homeassistant/helpers/template.py

* Fix test

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-12-08 20:57:53 +01:00
Jan-Philipp Benecke d1aa690c24
Migrate non-component tests to use freezegun/freezer (#105142) 2023-12-07 22:58:09 +01:00
Erik Montnemery 3bcc6194ef
Add domain key config validation (#104242)
* Drop use of regex in helpers.extract_domain_configs

* Update test

* Revert test update

* Add domain_from_config_key helper

* Add validator

* Address review comment

* Update snapshots

* Inline domain_from_config_key in validator
2023-12-05 15:07:32 +01:00
Erik Montnemery 25bea91683
Use modern platform path when reporting platform config errors (#104238)
* Use modern platform path when reporting platform config errors

* Update tests

* Address review comment

* Explicitly pass platform domain to log helpers

* Revert overly complicated changes

* Try a simpler solution
2023-12-05 15:06:13 +01:00
Erik Montnemery 84e74e4c74
Reverse component path (#104087)
* Reverse component path

* Update translations helper

* Fix

* Revert incorrect change of PLATFORM_FORMAT

* Fix use of PLATFORM_FORMAT in tts

* Fix ios
2023-12-05 08:43:58 +01:00
Erik Montnemery 35e2f591c1
Make `cv.string` return subclasses of str as is (#103916) 2023-12-04 20:36:16 +01:00
Erik Montnemery 95f7db1970
Move config_per_platform and extract_domain_configs to config.py (#104989) 2023-12-04 12:48:49 +01:00
Erik Montnemery db51a8e1f7
Allow passing breaks_in_ha_version to deprecation helper decorators (#104985) 2023-12-04 11:52:10 +01:00
J. Nick Koston 1522118453
Remove aiohttp cancel on disconnect workaround (#104175) 2023-11-29 11:20:36 -07:00
Paul Bottein 38eda9f46e
Add multiple option to text selector (#104635)
Co-authored-by: Robert Resch <robert@resch.dev>
2023-11-29 18:32:32 +01:00
schelv 31cab5803c
Add Option For Kelvin Unit To Color Temperature Selector (#103799) 2023-11-29 12:25:06 +01:00
Aarni Koskela 706add4a57
Switch formatting from black to ruff-format (#102893)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-11-27 14:38:59 +01:00
Jan Bouwhuis af71c2bb45
Raise and suppress stack trace when reloading yaml fails (#102410)
* Allow async_integration_yaml_config to raise

* Docstr - split check

* Implement as wrapper, return dataclass

* Fix setup error handling

* Fix reload test mock

* Move log_messages to error handler

* Remove unreachable code

* Remove config test helper

* Refactor and ensure notifications during setup

* Remove redundat error, adjust tests notifications

* Fix patch

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Follow up comments

* Add call_back decorator

* Split long lines

* Update exception abbreviations

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-11-24 17:34:45 +01:00
Erik Montnemery a573f60947
Rename some check_config test cases (#104244) 2023-11-20 13:02:44 +01:00
Erik Montnemery 80813e992d
Improve formatting of component errors (#104081)
* Improve formatting of component errors

* Update tests
2023-11-17 23:01:00 +01:00
Erik Montnemery a78764f000
Improve formatting of package errors (#104078) 2023-11-17 14:57:37 +01:00
Erik Montnemery 4536fb3541
Remove mock_entity_platform test helper (#104073) 2023-11-16 16:55:08 +01:00
Erik Montnemery b400b33b0d
Refer to domain configuration in custom validator errors (#104065) 2023-11-16 15:28:48 +01:00
Erik Montnemery d8a49b14e5
Use relative paths in configuration validation error messages (#104064) 2023-11-16 10:56:47 +01:00
Erik Montnemery 98030a9ce1
Improve formatting of package errors (#103976) 2023-11-16 09:08:47 +01:00
Erik Montnemery 1c817cc18c
Attach relevant config to check_config errors (#104048) 2023-11-16 07:25:52 +01:00
Erik Montnemery 5b37096b5f
Refactor config.async_log_exception (#104034)
* Refactor config.async_log_exception

* Improve test coverage

* Make functions public
2023-11-15 19:09:49 +01:00
Erik Montnemery dd7670cacf
Improve errors for component configuration with missing keys (#103982) 2023-11-15 10:47:05 +01:00
Erik Montnemery 94a2087ba0
Improve formatting of config validation errors (#103957)
* Improve formatting of config validation errors

* Address review comments
2023-11-14 12:48:45 +01:00
Erik Montnemery dedd3418a1
Improve print of line numbers when there are configuration errors (#103216)
* Improve print of line numbers when there are configuration errors

* Update alarm_control_panel test
2023-11-14 08:21:36 +01:00
Erik Montnemery 07af073735
Remove trailing space from configuration error messages (#103909)
* Remove trailing space from configuration error messages

* Update test
2023-11-13 15:19:37 +01:00
Erik Montnemery 01b3e0c49e
Remove useless code from entity helper tests (#103854) 2023-11-12 18:55:34 +01:00
Allen Porter 787fb3b954
Improve OAuth error handling in configuration flows (#103157)
* Improve OAuth error handling in configuration flows

* Update strings for all integrations that use oauth2 config flow

* Remove invalid_auth strings

* Revert change to release

* Revert close change in aiohttp mock
2023-11-11 11:02:51 +01:00
Franck Nijhof 70ad5ab3e4
Update helper tests to use device & entity registry fixtures (#103710) 2023-11-10 09:32:19 +01:00
Erik Montnemery 123f14dd6c
Attach correct platform config in check_config warnings and errors (#103633) 2023-11-09 00:06:04 +01:00
Erik Montnemery d913508607
Allow removing an entity more than once (#102904) 2023-11-08 12:50:40 +01:00
Erik Montnemery cc5eda76d3
Humanize core config errors in check_config helper (#103635) 2023-11-08 10:15:27 +01:00
Erik Montnemery 3ba8a82243
Differentiate between warnings and errors in check_config helper (#102902)
* Differentiate between warnings and errors in check_config helper

* Update tests

* Treat configuration errors in frontend and its dependencies as errors

* Improve test coverage

* Address review comments

* Improve test coverage

* Improve test coverage

* Address review comments

* Add comment
2023-11-05 03:08:04 +01:00
Jan-Philipp Benecke ae1117bc74
Fix failing entity reuse test (#103342)
* Fix failing entity reuse test

* One more test
2023-11-03 23:19:37 +01:00
Erik Montnemery 0ea0a1ed06
Prevent accidentally reusing an entity object (#102911)
* Prevent accidentally reusing an entity object

* Fix group reload service

* Revert "Fix group reload service"

* Improve test

* Add tests aserting entity can't be reused
2023-11-03 21:01:38 +01:00
Paul Bottein 89a9e6c6e8
Add trigger selector for blueprint (#103050) 2023-11-03 09:11:49 +01:00
Kevin Stillhammer 06c9719cd6
Support multiple responses for service calls (#96370)
* add supports_response to platform entity services

* support multiple entities in entity_service_call

* support legacy response format for service calls

* revert changes to script/shell_command

* add back test for multiple responses for legacy service

* remove SupportsResponse.ONLY_LEGACY

* Apply suggestion

Co-authored-by: Allen Porter <allen.porter@gmail.com>

* test for entity_id remove None

* revert Apply suggestion

* return EntityServiceResponse from _handle_entity_call

* Use asyncio.gather

* EntityServiceResponse not Optional

* styling

---------

Co-authored-by: Allen Porter <allen.porter@gmail.com>
2023-11-02 18:37:35 -07:00
Erik Montnemery 03d3a87f23
Small cleanup of legacy groups (#102918)
* Small cleanup of legacy groups

* Update tests which create groups
2023-10-28 17:16:41 +02:00
Erik Montnemery 6f515c06a2
Add test for check_config helper (#102898) 2023-10-28 14:52:20 +02:00
Erik Montnemery 294f565bad
Allow missing components in safe mode (#102888) 2023-10-27 12:25:27 +02:00
Erik Montnemery b83ada8c19
Use real devices in automation and script tests (#102785) 2023-10-25 16:09:39 +02:00
Raman Gupta 35d18a9a3e
Add tests for types and functions for type conversions in templates (#100807)
Co-authored-by: Robert Resch <robert@resch.dev>
2023-10-25 13:20:34 +02:00
J. Nick Koston f91583a0fc
Add support for family to aiohttp session helper (#102702) 2023-10-24 18:40:39 -05:00
Erik Montnemery c481fdb7d0
Rename safe mode to recovery mode (#102580) 2023-10-23 20:33:08 +02:00
Erik Montnemery 1621310ba7
Add serial_number to device registry entries (#102334)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2023-10-22 15:14:44 +02:00
J. Nick Koston 433c022687
Save previous unique id in entity registry when it changes (#102093) 2023-10-16 21:26:19 -10:00
J. Nick Koston e5ebdf7ad4
Remove implict name check from Entity base class (#101905) 2023-10-15 23:40:43 +02:00
G Johansson dc29190564
CountrySelector (#100963)
* CountrySelector

* rename

* remove multiple for now

* Add no_sort

* Update homeassistant/helpers/selector.py

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-10-12 16:44:30 +02:00
Robert Resch b932c67eb7
Delete optional schema keys, when they are not present (#101755)
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-10-10 21:08:54 +02:00
Nicolas van de Walle 1b11062b27
Improved debugging for "Failed to set state" (#101657) 2023-10-08 19:40:42 +02:00
Joost Lekkerkerker faea3b1634
Abort config flow when invalid token is received (#101642) 2023-10-08 13:32:35 +02:00
Erik Montnemery 20188181f7
Fix spelling in sensor test (#101520) 2023-10-06 11:51:08 +02:00
Erik Montnemery 3478666973
Use loader.async_suggest_report_issue in deprecation helper (#101393) 2023-10-06 09:51:08 +02:00
Erik Montnemery dce5099d92
Use loader.async_suggest_report_issue in frame helper (#101461) 2023-10-05 19:52:26 +02:00
Erik Montnemery 7e39acda37
Minor improvement of frame helper (#101387)
* Minor improvement of frame helper

* Add new custom integration for testing

* Make IntegrationFrame kw_only
2023-10-04 21:43:00 +02:00
Erik Montnemery 17779c5f0c
Add loader.async_suggest_report_issue and loader.async_get_issue_tracker (#101336)
* Add loader.async_suggest_report_issue and loader.async_get_issue_tracker

* Update tests

* Add tests

* Address review comments

* Address review comments
2023-10-04 13:40:33 +02:00
Erik Montnemery 2627abb9ef
Improve test coverage of deprecation helper (#101335) 2023-10-03 20:57:24 +02:00
Erik Montnemery ab2de18f8f
Refactor frame.get_integration_frame (#101322) 2023-10-03 19:21:27 +02:00
Marc Mueller 100b6fd06f
Fix flaky lru_cache test (#101252) 2023-10-02 13:52:56 +02:00
Ville Skyttä f4bf8fa8f1
Catch HTML case insensitively in "no HTML" config validation (#101181) 2023-10-01 16:19:24 +02:00
Erik Montnemery 47ecce4873
Allow deleting entity entries from entity_registry.async_migrate_entries (#101094)
* Allow deleting entity entries from entity_registry.async_migrate_entries

* Explicitly return None in tests
2023-09-30 10:23:10 +02:00
Marc Mueller c59404b5bc
Fix additional test cases for Python 3.12 (#101006) 2023-09-27 17:19:20 +02:00
Erik Montnemery ab060b86d1
Remove async_process_integration_platform_for_component (#100680) 2023-09-21 17:06:41 +02:00
Erik Montnemery d1afcd773f
Revert "Cache entity properties that are never expected to change in the base class" (#100422)
Revert "Cache entity properties that are never expected to change in the base class (#95315)"

This reverts commit 042776ebb8.
2023-09-15 11:25:24 +02:00
J. Nick Koston 042776ebb8
Cache entity properties that are never expected to change in the base class (#95315) 2023-09-14 17:48:48 -05:00
Erik Montnemery bbcbb2e322
Improve Entity._suggest_report_issue (#100204) 2023-09-12 21:07:32 +02:00
Erik Montnemery 51576b7214
Improve typing of entity.entity_sources (#99407)
* Improve typing of entity.entity_sources

* Calculate entity info source when generating WS response

* Adjust typing

* Update tests
2023-09-12 20:41:26 +02:00
Erik Montnemery 1654ef7759
Make WS command render_template not give up if initial render raises (#99808) 2023-09-08 21:02:06 +02:00
J. Nick Koston 034fabe188
Use loop time to set context (#99701)
* Use loop time to set context

loop time is faster than utcnow, and since its only used internally it can
be switched without a breaking change

* fix mocking
2023-09-06 11:04:49 +02:00
Erik Montnemery 48f7924e9e
Allow specifying a custom log function for template render (#99572)
* Allow specifying a custom log function for template render

* Bypass template cache when reporting errors + fix tests

* Send errors as events

* Fix logic for creating new TemplateEnvironment

* Add strict mode back

* Only send error events if report_errors is True

* Force test of websocket_api only

* Debug test

* Run pytest with higher verbosity

* Timeout after 1 minute, enable syslog output

* Adjust timeout

* Add debug logs

* Fix unsafe call to WebSocketHandler._send_message

* Remove debug code

* Improve test coverage

* Revert accidental change

* Include severity in error events

* Remove redundant information from error events
2023-09-06 10:03:35 +02:00
J. Nick Koston a2dae60170
Refactor dispatcher to reduce run time and memory overhead (#99676)
* Fix memory leak in dispatcher removal

When we removed the last job/callable from the dict for the
signal we did not remove the dict for the signal which meant
it leaked

* comment

* cleanup a bit more
2023-09-05 21:18:27 -04:00
Erik Montnemery 709ce7e0af
Set state of entity with invalid state to unknown (#99452)
* Set state of entity with invalid state to unknown

* Add test

* Apply suggestions from code review

Co-authored-by: Robert Resch <robert@resch.dev>

* Update test_entity.py

---------

Co-authored-by: Robert Resch <robert@resch.dev>
2023-09-04 14:09:51 +02:00
Erik Montnemery 9dac6a2948
Use loop.time in DataUpdateCoordinator (#98937) 2023-08-28 10:16:34 -05:00
Ville Skyttä 6399d74c15
Remove unnnecessary pylint configs from core (#98704) 2023-08-22 23:12:12 +02:00
Ville Skyttä 3094991236
Upgrade ruff to 0.0.285 (#98647) 2023-08-19 08:17:17 -04:00
Erik Montnemery 7fcc2dd44e
Make the check_config script open issue_registry read only (#98545)
* Don't blow up if validators can't access the issue registry

* Make the check_config script open issue_registry read only

* Update tests/helpers/test_issue_registry.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-08-18 20:15:00 +02:00
Marc Mueller a9ade1f84d
Use asyncio.timeout [core] (#98447) 2023-08-15 08:36:05 -05:00
Erik Montnemery 97f3199d6d
Do not add entities with invalid device info (#98150) 2023-08-11 13:14:47 +02:00
Franck Nijhof 296c27859e
Fix issue registry sending unneeded update events (#98230) 2023-08-10 21:57:42 -04:00
Erik Montnemery 4e8b81370e
Adjust device_registry tests which create devices (#98215) 2023-08-10 19:28:33 +02:00
Erik Montnemery c7b4d4f361
Adjust helpers tests which create devices (#98214) 2023-08-10 19:28:16 +02:00
Marc Mueller f39a35c4ef
Fix jinja2 DeprecationWarnings (#97728) 2023-08-04 11:25:08 +02:00
Paul Bottein 83af2f5b8b
Allow to sort options in select selector (#97680)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-08-03 21:49:22 +02:00
Meow 6fd60024cc
Refactored deprecated UNITS (#97368) 2023-08-03 21:12:01 +02:00
Franck Nijhof af5fc7e759
Ensure load the device registry if it contains invalid configuration URLs (#97589) 2023-08-01 23:15:31 +02:00
J. Nick Koston 094f2cbad7
Fix saving subclassed datetime objects in storage (#97502) 2023-07-31 18:49:02 +02:00
J. Nick Koston 13349e76ed
Avoid firing update coordinator callbacks when nothing has changed (#97268) 2023-07-28 12:19:20 -05:00
Franck Nijhof 737ac8c600
Fix DeviceInfo configuration_url validation (#97319) 2023-07-27 18:57:01 +02:00
Franck Nijhof b655b9d530
Allow for translating service examples (#97141) 2023-07-24 15:57:02 +02:00
Marc Mueller 995c29e052
Cleanup EventType typing (#97136) 2023-07-24 13:18:38 +02:00
Marc Mueller 4161f53bea
Improve `async_track_state_change_filtered` callback typing (#97134) 2023-07-24 12:42:29 +02:00
Marc Mueller 582499a260
Improve `async_track_template_result` callback typing (#97135) 2023-07-24 12:42:17 +02:00
Marc Mueller 797a9c1ead
Improve `async_track_state_added/removed_domain` callback typing (#97126) 2023-07-24 09:11:41 +02:00
Marc Mueller 2618bfc073
Use EventType for state changed [core] (#97115) 2023-07-23 18:10:03 -05:00
Jan Bouwhuis 9424d11408
Allow homeassistant in MQTT configuration_url schema (#96107) 2023-07-22 22:50:58 +02:00
Erik Montnemery df46179d26
Fix broken service test (#96943) 2023-07-20 13:11:55 +02:00
Joost Lekkerkerker 0ba2531ca4
Fix bug in check_config when an integration is removed by its own validator (#96068)
* Raise if present is False

* Fix feedback

* Update homeassistant/helpers/check_config.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Update homeassistant/helpers/check_config.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Fix tests

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-07-20 11:45:44 +02:00
J. Nick Koston 01e66d6fb2
Improve handling of unrecoverable storage corruption (#96712)
* Improve handling of unrecoverable storage corruption

fixes #96574

If something in storage gets corrupted core can boot loop
or if its integration specific, the integration will fail to
start.

We now complainly loudly in the log, move away the corrupt data
and start fresh to allow startup to proceed so the user can
get to the UI and restore from backup without having to attach
a console (or otherwise login to the OS and manually modify files).

* test for corruption

* ensure OSError is still fatal

* one more case

* create an issue for corrupt storage

* fix key

* persist

* feedback

* feedback

* better to give the full path

* tweaks

* grammar

* add time

* feedback

* adjust

* try to get issue_domain from storage key

* coverage

* tweak wording some more
2023-07-19 09:23:12 +02:00
Paul Bottein d8c989f732
Make default theme selectable for set theme service (#96849) 2023-07-18 17:36:35 +02:00
Franck Nijhof b9f92b526b
Add prefix support to text selector (#96830) 2023-07-18 12:17:31 +02:00
J. Nick Koston bc6a41fb94
Remove deprecated state.get_changed_since (#96579) 2023-07-18 09:42:48 +02:00
J. Nick Koston 7ec506907c
Ensure async_get_system_info does not fail if supervisor is unavailable (#96492)
* Ensure async_get_system_info does not fail if supervisor is unavailable

fixes #96470

* fix i/o in the event loop

* fix tests

* handle some more failure cases

* more I/O here

* coverage

* coverage

* Update homeassistant/helpers/system_info.py

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>

* remove supervisor detection fallback

* Update tests/helpers/test_system_info.py

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2023-07-16 11:10:07 -04:00
Erik Montnemery 614f3c6a15
Move device info validation to device registry (#96465)
* Move device info validation to device registry

* Don't move DeviceInfo

* Fix type annotation

* Don't block adding device for unknown config entry

* Fix test

* Remove use of locals()

* Improve error message
2023-07-14 08:55:17 -04:00
Erik Montnemery 7539cf25be
Don't require passing identifiers to DeviceRegistry.async_get_device (#96479)
* Require keyword arguments to DeviceRegistry.async_get_device

* Update tests

* Update tests

* Don't enforce keyword arguments
2023-07-13 13:39:25 -04:00
J. Nick Koston 08af42b00e
Fix mixed case service schema registration (#96448) 2023-07-12 14:39:51 -10:00
Paul Bottein e513b7d0eb
Add condition selector for blueprint (#96350)
* Add condition selector for blueprint

* Add tests and validation

* Update comment
2023-07-12 10:58:35 -04:00
Franck Nijhof 594d240a96
Migrate & fix logger services to support translations (#96393)
* Migrate logger services to support translations

* Fix tests and schema validation

* Apply suggestions from code review

Co-authored-by: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com>

---------

Co-authored-by: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com>
2023-07-12 10:37:18 -04:00
Franck Nijhof f054de0ad5
Add support for service translations (#95984) 2023-07-11 15:52:12 +02:00
Paulus Schoutsen eee8566694
Differentiate between device info types (#95641)
* Differentiate between device info types

* Update allowed fields

* Update homeassistant/helpers/entity_platform.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Split up message in 2 lines

* Use dict for device info types

* Extract device info function and test error checking

* Simplify parsing device info

* move checks around

* Simplify more

* Move error checking around

* Fix order

* fallback config entry title to domain

* Remove fallback for name to config entry domain

* Ensure mocked configuration URLs are strings

* one more test case

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-07-10 09:56:06 -04:00
Erik Montnemery 3d064b7d6b
Add filters to cover/services.yaml (#95854) 2023-07-08 11:51:02 +02:00
Jan Bouwhuis 18ee9f4725
Refactor async_get_hass to rely on threading.local instead of a ContextVar (#96005)
* Test for async_get_hass

* Add Fix
2023-07-07 14:52:38 -04:00
Erik Montnemery 86a397720f
Move platform_integration_no_support issue to the homeassistant integration (#95927)
* Move platform_integration_no_support issue to the homeassistant integration

* Update test

* Improve repair text

* Update test
2023-07-07 13:31:54 +02:00
J. Nick Koston b7b8afffd0
Handle integrations with empty services or failing to load during service description enumeration (#95911)
* wip

* tweaks

* tweaks

* add coverage

* complain loudly as we never execpt this to happen

* ensure not None

* comment it
2023-07-06 11:19:06 -04:00
Jan Bouwhuis b9c7e7c15e
Fix not including device_name in friendly name if it is None (#95485)
* Omit device_name in friendly name if it is None

* Fix test
2023-07-06 11:14:09 -04:00
Bram Kragten 342d07cb92
Set correct `response` value in service description when `async_set_service_schema` is used (#95985)
* Mark scripts as response optional, make it always return a response if return_response is set

* Update test_init.py

* Revert "Update test_init.py"

This reverts commit 8e113e54db.

* Split + add test
2023-07-06 10:24:34 -04:00
J. Nick Koston b2e708834f
Add slots to the StateMachine class (#95849) 2023-07-05 14:00:37 +02:00
J. Nick Koston b24c6adc75
Avoid regex for negative zero check in sensor (#95691)
* Avoid regex for negative zero check in sensor

We can avoid calling the regex for every sensor value
since most of the time values are not negative zero

* tweak

* tweak

* Apply suggestions from code review

* simpler

* cover

* safer and still fast

* safer and still fast

* prep for py3.11

* fix check

* add missing cover

* more coverage

* coverage

* coverage
2023-07-02 21:53:50 -04:00
Paulus Schoutsen e4f617e92e
Update log message when referenced entity not found (#95577)
* Update log message when referenced entity not found

* Update homeassistant/helpers/service.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update test

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-07-02 00:04:03 +02:00
Paulus Schoutsen 9280dc69ae
Default device name to config entry title (#95547)
* Default device name to config entry title

* Only apply name default if device info provided

* Fix logic detecting type of device info
2023-06-30 13:54:20 -04:00
Bram Kragten a7dfe46fb1
Add conversation agent selector, use in `conversation.process` service (#95462) 2023-06-28 21:38:06 -04:00
Paulus Schoutsen 243abf32c0
Add test to stop action (#95376) 2023-06-27 19:38:30 +02:00
Franck Nijhof 3e85a29b86
Move overlapping pylint rules to ruff, disable mypy overlap (#94359) 2023-06-27 17:42:46 +02:00
Erik Montnemery 071d3a474f
Base entity ids on English for languages not using Latin script (#91357) 2023-06-27 14:37:50 +02:00
Paulus Schoutsen d95c241a1a
Add service response values to service descriptions (#95262) 2023-06-26 12:57:43 -04:00
Erik Montnemery 8fda56d2c9
Stable entity registry id when a deleted entity is restored (#77710)
* Stable entity_id and registry id when a deleted entity is restored

* Don't restore area_id

* Don't restore entity_id

* Address review comments
2023-06-26 15:54:35 +02:00
J. Nick Koston 9051750add
Cache entity translation lookups and keys (#95180) 2023-06-25 08:50:48 -05:00
Allen Porter 528c206094
Add script specific error messages for `response_variable` (#95188) 2023-06-24 21:34:57 -07:00
Allen Porter b9b5fe6be8
Add service response data for listing calendar events (#94759)
* Add service response data for listing calendar events

Add the capability of response data for for the entity component.

* Rename input arguments and add service description

* Improve list events to be more user friendly

Allow the end date to be determined based on a relative time duration. Make the start time optional and set to "now". Add additional test coverage. Update demo calendar to actually perform date range checks.

* Wrap docstrings properly.

* Increase test coverage

* Update to use new API calls

* Readability improvements

* Wrap docstrings

* Require at least one of end or duration

* Check for multiple entity matches earlier in the request

* Update documentation strings
2023-06-23 23:34:34 -04:00
Franck Nijhof e2f5a707ce
Fix use_device_name in case device device class translations are used (#95010)
Co-authored-by: Erik <erik@montnemery.com>
2023-06-22 11:30:19 +02:00
J. Nick Koston 8d2daaa694
Limit cache size of EntityValues (#94983) 2023-06-21 22:23:35 +02:00
Allen Porter 30e8f806c1
Improve service response data APIs (#94819)
* Improve service response data APIs

Make the API naming more consistent, and require registration that a
service supports response data so that we can better integrate with
the UI and avoid user confusion with better error messages.

* Improve test coverage

* Add an enum for registering response values

* Assign enum values

* Convert SupportsResponse to StrEnum

* Update service call test docstrings

* Add tiny missing full stop in comment

---------

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
2023-06-20 06:24:31 -07:00
Erik Montnemery 4a8adae146
Teach alarm_control_panel device trigger about entity registry ids (#60977)
* Teach alarm_control_panel device trigger about entity registry ids

* Lint code

* Address review comment
2023-06-20 08:27:31 -04:00
Erik Montnemery 609a573b55
Regenerate instance ID on error (#94898) 2023-06-20 11:16:51 +02:00
Allen Porter c4284c07b6
Allow scripts to capture service response data in variables (#94757)
* Allow scripts service actions to save return values

* Simplify script service response data

* Rename result_variable to response_variable based on feedback
2023-06-16 22:59:44 -04:00
J. Nick Koston 68cf796be8
Speed up entity service calls (#94731)
* Speed up entity service calls

- Avoid permissions check if the caller is an admin
- Use set intersection instead of linear search of entity platforms to find entities

* tweak

* fix light test to not use an admin user
2023-06-16 21:07:57 -04:00
Allen Porter 12129e9d21
Update service call return values and error handling (#94657)
* Update return signature of service calls

* Add timeout error handling in websocket api for service calls

* Update recorder tests to remove assertion on service call

* Remove timeout behavior and update callers that depend on it today

* Fix tests

* Add missing else

* await coro directly

* Fix more tests

* Update the intent task to use wait instead of timeout

* Remove script service call limits and limit constants

* Update tests that depend on service call limits

* Use wait instead of wait_for and add test

* Update homeassistant/helpers/intent.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-06-16 07:01:40 -07:00
J. Nick Koston 26be0fab78
Fix debouncer not scheduling timer when wrapped function raises (#94689)
* Fix debouncer not scheduling timer when callback function raises

* test coro as well

* preen
2023-06-15 22:15:49 -04:00
Erik Montnemery 334dacc322
Change Entity.name default to UNDEFINED (#94574)
* Change Entity.name default to UNDEFINED

* Update typing

* Update Pylint plugin

* Update TTS test
2023-06-15 11:09:53 +02:00
Erik Montnemery d51982f12f
Add missing assert to test_async_remove_ignores_in_flight_polling (#94487) 2023-06-12 21:48:12 +02:00
Erik Montnemery 59f5b8f2d6
Remove unneeded checks for Entity.platform (#94321)
* Remove unneeded checks for Entity.platform

* Update tests

* Prevent breaking integrations without an EntityComponent

* Warn when entity has no platform
2023-06-09 15:17:41 +02:00
Michael Benz 305fa128fb
Add reload support to intent_script (#93404)
* support live reload of intent_script

* add services.yaml

* update tesls for full code coverage

* Update based on feedback

* fix intent_script reload when no intent_script config

* Update homeassistant/helpers/intent.py

* update tests to handle no_existing better

---------

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2023-06-03 14:02:23 -04:00
J. Nick Koston 457bc4571d
Make RestoreStateData.async_get_instance backwards compatible (#93924) 2023-06-01 19:31:17 +02:00
Erik Montnemery f9037d5f6d
Add platform only config schema to nsw_fuel_station and ping (#93913) 2023-06-01 17:30:15 +02:00
Erik Montnemery c1c319d4d1
Rename `cv.no_yaml_config_schema` to `cv.config_entry_only_config_schema` (#93908)
* Rename cv.no_yaml_config_schema to cv.config_entry_only_config_schema

* ✏️
2023-06-01 13:15:48 +02:00
Erik Montnemery e0db9ab041
Add CONFIG_SCHEMA to broadlink (#93854)
* Add CONFIG_SCHEMA to broadlink

* Simplify error message

* Rename to no_yaml_config_schema

* Add tests

* Raise issue

* Tweak repairs issue description and title

* Update homeassistant/helpers/config_validation.py

* Add link

* Update homeassistant/components/homeassistant/strings.json

Co-authored-by: Franck Nijhof <git@frenck.dev>

* Fix logic, add test

---------

Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-06-01 09:51:26 +02:00
Erik Montnemery 59c6220b7c
Subscribe to device registry changes from entities (#93601)
* Subscribe to device registry changes from entities

* Use async_track_device_registry_updated_event

* Fix unsubscribe

* Fix logic, add tests
2023-05-31 11:01:55 +02:00
J. Nick Koston fba826ae9e
Migrate restore_state helper to use registry loading pattern (#93773)
* Migrate restore_state helper to use registry loading pattern

As more entities have started using restore_state over time, it
has become a startup bottleneck as each entity being added is
creating a task to load restore state data that is already loaded
since it is a singleton

We now use the same pattern as the registry helpers

* fix refactoring error -- guess I am tired

* fixes

* fix tests

* fix more

* fix more

* fix zha tests

* fix zha tests

* comments

* fix error

* add missing coverage

* s/DATA_RESTORE_STATE_TASK/DATA_RESTORE_STATE/g
2023-05-30 20:48:17 -05:00
J. Nick Koston 9f0d3bfce8
Use ReadOnlyDict for entity registry options (#93824)
* Use ReadOnlyDict for entity registry options

While reviewing #93601 it was noticed this was slow at startup
https://github.com/home-assistant/core/pull/93601#issuecomment-1568958280

This is a first pass attempt to improve the performance

* fix tests
2023-05-30 20:11:39 -04:00