-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit b41573e
Showing
13 changed files
with
700 additions
and
0 deletions.
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,129 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ |
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,8 @@ | ||
{ | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.nosetestsEnabled": false, | ||
"python.testing.pytestEnabled": true, | ||
"python.envFile": "${workspaceRoot}/vscode.env", | ||
"python.linting.enabled": true, | ||
"python.linting.prospectorEnabled": 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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 dreautall | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Home Assistant Custom Component for Stromnetz Graz | ||
|
||
Home Assistant Custom Component for Stromnetz Graz integration. | ||
|
||
You must have a working login to the [Stromnetz Graz Web Portal](https://webportal.stromnetz-graz.at/) and be able to see your meter readings there. Please refer to Stromnetz Graz how to set up access if you don't have it. | ||
|
||
Please have `IME` mode (15 minute statistic interval) enabled (see [their FAQ](https://www.stromnetz-graz.at/sgg/stromzaehler/intelligenter-stromzaehler/faqs)), otherwise the statistics will not show properly in Home Assistant (see also **Limitations** below!) | ||
|
||
After adding this integration, you are able to see the energy meter readings in the energy dashboard by adding the `stromnetzgraz:energy_consumption:1234` sensor to it (where 1234 is the meter id). You can add multiple sensors if you have multiple (for example for a hot water boiler). | ||
|
||
**Do NOT add `sensor.meter_consumption_1234` or `sensor.meter_reading_1234` to the energy dashboard - it will not work!** | ||
|
||
## Limitations | ||
|
||
If you don't have `IME` mode enabled, the smart meter will only transmit daily summary data. So only the weekly/monthly report will look okay. If you choose to enable `IME` afterwards, please delete and re-add the integration. | ||
|
||
Stromnetz Graz only provides the data for the previous day, there is no live data available. Because of that, the `sensor.meter_...` values are useless for long-time statistics (HA expects sensors to provide live data), but you might find the latest reading value useful elsewhere. The actual statistics are refreshed every six hours in the separate `stromnetzgraz:energy_consumption:...` sensors. | ||
|
||
Because of that limitation, related values on the energy dashboard (CO₂ and price/money) might display strange and wrong values - they all expect live data to function properly. | ||
|
||
## Installation (HACS) | ||
|
||
When using HACS, just add this repository as a [custom repostiory](https://hacs.xyz/docs/navigation/settings#custom-repositories) of category `Integration` with the url `https://github.com/dreautall/ha-stromnetzgraz`. | ||
|
||
## Installation (manual) | ||
|
||
Place the folder `stromnetzgraz` and all it's files in the folder `custom_components` in the config folder of HA (where configuration.yaml is). | ||
|
||
# Release notes | ||
|
||
See [Github Releases](https://github.com/dreautall/ha-stromnetzgraz/releases/). | ||
|
||
# Version | ||
|
||
Can be used with Home Assistant >= `2022.2` |
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,60 @@ | ||
"""The Stromnetz Graz integration.""" | ||
from __future__ import annotations | ||
|
||
import asyncio | ||
import logging | ||
import aiohttp | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.exceptions import ConfigEntryNotReady | ||
from homeassistant.const import Platform | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.const import ( | ||
CONF_USERNAME, | ||
CONF_PASSWORD, | ||
) | ||
|
||
from sngraz import StromNetzGraz, InvalidLogin | ||
from .const import DOMAIN | ||
|
||
PLATFORMS = [Platform.SENSOR] | ||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Set up Stromnetz Graz from a config entry.""" | ||
|
||
conn = StromNetzGraz(entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD]) | ||
|
||
hass.data[DOMAIN] = conn | ||
|
||
try: | ||
await conn.authenticate() | ||
except asyncio.TimeoutError as err: | ||
raise ConfigEntryNotReady from err | ||
except aiohttp.ClientError as err: | ||
_LOGGER.error("Error connecting: %s ", err) | ||
return False | ||
except InvalidLogin as err: | ||
_LOGGER.error("Invalid Auth: %s", err) | ||
return False | ||
except Exception as exp: | ||
_LOGGER.error("Failed to login. %s", exp) | ||
return False | ||
|
||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
|
||
return True | ||
|
||
|
||
async def async_update_entry(hass: HomeAssistant, entry: ConfigEntry) -> None: | ||
"""Update options.""" | ||
await hass.config_entries.async_reload(entry.entry_id) | ||
|
||
|
||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Unload a config entry.""" | ||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): | ||
await hass.data[DOMAIN].close_connection() | ||
|
||
return unload_ok |
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,68 @@ | ||
"""Config flow for Stromnetz Graz integration.""" | ||
from __future__ import annotations | ||
|
||
import logging | ||
import asyncio | ||
from typing import Any | ||
import aiohttp | ||
|
||
import voluptuous as vol | ||
|
||
from homeassistant import config_entries | ||
from homeassistant.const import ( | ||
CONF_USERNAME, | ||
CONF_PASSWORD, | ||
) | ||
from homeassistant.data_entry_flow import FlowResult | ||
|
||
from sngraz import StromNetzGraz, InvalidLogin | ||
from .const import DOMAIN | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
# TODO adjust the data schema to the data that you need | ||
STEP_USER_DATA_SCHEMA = vol.Schema( | ||
{ | ||
vol.Required(CONF_USERNAME): str, | ||
vol.Required(CONF_PASSWORD): str, | ||
} | ||
) | ||
|
||
|
||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): | ||
"""Handle a config flow for Stromnetz Graz.""" | ||
|
||
VERSION = 1 | ||
|
||
async def async_step_user( | ||
self, user_input: dict[str, Any] | None = None | ||
) -> FlowResult: | ||
"""Handle the initial step.""" | ||
if user_input is None: | ||
return self.async_show_form( | ||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA | ||
) | ||
|
||
errors = {} | ||
sn = StromNetzGraz(user_input[CONF_USERNAME], user_input[CONF_PASSWORD]) | ||
try: | ||
await sn.authenticate() | ||
except asyncio.TimeoutError: | ||
errors["base"] = "timeout" | ||
except aiohttp.ClientError: | ||
errors["base"] = "cannot_connect" | ||
except InvalidLogin as err: | ||
errors["base"] = "invalid_login" | ||
_LOGGER.warning("Invalid Login: %s", err) | ||
except Exception: # pylint: disable=broad-except | ||
_LOGGER.exception("Unexpected exception") | ||
errors["base"] = "unknown" | ||
|
||
await sn.close_connection() | ||
|
||
if errors: | ||
return self.async_show_form( | ||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors | ||
) | ||
|
||
return self.async_create_entry(title=sn._username, data=user_input) |
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,4 @@ | ||
"""Constants for the Stromnetz Graz integration.""" | ||
|
||
DATA_HASS_CONFIG = "stromnetzgraz_hass_config" | ||
DOMAIN = "stromnetzgraz" |
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,16 @@ | ||
{ | ||
"domain": "stromnetzgraz", | ||
"name": "Stromnetz Graz", | ||
"config_flow": true, | ||
"documentation": "https://github.com/dreautall/ha-stromnetzgraz", | ||
"requirements": ["pandas==1.4.3", "pyJWT==2.5.0", "stromnetzgraz==0.1.1"], | ||
"ssdp": [], | ||
"zeroconf": [], | ||
"homekit": {}, | ||
"dependencies": [], | ||
"codeowners": [ | ||
"@dreautall" | ||
], | ||
"iot_class": "cloud_polling", | ||
"version": "0.0.1" | ||
} |
Oops, something went wrong.