Commit graph

78 commits

Author SHA1 Message Date
Erik Montnemery
8de771de96
Rename async_track_state_reported_event to async_track_state_report_event (#120637)
* Rename async_track_state_reported_event to async_track_state_report_event

* Update tests
2024-06-27 13:45:15 +02:00
J. Nick Koston
5503379a3b
Fix performance regression in integration from state_reported (#120621)
* Fix performance regression in integration from state_reported

Because the callbacks were no longer indexed by entity id, users
saw upwards of 1M calls/min

https://github.com/home-assistant/core/pull/113869/files#r1655580523

* Update homeassistant/helpers/event.py

* coverage

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-06-27 08:50:41 +02:00
Erik Montnemery
f1a57d69cc
Remove deprecated run_immediately flag from integration sensor (#120593) 2024-06-26 20:55:41 +02:00
Erik Montnemery
a36c40a434
Use state_reported events in Riemann sum sensor (#113869) 2024-06-26 13:35:01 +02:00
Marc Mueller
3559755aed
Add import aliases for PLATFORM_SCHEMA (#120445) 2024-06-25 19:16:19 +02:00
dougiteixeira
30f3f1082f
Use the new device helpers in Integral (#120157) 2024-06-22 15:30:38 +02:00
Joakim Plate
6420837d58
Calculate device class as soon as it is known in integral (#119940) 2024-06-21 12:47:57 +02:00
Joakim Plate
ef51fc0d97
Remove code slated for deletion in integral (#119935)
* Remove code slated for deletion in integral
2024-06-19 02:25:11 +02:00
Ron Weikamp
43c69c71c2
Add time based integration trigger to Riemann sum integral helper sensor (#110685)
* Schedule max dt for Riemann Integral sensor

* Simplify validation. Dont integrate on change if either old or new state is not numeric.

* Add validation to integration methods. Rollback requirement for both states to be always numeric.

* Use 0 max_dt for disabling time based updates.

* Use docstring instead of pass keyword in abstract methods.

* Use time_period config validation for max_dt

* Use new_state for scheduling max_dt. Only schedule if new state is numeric.

* Use default 0 (None) for max_dt.

* Rename max_dt to max_age.

* Rollback accidental renaming of different file

* Remove unnecessary and nonsensical max value.

* Improve new config description

* Use DurationSelector in config flow

* Rename new config to max_sub_interval

* Simplify by checking once for the integration strategy

* Use positive time period validation of sub interval in platform schema

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

* Remove return keyword

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

* Simplify scheduling of interval exceeded callback

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

* Improve documentation

* Be more clear about when time based integration is disabled.

* Update homeassistant/components/integration/config_flow.py

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-05-30 20:40:23 +02:00
Joakim Plate
1ef09048e6
Allow the rounding to be optional in integral (#116884) 2024-05-06 20:06:26 +02:00
Sid
0d66d298ec
Enable Ruff RET504 (#114528)
* Enable Ruff RET504

* fix test

* Use noqa instead of cast

* fix sonos RET504

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-04-06 11:07:37 +02:00
Marc Mueller
0f03079065
Update import for EventStateChangedData [i-z] (#114900) 2024-04-04 11:48:29 -10:00
Erik Montnemery
0030c97f59
Tweak integration sensor (#114384)
* Tweak integration sensor

* Improve tests
2024-04-02 09:19:25 +02:00
Sid
6587ee20db
Enable Ruff TRY300 (#114437)
* Enable Ruff TRY300

* Update validation.py

* Address review comments
2024-03-30 10:37:59 +01:00
Ron Weikamp
e1036b3af0
Refactor Riemann sum integral sensor to prepare for time based trigger (#113932)
* Refactor Integration sensor.

* Use local simple function to verify the State is numeric.

* Merge two methods to one.

* Method renaming: _handle_state_change

* Move async_write_ha_state to the caller.

* Add comment on why attr_icon is set to None

* Remove possible None type of State in validation methods.

* Use a dict to map method name to method class.

* Explain derived unit after integration.

* Renaming to _multiply_unit_with_time and elaborate in docstring.

* Set integral unit_of_measurement explicitly to None if source unit_of_measurement is None

* One function for unit of measurement related steps.

* Improve docstring of _multiply_unit_with_time

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

* Apply f-string suggestions from code review

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

* Be more clear in comment about removing the sensors icon default.

* Apply suggestions from code review

Co-authored-by: Diogo Gomes <diogogomes@gmail.com>

* Update homeassistant/components/integration/sensor.py

* Update homeassistant/components/integration/sensor.py

* Update homeassistant/components/integration/sensor.py

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
Co-authored-by: Diogo Gomes <diogogomes@gmail.com>
2024-03-26 19:09:48 +01:00
Marc Mueller
8f1e2f1a7b
Replace EventType with Event [h-i] (#112740) 2024-03-08 19:35:47 +01:00
Marc Mueller
8809d3aa88
Add empty line after module docstring [g-i] (#112699) 2024-03-08 08:52:48 -05:00
Robert Resch
eab4c24f7f
Fix KeyError in derivative and integration (#102294) 2023-10-19 18:22:22 +02:00
Robert Resch
1915fee9ba
Remove "none" in favor of optional select in integration (#101396) 2023-10-11 17:36:53 +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
Ville Skyttä
c287bd1a3b
Remove pylint configs flagged by useless-suppression (#99081) 2023-08-26 17:46:03 +03:00
Diogo Gomes
f96446cb24
Clean up integration sensor (#98552)
always update
2023-08-18 20:45:12 +02:00
Erik Montnemery
045c327928
Move DeviceInfo from entity to device registry (#98149)
* Move DeviceInfo from entity to device registry

* Update integrations
2023-08-10 22:04:26 -04:00
Marc Mueller
5b73bd2f8e
Use EventType for state changed [h-m] (#97117) 2023-07-24 08:01:50 +02:00
Marc Mueller
77f38e33e5
Import names from typing instead of typing_extensions [3.11] (#97065) 2023-07-22 17:03:44 -05:00
dougiteixeira
c6210b68bd
Fix device source for Riemann sum integral (#95622)
Fix Device Source
2023-06-30 14:49:00 -04:00
dougiteixeira
e5afff7f98
Add the device of the source entity in the helper entities for Riemann sum integral (#94727) 2023-06-23 00:04:51 +02:00
Diogo Gomes
b5f582eecc
Make Riemann sum sensors restore last valid state (#93674)
* keep last valid state

* keep last valid state

* typo

* increase coverage

* better error handling

* debug messages

* increase coverage

* remove random log

* don't expose last_valid_state as an attribute
2023-06-02 08:44:36 -04:00
epenet
c475273145
Prevent SensorEntity and RestoreEntity inheritance (#88971) 2023-05-24 12:49:35 +02:00
Diogo Gomes
e100bcfaea
Better handling of source sensor unavailability in Riemman Integration (#93137)
* refactor and increase coverage

* fix log order
2023-05-23 11:19:29 +02:00
Diogo Gomes
23e24d75dc
Don't try to restore unavailable nor unknown states (#92825) 2023-05-09 22:22:06 +02:00
Diogo Gomes
48546c77b5
Follow the unavailability of the source sensor (#91975) 2023-04-25 09:49:58 +02:00
epenet
55a5e17cf2
Use UnitOfTime in integrations (h-s) (#84289) 2022-12-20 13:21:14 +01:00
epenet
4f963cfc64
Improve type hints in integration (#78345) 2022-09-13 22:45:25 +02:00
epenet
23090cb8a2
Improve entity type hints [i] (#77529) 2022-08-30 19:21:08 +02:00
Diogo Gomes
8ca5b5d4a4
Remove icon attribute if device class is set (#76161) 2022-08-04 19:36:37 +02:00
Erik Montnemery
78cb0e24bc
Improve integration sensor's time unit handling (#72759) 2022-05-31 15:51:38 +02:00
RoboMagus
c1ddde3764
Check if attributes are present in new_state before accessing them (#71967)
* Check if attributes are present in new_state before accessing them.

* Early return if new state is None|Unknown|Unavailable

* Removed whitespace at line endings. +black run

* Update test for coverage
2022-05-25 08:44:08 +02:00
Diogo Gomes
852eaa062c
update unit_of_measurement even if unit_of_measurement is known (#69699) 2022-04-30 02:16:05 +03:00
Diogo Gomes
fa28ee1f14
Remove deprecated unit configuration option from integration integration (#69157) 2022-04-13 19:19:34 +02:00
Diogo Gomes
8fe9e364e1
Update integration Riemann sum to use _attr* (#69769)
* move to _attr

* improve debug

* review comment

Co-authored-by: Shay Levy <levyshay1@gmail.com>

Co-authored-by: Shay Levy <levyshay1@gmail.com>
2022-04-10 20:09:33 +03:00
Erik Montnemery
c79b361927
Unsubscribe from listeners when removing integration sensor (#69235) 2022-04-04 11:09:38 +02:00
Diogo Gomes
0cbc29caca
Add unique_id through YAML to the integration component (#68435) 2022-03-20 22:48:11 +01:00
Erik Montnemery
0655ebbd84
Add config flow for integration sensor (#68288) 2022-03-18 09:52:17 +01:00
Franck Nijhof
fa09cf663e
Update black to 22.1.0 (#65788) 2022-02-05 14:19:37 +01:00
Ryan Steckler
b541e91885
Fix units not being pulled from source sensor (#63639) 2022-01-24 15:15:34 +01:00
epenet
178d2848f3
Add setup type hints [i-k] (#63444)
Co-authored-by: epenet <epenet@users.noreply.github.com>
2022-01-05 12:14:13 +01:00
epenet
1692fab664
Use new enums in integration (#61803)
Co-authored-by: epenet <epenet@users.noreply.github.com>
2021-12-14 18:32:33 +01:00
Diogo Gomes
ec9b5df7b3
Ignore None state in state_change_event (#59485) 2021-11-10 22:31:56 -08:00