🏡 Open source home automation that puts local control and privacy first.
Go to file
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
.devcontainer Fixes invalid JSON syntax in devcontainer (#29911) 2019-12-13 12:41:56 +01:00
.github Don't exempt project for PR's for stalebot (#33086) 2020-03-21 15:29:46 +01:00
.vscode Always run flake8 through pre-commit, and with doctests (#28490) 2019-11-06 21:38:00 +02:00
docs Update featured integrations screenshot in README (#30134) 2020-01-07 14:30:52 +01:00
homeassistant Add pvpc electricity prices integration (#32092) 2020-03-22 14:25:31 -05:00
script Remove group as a dependency from entity integrations (#32870) 2020-03-16 14:47:44 -07:00
tests Add pvpc electricity prices integration (#32092) 2020-03-22 14:25:31 -05:00
.coveragerc Remove mopar integration (ADR-0004) (#33066) 2020-03-21 07:09:48 +01:00
.dockerignore Docker cleanup. (#8226) 2017-06-30 08:07:33 -07:00
.gitattributes Fix line endings [skipci] (#12333) 2018-02-11 23:07:28 -08:00
.gitignore Move imports in wake_on_lan component (#28100) 2019-10-22 23:14:52 -07:00
.ignore Include .ignore file for search utilities (#5290) 2017-01-16 22:52:53 -08:00
.pre-commit-config.yaml Run gen_requirements_all and hassfest in pre-commit (#32792) 2020-03-17 21:03:43 +01:00
.readthedocs.yml Drop Python 3.6 support (#29978) 2019-12-16 07:29:19 +01:00
.travis.yml Drop Python 3.6 support (#29978) 2019-12-16 07:29:19 +01:00
CLA.md Update LICENSE.md and CLA.md to reflect the new Apache 2.0 license 2017-01-28 12:12:34 -08:00
CODEOWNERS Add pvpc electricity prices integration (#32092) 2020-03-22 14:25:31 -05:00
CODE_OF_CONDUCT.md Add organization docs 2017-01-22 16:21:20 -08:00
CONTRIBUTING.md Contributing: Add note about feature suggestions and bug tracking (#30225) 2019-12-30 17:54:16 +01:00
Dockerfile.dev Fix dev dockerfile 2019-11-05 21:38:30 +01:00
LICENSE.md Update license to official GitHub template (#16470) 2018-09-07 10:11:51 +02:00
MANIFEST.in Consolidate frontend (#9915) 2017-10-24 19:36:27 -07:00
README.rst Adjusts repository README (#29805) 2019-12-10 09:22:37 +01:00
azure-pipelines-ci.yml Disable codecov because it stop working after renaming. 2020-03-03 16:06:17 +01:00
azure-pipelines-release.yml Update azure-pipelines-release.yml for Azure Pipelines 2020-03-02 22:55:57 +01:00
azure-pipelines-translation.yml Update azure-pipelines-translation.yml for Azure Pipelines 2019-09-05 12:09:21 +02:00
azure-pipelines-wheels.yml Update azure-pipelines-wheels.yml for Azure Pipelines 2020-03-22 19:40:25 +01:00
codecov.yml Update codecov.yml 2020-02-15 13:06:08 -08:00
pylintrc Revert "Use orjson to parse json faster (#32153)" (#32185) 2020-02-25 21:07:16 +01:00
pyproject.toml Drop Python 3.6 support (#29978) 2019-12-16 07:29:19 +01:00
requirements_all.txt Add pvpc electricity prices integration (#32092) 2020-03-22 14:25:31 -05:00
requirements_docs.txt Upgrade Sphinx to 2.3.1 (#30310) 2019-12-31 15:32:26 +01:00
requirements_test.txt Upgrade pre-commit to 2.2.0 (#32737) 2020-03-12 14:44:14 -07:00
requirements_test_all.txt Add pvpc electricity prices integration (#32092) 2020-03-22 14:25:31 -05:00
requirements_test_pre_commit.txt deCONZ - Services normalize bridge id (#31378) 2020-02-01 18:11:05 +01:00
setup.cfg Upgrade mypy to 0.770, tighten config a bit (#32715) 2020-03-12 11:52:20 +01:00
setup.py Reflect new repo name (#32611) 2020-03-09 12:46:52 -07:00
tox.ini Run mypy through a pyenv/virtualenv enabler wrapper script (#30922) 2020-02-01 07:12:46 -08:00

README.rst

Home Assistant |Chat Status|
=================================================================================

Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server.

Check out `home-assistant.io <https://home-assistant.io>`__ for `a
demo <https://home-assistant.io/demo/>`__, `installation instructions <https://home-assistant.io/getting-started/>`__,
`tutorials <https://home-assistant.io/getting-started/automation-2/>`__ and `documentation <https://home-assistant.io/docs/>`__.

|screenshot-states|

Featured integrations
---------------------

|screenshot-components|

The system is built using a modular approach so support for other devices or actions can be implemented easily. See also the `section on architecture <https://developers.home-assistant.io/docs/en/architecture_index.html>`__ and the `section on creating your own
components <https://developers.home-assistant.io/docs/en/creating_component_index.html>`__.

If you run into issues while using Home Assistant or during development
of a component, check the `Home Assistant help section <https://home-assistant.io/help/>`__ of our website for further help and information.

.. |Chat Status| image:: https://img.shields.io/discord/330944238910963714.svg
   :target: https://discord.gg/c5DvZ4e
.. |screenshot-states| image:: https://raw.github.com/home-assistant/home-assistant/master/docs/screenshots.png
   :target: https://home-assistant.io/demo/
.. |screenshot-components| image:: https://raw.github.com/home-assistant/home-assistant/dev/docs/screenshot-components.png
   :target: https://home-assistant.io/integrations/