1
mirror of https://github.com/home-assistant/core synced 2024-10-07 10:13:38 +02:00
ha-core/tests
Eugenio Panadero 8d2e72cdf6
Add pvpc electricity prices integration (#32092)
* Add new integration: pvpc_hourly_pricing

to add a sensor with the current hourly price of electricity in Spain.
Configuration is done by selecting one of the 3 reference tariffs, with
1, 2, or 3 billing periods.

* Features config flow, entity registry, RestoreEntity, options flow
  to change tariff, manual yaml config as integration or sensor platform
* Cloud polling sensor with minimal API calls (3/hour at random times)
  and smart retry; fully async
* Only 1 state change / hour (only when the price changes)
* At evening, try to download published tomorrow prices, to always store
  prices info for a window of [3, 27] hours in the future.
* Include useful state attributes to program automations to be run
  at best electric prices.
* Add spanish and english translations.

* Requires `xmltodict` to parse official xml file with hourly prices
for each day.

* Update requirements and add to codeowners

* Avoid passing in hass as a parameter to the entity

Instead, create time change listeners in async_added_to_hass and
call async_generate_entity_id before async_add_entities

* Fix lint issues

* Add tests for config & options flow

* Add tests for manual yaml config

with entity definition as integration and also as a sensor platform

* Fix placement of PLATFORM_SCHEMA and update generated config_flows

* Store prices internally linked to UTC timestamps

- to deal with days with DST changes
- and work with different local timezones

* Add availability to sensor

to 'expire' the sensor if there is no connection available
 and current hour is not in the stored prices.

Also, turn off logging and retrying if prices can't be downloaded
repeatedly, by flagging `data_source_available` as False, so there is no
log-flood mess.

* Add more tests

- to cover behavior in DST changes and complete coverage of sensor logic
- to cover abort config flow

* fix linter

* Better handling of sensor availability and minor enhancements

- Emmit 1 error if data source is marked as unavailable
  (after some retries), and be silent until cloud access is recovered,
  then emmit 1 warning.
- Follow standard of camel_case keys in attributes

* Mock aiosession to not access real API, store fixture data

- Store a set of daily xml files to test sensor logic for all situations
- Mock time and session to run tests with stored API responses
- Add availability test to simulate a lost + recovery of cloud access,
  checking that logging is reasonable: 1 error to flag the continued
  disconnection + 1 warning in recovery.

* Change API endpoint to retrieve JSON data

and remove xmltodict from reqs.

It seems that this endpoint is more reliable than the XML.

* Adapt tests to new API endpoint

* Translate tariff labels to plain English

and sync the default timeout value for all ways of configuration.

* Relax logging levels to meet silver requirements

- 1 warning when becoming unavailable, another warning when recovered.
- Warnings for unexpected TimeoutError or ClientError
- Move the rest to debug level, leaving info for HA internals

Also reduce number of API calls from 3 to 2 calls/hour.

* Fix requirements

* Mod tests to work with timezone Atlantic/Canary

and fix state attributes for timezones != reference, by using 3 price
prefixes: 'price_last_day_XXh', 'price_next_day_XXh' and 'price_XXh',
all generated with local time (backend timezone)

* Try to fix CI tests

* Externalize pvpc data and simplify sensor.py

* add new `aiopvpc` to requirements
* Remove data parsing and price logic from here
* Replace some constant properties with class variables

* Simplify tests for pvpc_hourly_pricing

* Fix updater for options flow

* Updater always reloads
* `tariff` value comes 1st from entry.options, 2nd from entry.data

* Fix lint

* Bump aiopvpc

* Remove options flow and platform setup

- Remove PLATFORM_SCHEMA and async_setup_platform
- Generate config_entry.unique_id with tariff instead of entity_id, in flow step.
- Remove TariffSelectorConfigFlow
- Adapt tests to maintain full coverage

* Fix docstring on test

and rename SENSOR_SCHEMA to SINGLE_SENSOR_SCHEMA to avoid confusion

* Remove timeout manual config, fix entry.options usage, simplify unique_id

* Simplify tests

- No need for a test_setup now, as platform setup is removed and integration
  setup is already used in `test_availability`
- Simplified `_process_time_step`: only one async_fire(EVENT_TIME_CHANGED)/hour

* Fix possible duplicated update

when source is not available.

* Do not access State last_changed for log messages

* Do not update until entity is added to hass

and call to async_update after 1st download or when recovering access, so
async_write_ha_state is not called twice on those.

* minor changes

* Rename method to select current price and make it a callback
2020-03-22 14:25:31 -05:00
..
auth Spelling: Config(uration) (#31782) 2020-02-13 08:27:00 -08:00
components Add pvpc electricity prices integration (#32092) 2020-03-22 14:25:31 -05:00
fixtures Add pvpc electricity prices integration (#32092) 2020-03-22 14:25:31 -05:00
hassfest
helpers Fix script logging with name (#33120) 2020-03-22 13:29:50 +01:00
mock
resources
scripts
test_util
testing_config Add and use percentage constant (#32094) 2020-02-28 11:46:48 -08:00
util Report which data causes JSON serialization error (#31901) 2020-02-17 10:49:42 -08:00
__init__.py
bandit.yaml Enable some more bandit checks (#30857) 2020-01-20 18:44:55 +02:00
common.py Allow managing Lovelace storage dashboards (#32241) 2020-02-28 12:43:17 -08:00
conftest.py Fix check_real location guard (#31890) 2020-02-16 15:33:09 -08:00
test_bootstrap.py Only check frontend for safe mode if frontend wanted to be loa… (#31969) 2020-02-19 15:56:46 +01:00
test_config_entries.py Freeze config entry data (#32615) 2020-03-09 14:07:50 -07:00
test_config.py Fix package default extraction (#33071) 2020-03-20 20:27:37 -07:00
test_core.py Speed up validate_entity_id (#32137) 2020-02-24 08:35:02 -08:00
test_data_entry_flow.py
test_loader.py Extend safe mode (#31927) 2020-02-18 11:52:38 -08:00
test_main.py
test_requirements.py
test_setup.py Fix hassio panel load (#32922) 2020-03-17 17:54:57 -07:00