Commit Graph

61 Commits

Author SHA1 Message Date
G Johansson
67ccdd36fb Allow template in query in sql (#150287) 2025-11-06 17:11:46 +01:00
David Rapan
144fc2a443 Refactor SQL's data conversion (#155598) 2025-11-02 18:49:18 +01:00
G Johansson
b01f5dd24b Raise repairs on platform setup for sql (#153581) 2025-10-04 07:02:36 +02:00
tronikos
d6543480ac Refactor SQL integration (#153135) 2025-09-28 19:03:13 +02:00
G Johansson
1428b41a25 Improve sql config flow (#150757)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2025-09-11 12:27:48 +02:00
G Johansson
277241c4d3 Adjust ManualTriggerSensorEntity to handle timestamp device classes (#145909) 2025-07-18 13:49:12 +02:00
Petro31
ff2c901930 Update trigger based template entity resolution order (#140660)
* Update trigger based template entity resolution order

* add test

* fix most comments

* Move resolution to base class

* add comment

* remove uncessary if statement

* add more tests

* update availability tests

* update logic stage 1

* phase 2 changes

* fix trigger template entity tests

* fix trigger template entities

* command line tests

* sql tests

* scrape test

* update doc string

* add rest tests

* update sql sensor _update signature

* fix scrape test constructor

* move state check to trigger_entity

* fix comments

* Update homeassistant/components/template/trigger_entity.py

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

* Update homeassistant/helpers/trigger_template_entity.py

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

* Update homeassistant/helpers/trigger_template_entity.py

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

* update command_line and rest

* update scrape

* update sql

* add case to command_line sensor

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2025-04-25 13:17:25 +02:00
Erik Montnemery
f83c8de8d3 Update signature of platforms' async_setup_entry (#138201) 2025-02-10 21:08:03 +01:00
G Johansson
877d16273b Fix SQL sensor name (#134414) 2025-01-02 08:51:49 +01:00
Erik Montnemery
533e383d5d Remove unnecessary assignment of Template.hass from sql (#123690) 2024-08-12 15:51:02 +02:00
G Johansson
9b341f5b67 Don't record attributes in sql (#120170) 2024-06-22 19:42:55 +02:00
Sid
c2b3bf3fb9 Enable Ruff RET502 (#115139) 2024-05-21 22:19:33 +02:00
Marc Mueller
930a396712 Add empty line after module docstring [s] (#112704) 2024-03-08 14:33:51 +01:00
G Johansson
5073842514 Fix sql integration no recorder (#111263) 2024-02-24 22:40:49 +01:00
G Johansson
99cf4a6b2d Add rollback on exception that needs rollback in SQL (#104948) 2023-12-08 21:13:37 +01:00
G Johansson
b8f35fb577 Fix missing unique id in SQL (#99641) 2023-09-04 22:31:53 +02:00
G Johansson
61c17291fb Move TemplateEntity to template (#98957)
* Move TemplateEntity to template

* Rename template_entity in helpers
2023-08-24 15:37:04 +02:00
Joost Lekkerkerker
87dd18cc2e Remove obsolete yaml check in SQL (#98950)
* Remove unique id check from SQL

* Remove unique id check from SQL
2023-08-24 12:35:11 +02:00
G Johansson
268e5244f0 Cleanup ManualTriggerSensorEntity (#98629)
* Cleanup ManualTriggerSensorEntity

* ConfigType
2023-08-18 20:19:17 +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
G Johansson
1f11ce63fc Manual trigger entity fix name influence entity_id (#97398) 2023-07-30 18:47:34 +02:00
G Johansson
f610a9b1c9 Fix sql entities not loading (#97316) 2023-07-27 09:24:32 +02:00
G Johansson
4e2b00a443 Refactor SQL with ManualTriggerEntity (#95116)
* First go

* Finalize sensor

* Add tests

* Remove not need _attr_name

* device_class

* _process_manual_data allow Any as value
2023-07-20 11:35:08 +02:00
dougiteixeira
4b1d096e6b Add device_class and state_class in config flow for SQL (#95020)
* Add device_class and state_class in config flow for SQL

* Update when selected NONE_SENTINEL

* Add tests

* Use SensorDeviceClass and SensorStateClass in tests

* Add volatile_organic_compounds_parts in strings selector

* Add test_attributes_from_entry_config

* Remove test_attributes_from_entry_config and complement test_device_state_class

* Add test_attributes_from_entry_config in test_sensor.py
2023-07-08 21:00:22 +02:00
G Johansson
9795699669 Fix db_url issue in SQL (#92324)
* db_url fix

* Add test

* assert entry.options
2023-05-01 16:17:01 +02:00
J. Nick Koston
4366f83ac8 Restore use of local timezone for MariaDB/MySQL in SQL integration (#91313)
* Use local timezone for recorder connection

The fix in #90335 had an unexpected side effect of
using UTC for the timezone since all recorder operations
use UTC. Since only sqlite much use the database executor
we can use a seperate connection pool which uses local time

This also ensures that the engines are disposed of
when Home Assistant is shutdown as previously we
did not cleanly disconnect

* coverage

* fix unclean shutdown in config flow

* tweaks
2023-04-12 20:24:55 -04:00
J. Nick Koston
6e9fcbfec1 Fix false positive in SQL sensor full table scan check (#91134) 2023-04-09 19:45:08 -10:00
J. Nick Koston
53d7e33607 Raise an issue for legacy SQL queries that will cause full table scans (#90971)
* Raise an issue for SQL queries that will cause full table scans

* Raise an issue for SQL queries that will cause full table scans

* Raise an issue for SQL queries that will cause full table scans

* Raise an issue for SQL queries that will cause full table scans

* Update homeassistant/components/sql/sensor.py

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

* coverage

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2023-04-07 22:32:36 -04:00
J. Nick Koston
8096be768d Isolate the sql integration with a separate query cache (#90438)
* Isolate the sql integration with a seperate query cache

If there were a lot of sql integrations they could affect
the performance of the recorder/logbook/history since they
were sharing the same LRU and since the sql sensor updates
frequently it would evict the recorder queries from the
LRU.

* generate in stmt

* avoid double gen

* Revert "avoid double gen"

This reverts commit 6a5aa65268.
2023-03-28 23:54:03 -04:00
J. Nick Koston
5dc96a6952 Fix unbound variable in sql when session setup fails (#90439)
Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/homeassistant/helpers/entity_platform.py", line 304, in _async_setup_platform
    await asyncio.shield(task)
  File "/Users/bdraco/home-assistant/homeassistant/components/sql/sensor.py", line 75, in async_setup_platform
    await async_setup_sensor(
  File "/Users/bdraco/home-assistant/homeassistant/components/sql/sensor.py", line 150, in async_setup_sensor
    sessmaker := await hass.async_add_executor_job(
  File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/bdraco/home-assistant/homeassistant/components/sql/sensor.py", line 205, in _validate_and_get_session_maker_for_db_url
    if sess:
UnboundLocalError: local variable 'sess' referenced before assignment
2023-03-28 23:52:44 -04:00
J. Nick Koston
7098debe09 Fix sql doing I/O in the event loop at startup (#90335)
* Fix sql doing I/O in the event loop

* Fix sql doing I/O in the event loop

* no test query on main db

* fix mocking because it was targeting the recorder
2023-03-26 21:02:24 -04:00
J. Nick Koston
03b204f445 Execute sql queries in the database executor when using the recorder database (#89673) 2023-03-14 10:56:02 +01:00
J. Nick Koston
2cb673db04 Handle bytes data in sql sensors (#89169) 2023-03-13 18:07:05 -10:00
G Johansson
afa58b80bd Default to recorder db for SQL integration (#85436)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-03-13 17:41:32 -10:00
G Johansson
f4cda2dfda Add device_class and state_class to sql (#85418) 2023-03-05 20:30:42 +01:00
Erik Montnemery
94519de8dd Upgrade SQLAlchemy to 2.0.2 (#86436)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-02-08 08:17:32 -06:00
G Johansson
2a965a6e44 SQL reintroduce yaml support (#75205)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-01-07 18:14:36 -10:00
G Johansson
09f37fc522 Migrate SQL to new entity naming style (#75203) 2022-07-14 21:46:26 +02:00
G Johansson
a746d7c1d7 Improve code quality in sql integration (#71705) 2022-05-12 19:40:00 -04:00
J. Nick Koston
18bdc70185 Update sql to prepare for sqlalchemy 2.0 (#71532)
* Update sql to prepare for sqlalchemy 2.0

* config flow as well
2022-05-11 20:45:47 -07:00
G Johansson
5b25b94a22 Fix template error in sql (#71169) 2022-05-01 23:04:03 +03:00
G Johansson
472ffd3bc6 Implement config flow for SQL integration (#68700) 2022-04-24 08:50:32 -10:00
G Johansson
3f9a6bbaa7 Fix sql false warning (#67614) 2022-03-04 08:20:10 -10:00
Paulus Schoutsen
fff74c66ae Fix SQL sensor (#67144) 2022-02-23 16:21:24 -08:00
G Johansson
8da150bd71 Improve code quality sql (#65321) 2022-02-12 08:13:01 -06:00
Diogo Gomes
d5d8eefded Case sensitive SQL queries checks (#62752) 2022-01-07 17:19:30 +01:00
epenet
992f9c3c6c Add setup type hints [s] (part 2) (#63479)
Co-authored-by: epenet <epenet@users.noreply.github.com>
2022-01-05 17:34:18 +01:00
Marc Mueller
f149bef9f3 Use assignment expressions 18 (#57967) 2021-10-18 18:36:35 +02:00
Erik Montnemery
e558b3463e Move temperature conversions to sensor base class (6/8) (#54476)
* Move temperature conversions to entity base class (6/8)

* Fix tests
2021-08-12 17:40:55 +02:00
J. Nick Koston
c10836fcee Upgrade to sqlalchemy 1.4.11 (#49538) 2021-04-21 20:29:36 -10:00