-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
251e2b2
commit e60b85e
Showing
23 changed files
with
888 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
|
||
- package-ecosystem: "pip" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
ignore: | ||
# Dependabot should not update Home Assistant as that should match the homeassistant key in hacs.json | ||
- dependency-name: "homeassistant" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
tests: | ||
name: "Python ${{ matrix.python-version }}" | ||
runs-on: "ubuntu-latest" | ||
|
||
strategy: | ||
matrix: | ||
python-version: ["3.10", "3.11", "3.12"] | ||
|
||
steps: | ||
- uses: "actions/checkout@v4" | ||
|
||
- name: Cache pip | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- uses: "actions/setup-python@v5" | ||
with: | ||
python-version: "${{ matrix.python-version }}" | ||
|
||
- name: "Install tox" | ||
run: | | ||
python -m pip install --upgrade tox tox-gh-actions | ||
- name: "Run tox targets for ${{ matrix.python-version }}" | ||
run: python -m tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: "Release" | ||
|
||
on: | ||
release: | ||
types: | ||
- "published" | ||
|
||
permissions: {} | ||
|
||
jobs: | ||
release: | ||
name: "Release" | ||
runs-on: "ubuntu-latest" | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: "Checkout the repository" | ||
uses: "actions/[email protected]" | ||
|
||
- name: "ZIP the integration directory" | ||
shell: "bash" | ||
run: | | ||
cd "${{ github.workspace }}/custom_components/integration_blueprint" | ||
zip integration_blueprint.zip -r ./ | ||
- name: "Upload the ZIP file to the release" | ||
uses: "softprops/[email protected]" | ||
with: | ||
files: ${{ github.workspace }}/custom_components/integration_blueprint/integration_blueprint.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: "Validate" | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
push: | ||
branches: | ||
- "main" | ||
pull_request: | ||
branches: | ||
- "main" | ||
|
||
jobs: | ||
hassfest: # https://developers.home-assistant.io/blog/2020/04/16/hassfest | ||
name: "Hassfest Validation" | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- name: "Checkout the repository" | ||
uses: "actions/[email protected]" | ||
|
||
- name: "Run hassfest validation" | ||
uses: "home-assistant/actions/hassfest@master" | ||
|
||
hacs: # https://github.com/hacs/action | ||
name: "HACS Validation" | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- name: "Checkout the repository" | ||
uses: "actions/[email protected]" | ||
|
||
- name: "Run HACS validation" | ||
uses: "hacs/action@main" | ||
with: | ||
category: "integration" | ||
# Remove this 'ignore' key when you have added brand images for your integration to https://github.com/home-assistant/brands | ||
ignore: "brands" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
__pycache__ | ||
.pytest* | ||
*.egg-info | ||
.coverage | ||
.vscode | ||
coverage.xml | ||
.ruff_cache | ||
/get_annual_example.txt | ||
/get_monthly_exemple.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
repos: | ||
- repo: https://gitlab.com/vojko.pribudic.foss/pre-commit-update | ||
rev: v0.6.0post1 | ||
hooks: | ||
- id: pre-commit-update | ||
|
||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v5.0.0 | ||
hooks: | ||
- id: check-added-large-files | ||
- id: check-ast | ||
- id: check-toml | ||
- id: check-yaml | ||
- id: debug-statements | ||
- id: check-case-conflict | ||
- id: end-of-file-fixer | ||
- id: detect-private-key | ||
- id: mixed-line-ending | ||
- id: requirements-txt-fixer | ||
|
||
- repo: https://github.com/codespell-project/codespell | ||
rev: v2.3.0 | ||
hooks: | ||
- id: codespell | ||
additional_dependencies: | ||
- tomli | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 24.10.0 | ||
hooks: | ||
- id: black | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.7.4 | ||
hooks: | ||
- id: ruff | ||
|
||
- repo: https://github.com/gitleaks/gitleaks | ||
rev: v8.21.2 | ||
hooks: | ||
- id: gitleaks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 - 2024 @Jezza34000 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,48 @@ | ||
# home-assistant-veolia | ||
![veolialogo][veolialogoimg] | ||
|
||
[![GitHub Release][releases-shield]][releases] | ||
[![GitHub Activity][commits-shield]][commits] | ||
[![License][license-shield]](LICENSE) | ||
|
||
![Project Maintenance][maintenance-shield] | ||
|
||
|
||
**This integration will set up the following platforms.** | ||
|
||
Platform | Description | ||
-- | -- | ||
`sensor` | Show info from Veolia API. | ||
|
||
![sensors][sensorsimg] | ||
|
||
## Installation | ||
|
||
1. Using the tool of choice open the directory (folder) for your HA configuration (where you find `configuration.yaml`). | ||
1. If you do not have a `custom_components` directory (folder) there, you need to create it. | ||
1. In the `custom_components` directory (folder) create a new folder called `integration_blueprint`. | ||
1. Download _all_ the files from the `custom_components/integration_blueprint/` directory (folder) in this repository. | ||
1. Place the files you downloaded in the new directory (folder) you created. | ||
1. Restart Home Assistant | ||
1. In the HA UI go to "Configuration" -> "Integrations" click "+" and search for "Integration blueprint" | ||
|
||
## Configuration is done in the UI | ||
|
||
<!----> | ||
|
||
## Contributions are welcome! | ||
|
||
If you want to contribute to this please read the [Contribution guidelines](CONTRIBUTING.md) | ||
|
||
*** | ||
|
||
|
||
[commits-shield]: https://img.shields.io/github/commit-activity/y/ludeeus/integration_blueprint.svg?style=for-the-badge | ||
[commits]: https://github.com/Jezza34000/home-assistant-veolia/commits/main | ||
[exampleimg]: example.png | ||
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg?style=for-the-badge | ||
[license-shield]: https://img.shields.io/github/license/ludeeus/integration_blueprint.svg?style=for-the-badge | ||
[maintenance-shield]: https://img.shields.io/badge/maintainer-%20%40Jezza34000-blue.svg?style=for-the-badge | ||
[releases-shield]: https://img.shields.io/github/release/Jezza34000/integration_blueprint.svg?style=for-the-badge | ||
[releases]: https://github.com/Jezza34000/home-assistant-veolia/releases | ||
[logoimg]: images/veolialogo.png | ||
[appareilimg]: images/sensors.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""The Veolia integration.""" | ||
|
||
import logging | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import Platform | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import device_registry as dev_reg | ||
from homeassistant.helpers.typing import ConfigType | ||
|
||
from .const import DOMAIN | ||
from .coordinator import VeoliaDataUpdateCoordinator | ||
from .data import VeoliaConfigEntry, VeoliaData | ||
from .sensor import LastIndexSensor | ||
|
||
PLATFORMS: list[Platform] = [ | ||
Platform.SENSOR, | ||
Platform.SWITCH, | ||
] | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: | ||
"""Set up the Veolia integration.""" | ||
return True | ||
|
||
|
||
async def async_setup_entry(hass, entry): | ||
"""Set up Veolia from a config entry.""" | ||
coordinator = VeoliaDataUpdateCoordinator(hass) | ||
await coordinator.async_config_entry_first_refresh() | ||
|
||
hass.data.setdefault(DOMAIN, {}) | ||
hass.data[DOMAIN][entry.entry_id] = coordinator | ||
|
||
await hass.config_entries.async_forward_entry_setups(entry, ["sensor"]) | ||
return True | ||
|
||
|
||
async def async_unload_entry( | ||
hass: HomeAssistant, | ||
entry: VeoliaConfigEntry, | ||
) -> bool: | ||
"""Handle removal of an entry.""" | ||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
|
||
|
||
async def async_reload_entry( | ||
hass: HomeAssistant, | ||
entry: VeoliaConfigEntry, | ||
) -> None: | ||
"""Reload config entry.""" | ||
await async_unload_entry(hass, entry) | ||
await async_setup_entry(hass, entry) | ||
|
||
|
||
async def async_remove_config_entry_device( | ||
hass: HomeAssistant, | ||
config_entry: ConfigEntry, | ||
device_entry: dev_reg.DeviceEntry, | ||
) -> bool: | ||
"""Remove a config entry from a device.""" | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""Adds config flow for Veolia.""" | ||
|
||
import voluptuous as vol | ||
from homeassistant import config_entries | ||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME | ||
from veolia_api import VeoliaAPI | ||
from veolia_api.exceptions import VeoliaAPIError | ||
|
||
from .const import DOMAIN | ||
|
||
|
||
class VeoliaFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): | ||
"""Config flow for veolia.""" | ||
|
||
VERSION = 1 | ||
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL | ||
|
||
def __init__(self) -> None: | ||
"""Initialize.""" | ||
self._errors = {} | ||
|
||
async def async_step_user(self, user_input=None) -> dict: | ||
"""Handle a flow initialized by the user.""" | ||
self._errors = {} | ||
|
||
if user_input is not None: | ||
valid = await self._test_credentials( | ||
user_input[CONF_USERNAME], | ||
user_input[CONF_PASSWORD], | ||
) | ||
if valid: | ||
return self.async_create_entry( | ||
title=user_input[CONF_USERNAME], | ||
data=user_input, | ||
) | ||
self._errors["base"] = "auth" | ||
|
||
return await self._show_config_form(user_input) | ||
return await self._show_config_form(user_input) | ||
|
||
async def _show_config_form(self, user_input) -> dict: | ||
"""Show the configuration form to edit location data.""" | ||
return self.async_show_form( | ||
step_id="user", | ||
data_schema=vol.Schema( | ||
{vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}, | ||
), | ||
errors=self._errors, | ||
) | ||
|
||
@staticmethod | ||
async def _test_credentials(username: str, password: str) -> bool: | ||
"""Return true if credentials is valid.""" | ||
try: | ||
api = VeoliaAPI(username, password) | ||
return await api.login() | ||
except VeoliaAPIError: | ||
pass | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Constants for veolia.""" | ||
|
||
from logging import Logger, getLogger | ||
|
||
LOGGER: Logger = getLogger(__package__) | ||
|
||
DOMAIN = "veolia" | ||
NAME = "Veolia" | ||
|
||
# Platforms | ||
SENSOR = "sensor" | ||
PLATFORMS = [SENSOR] | ||
|
||
# API constants keys | ||
LAST_DATA = -1 | ||
IDX = "index" | ||
LITRE = "litre" | ||
CONSO = "consommation" | ||
IDX_FIABILITY = "fiabilite_index" | ||
CONSO_FIABILITY = "fiabilite_conso" | ||
DATA_DATE = "date_releve" |
Oops, something went wrong.