solaredge2mqtt 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- solaredge2mqtt-0.1.1/LICENSE +21 -0
- solaredge2mqtt-0.1.1/MANIFEST.in +16 -0
- solaredge2mqtt-0.1.1/PKG-INFO +90 -0
- solaredge2mqtt-0.1.1/README.md +65 -0
- solaredge2mqtt-0.1.1/THIRD-PARTY-NOTICES +37 -0
- solaredge2mqtt-0.1.1/requirements.txt +5 -0
- solaredge2mqtt-0.1.1/setup.cfg +15 -0
- solaredge2mqtt-0.1.1/setup.py +42 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt/__init__.py +3 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt/__main__.py +4 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt/_version.py +21 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt/core/__init__.py +0 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt/core/logging.py +33 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt/core/settings.py +72 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt/models/__init__.py +15 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt/models/base.py +32 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt/models/sunspec.py +243 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt/service.py +295 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt.egg-info/PKG-INFO +90 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt.egg-info/SOURCES.txt +24 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt.egg-info/dependency_links.txt +1 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt.egg-info/entry_points.txt +2 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt.egg-info/requires.txt +5 -0
- solaredge2mqtt-0.1.1/solaredge2mqtt.egg-info/top_level.txt +1 -0
- solaredge2mqtt-0.1.1/versioneer.py +2277 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 learningHouse
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Include the README
|
|
2
|
+
include *.md
|
|
3
|
+
|
|
4
|
+
# Include the license file
|
|
5
|
+
include LICENSE
|
|
6
|
+
|
|
7
|
+
# Include information about third party licensors
|
|
8
|
+
include THIRD-PARTY-NOTICES
|
|
9
|
+
|
|
10
|
+
include requirements.txt
|
|
11
|
+
|
|
12
|
+
recursive-include solaredge2mqtt *.py
|
|
13
|
+
|
|
14
|
+
# Include information about version
|
|
15
|
+
include versioneer.py
|
|
16
|
+
include solaredge2mqtt/_version.py
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: solaredge2mqtt
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Read data from SolarEdge Inverter and publish it to MQTT
|
|
5
|
+
Home-page: https://github.com/deroetzi/solaredge2mqtt
|
|
6
|
+
Author: Johannes Ott
|
|
7
|
+
Author-email: info@johannes-ott.net
|
|
8
|
+
Project-URL: Bug Reports, https://github.com/deroetzi/solaredge2mqtt/issues
|
|
9
|
+
Keywords: smart home
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Topic :: Home Automation
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Natural Language :: English
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Requires-Python: >=3.10, <4
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: solaredge_modbus==0.8.0
|
|
21
|
+
Requires-Dist: pydantic==2.3.0
|
|
22
|
+
Requires-Dist: pydantic-settings==2.0.3
|
|
23
|
+
Requires-Dist: loguru==0.7.2
|
|
24
|
+
Requires-Dist: gmqtt==0.6.13
|
|
25
|
+
|
|
26
|
+
# SolarEdge 2 MQTT Service
|
|
27
|
+
[](https://github.com/DerOetzi/solaredge2mqtt/blob/main/LICENSE) [](https://github.com/DerOetzi/solaredge2mqtt/releases/latest) [](https://github.com/DerOetzi/solaredge2mqtt/actions/workflows/build_project.yml) [](https://pypi.org/project/solaredge2mqtt/)
|
|
28
|
+
|
|
29
|
+
The SolarEdge2MQTT service is a project designed to read data from a SolarEdge inverter and publish it to an MQTT broker. The service is useful for integrating SolarEdge inverters into home automation systems or other applications that use MQTT for data exchange. It provides real-time monitoring of power flow and other parameters from the inverter. The project is open-source and can be customized to suit specific needs.
|
|
30
|
+
|
|
31
|
+
*The SolarEdge2MQTT service is currently in an early stage of development. While it is functional and can be used to read data from a SolarEdge inverter and publish it to an MQTT broker, it is still undergoing active development. Features may be added, removed, or changed, and there may be bugs. Users should be aware of this and use the service with caution. Despite its early state, the project is open-source and contributions are welcome.*
|
|
32
|
+
|
|
33
|
+
## Installation and Configuration
|
|
34
|
+
|
|
35
|
+
Install and update using pip.
|
|
36
|
+
```
|
|
37
|
+
pip install -U solaredge2mqtt
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Install and update using docker
|
|
41
|
+
```
|
|
42
|
+
docker pull ghcr.io/deroetzi/solaredge2mqtt:latest
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Service configuration
|
|
46
|
+
|
|
47
|
+
The service is configured by environment variables. The following options can be set:
|
|
48
|
+
|
|
49
|
+
Environment Variable | default (production/development) | description
|
|
50
|
+
-------------------------------- | -------------------------------- | ------------------------------------------------------
|
|
51
|
+
SE2MQTT_ENVIRONMENT | production | Choose the default environment settings: production or development.
|
|
52
|
+
SE2MQTT_MODBUS_HOST | *None* | IP address of your inverter
|
|
53
|
+
SE2MQTT_MODBUS_PORT | 1502 | Modbus port of your inverter
|
|
54
|
+
SE2MQTT_MODBUS_TIMEOUT | 1 | Timeout for the modbus connection
|
|
55
|
+
SE2MQTT_MODBUS_UNIT | 1 | Modbus unit address
|
|
56
|
+
SE2MQTT_CLIENT_ID | solaredge2mqtt | MQTT client id
|
|
57
|
+
SE2MQTT_BROKER | *None* | IP address of your MQTT broker
|
|
58
|
+
SE2MQTT_PORT | 1883 | Port of your MQTT broker
|
|
59
|
+
SE2MQTT_USERNAME | *None* | Username to authenticate to your MQTT broker
|
|
60
|
+
SE2MQTT_PASSWORD | *None* | Password to authenticate to your MQTT broker
|
|
61
|
+
SE2MQTT_TOPIC_PREFIX | solaredge | SolarEdge2MQTT will use this as prefix topic
|
|
62
|
+
SE2MQTT_INTERVAL | 5 | Interval between requests in seconds
|
|
63
|
+
SE2MQTT_LOGGING_LEVEL | INFO | Set logging level to DEBUG, INFO, WARNING, ERROR, CRITICAL
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
#### Example configuration
|
|
67
|
+
|
|
68
|
+
You can download [.env.example](https://raw.githubusercontent.com/DerOetzi/solaredge2mqtt/master/core/.env.example) and rename it to `.env`. Inside, you can modify the default configuration values to meet your needs in this file.
|
|
69
|
+
|
|
70
|
+
## Run the service
|
|
71
|
+
|
|
72
|
+
### In the console
|
|
73
|
+
|
|
74
|
+
Copy the [.env.example](https://raw.githubusercontent.com/DerOetzi/solaredge2mqtt/master/core/.env.example) file to .env and modify it according to your needs.
|
|
75
|
+
|
|
76
|
+
Then, simply run `solaredge2mqtt` to start the service.
|
|
77
|
+
|
|
78
|
+
### With docker:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
docker run --name solaredge2mqtt --rm \
|
|
82
|
+
-e "SE2MQTT_MODBUS_HOST=<INVERTER_IP>" \
|
|
83
|
+
-e "SE2MQTT_BROKER=<BROKER_IP>" \
|
|
84
|
+
-e "SE2MQTT_USERNAME=<MQTT_USERNAME>" \
|
|
85
|
+
-e "SE2MQTT_PASSWORD=<MQTT_PASSWORD>" \
|
|
86
|
+
-e "TZ=Europe/Berlin" \
|
|
87
|
+
ghcr.io/deroetzi/solaredge2mqtt:latest
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Add optional environment arguments from above to fit to your setup.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# SolarEdge 2 MQTT Service
|
|
2
|
+
[](https://github.com/DerOetzi/solaredge2mqtt/blob/main/LICENSE) [](https://github.com/DerOetzi/solaredge2mqtt/releases/latest) [](https://github.com/DerOetzi/solaredge2mqtt/actions/workflows/build_project.yml) [](https://pypi.org/project/solaredge2mqtt/)
|
|
3
|
+
|
|
4
|
+
The SolarEdge2MQTT service is a project designed to read data from a SolarEdge inverter and publish it to an MQTT broker. The service is useful for integrating SolarEdge inverters into home automation systems or other applications that use MQTT for data exchange. It provides real-time monitoring of power flow and other parameters from the inverter. The project is open-source and can be customized to suit specific needs.
|
|
5
|
+
|
|
6
|
+
*The SolarEdge2MQTT service is currently in an early stage of development. While it is functional and can be used to read data from a SolarEdge inverter and publish it to an MQTT broker, it is still undergoing active development. Features may be added, removed, or changed, and there may be bugs. Users should be aware of this and use the service with caution. Despite its early state, the project is open-source and contributions are welcome.*
|
|
7
|
+
|
|
8
|
+
## Installation and Configuration
|
|
9
|
+
|
|
10
|
+
Install and update using pip.
|
|
11
|
+
```
|
|
12
|
+
pip install -U solaredge2mqtt
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Install and update using docker
|
|
16
|
+
```
|
|
17
|
+
docker pull ghcr.io/deroetzi/solaredge2mqtt:latest
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Service configuration
|
|
21
|
+
|
|
22
|
+
The service is configured by environment variables. The following options can be set:
|
|
23
|
+
|
|
24
|
+
Environment Variable | default (production/development) | description
|
|
25
|
+
-------------------------------- | -------------------------------- | ------------------------------------------------------
|
|
26
|
+
SE2MQTT_ENVIRONMENT | production | Choose the default environment settings: production or development.
|
|
27
|
+
SE2MQTT_MODBUS_HOST | *None* | IP address of your inverter
|
|
28
|
+
SE2MQTT_MODBUS_PORT | 1502 | Modbus port of your inverter
|
|
29
|
+
SE2MQTT_MODBUS_TIMEOUT | 1 | Timeout for the modbus connection
|
|
30
|
+
SE2MQTT_MODBUS_UNIT | 1 | Modbus unit address
|
|
31
|
+
SE2MQTT_CLIENT_ID | solaredge2mqtt | MQTT client id
|
|
32
|
+
SE2MQTT_BROKER | *None* | IP address of your MQTT broker
|
|
33
|
+
SE2MQTT_PORT | 1883 | Port of your MQTT broker
|
|
34
|
+
SE2MQTT_USERNAME | *None* | Username to authenticate to your MQTT broker
|
|
35
|
+
SE2MQTT_PASSWORD | *None* | Password to authenticate to your MQTT broker
|
|
36
|
+
SE2MQTT_TOPIC_PREFIX | solaredge | SolarEdge2MQTT will use this as prefix topic
|
|
37
|
+
SE2MQTT_INTERVAL | 5 | Interval between requests in seconds
|
|
38
|
+
SE2MQTT_LOGGING_LEVEL | INFO | Set logging level to DEBUG, INFO, WARNING, ERROR, CRITICAL
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
#### Example configuration
|
|
42
|
+
|
|
43
|
+
You can download [.env.example](https://raw.githubusercontent.com/DerOetzi/solaredge2mqtt/master/core/.env.example) and rename it to `.env`. Inside, you can modify the default configuration values to meet your needs in this file.
|
|
44
|
+
|
|
45
|
+
## Run the service
|
|
46
|
+
|
|
47
|
+
### In the console
|
|
48
|
+
|
|
49
|
+
Copy the [.env.example](https://raw.githubusercontent.com/DerOetzi/solaredge2mqtt/master/core/.env.example) file to .env and modify it according to your needs.
|
|
50
|
+
|
|
51
|
+
Then, simply run `solaredge2mqtt` to start the service.
|
|
52
|
+
|
|
53
|
+
### With docker:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
docker run --name solaredge2mqtt --rm \
|
|
57
|
+
-e "SE2MQTT_MODBUS_HOST=<INVERTER_IP>" \
|
|
58
|
+
-e "SE2MQTT_BROKER=<BROKER_IP>" \
|
|
59
|
+
-e "SE2MQTT_USERNAME=<MQTT_USERNAME>" \
|
|
60
|
+
-e "SE2MQTT_PASSWORD=<MQTT_PASSWORD>" \
|
|
61
|
+
-e "TZ=Europe/Berlin" \
|
|
62
|
+
ghcr.io/deroetzi/solaredge2mqtt:latest
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Add optional environment arguments from above to fit to your setup.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
ThirdPartyNotices
|
|
2
|
+
-----------------
|
|
3
|
+
Solaredge 2 MQTT uses third-party software or other resources that
|
|
4
|
+
may be distributed under licenses different from deroetzi/se2mqtt
|
|
5
|
+
software.
|
|
6
|
+
In the event that we overlooked to list a required notice, please bring this
|
|
7
|
+
to our attention by opening an issue on:
|
|
8
|
+
https://github.com/deroetzi/se2mqtt/issues
|
|
9
|
+
|
|
10
|
+
Components:
|
|
11
|
+
-----------
|
|
12
|
+
|
|
13
|
+
Component: Python3
|
|
14
|
+
Licensor: Python Software Foundation
|
|
15
|
+
Website: https://www.python.org
|
|
16
|
+
License: PSF License
|
|
17
|
+
|
|
18
|
+
Component: Pydantic
|
|
19
|
+
Licensor: Samuel Colvin
|
|
20
|
+
Website: https://github.com/samuelcolvin/pydantic
|
|
21
|
+
License: MIT License
|
|
22
|
+
|
|
23
|
+
Component: Loguru
|
|
24
|
+
Licensor: Loguru Contributors
|
|
25
|
+
Website: https://github.com/Delgan/loguru
|
|
26
|
+
License: MIT License
|
|
27
|
+
|
|
28
|
+
Component: solaredge_modbus
|
|
29
|
+
Licensor: nmakel
|
|
30
|
+
Website: https://github.com/nmakel/solaredge_modbus
|
|
31
|
+
License: MIT License
|
|
32
|
+
|
|
33
|
+
Component: GMQTT
|
|
34
|
+
Licensor: Mikhail Turchunovich
|
|
35
|
+
Website: https://github.com/wialon/gmqtt
|
|
36
|
+
License: MIT License
|
|
37
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[metadata]
|
|
2
|
+
license_files = LICENSE
|
|
3
|
+
|
|
4
|
+
[versioneer]
|
|
5
|
+
VCS = git
|
|
6
|
+
style = pep440
|
|
7
|
+
versionfile_source = solaredge2mqtt/_version.py
|
|
8
|
+
versionfile_build = solaredge2mqtt/_version.py
|
|
9
|
+
tag_prefix = v
|
|
10
|
+
parentdir_prefix =
|
|
11
|
+
|
|
12
|
+
[egg_info]
|
|
13
|
+
tag_build =
|
|
14
|
+
tag_date = 0
|
|
15
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from os import path
|
|
2
|
+
|
|
3
|
+
import setuptools
|
|
4
|
+
|
|
5
|
+
import versioneer
|
|
6
|
+
|
|
7
|
+
with open("README.md", "r", encoding="utf-8") as fh:
|
|
8
|
+
long_description = fh.read()
|
|
9
|
+
|
|
10
|
+
with open("requirements.txt", "r", encoding="utf-8") as fh:
|
|
11
|
+
requirements = fh.readlines()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
packages = setuptools.find_packages(exclude=["tests"])
|
|
15
|
+
|
|
16
|
+
setuptools.setup(
|
|
17
|
+
name="solaredge2mqtt",
|
|
18
|
+
version=versioneer.get_version(),
|
|
19
|
+
cmdclass=versioneer.get_cmdclass(),
|
|
20
|
+
description="Read data from SolarEdge Inverter and publish it to MQTT",
|
|
21
|
+
long_description=long_description,
|
|
22
|
+
long_description_content_type="text/markdown",
|
|
23
|
+
url="https://github.com/deroetzi/solaredge2mqtt",
|
|
24
|
+
author="Johannes Ott",
|
|
25
|
+
author_email="info@johannes-ott.net",
|
|
26
|
+
classifiers=[
|
|
27
|
+
"Development Status :: 4 - Beta",
|
|
28
|
+
"Topic :: Home Automation",
|
|
29
|
+
"License :: OSI Approved :: MIT License",
|
|
30
|
+
"Natural Language :: English",
|
|
31
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
32
|
+
"Programming Language :: Python :: 3.10",
|
|
33
|
+
"Programming Language :: Python :: 3.11",
|
|
34
|
+
],
|
|
35
|
+
keywords="smart home",
|
|
36
|
+
packages=packages,
|
|
37
|
+
include_package_data=True,
|
|
38
|
+
python_requires=">=3.10, <4",
|
|
39
|
+
install_requires=[req for req in requirements if not req.startswith("#")],
|
|
40
|
+
entry_points={"console_scripts": ["solaredge2mqtt=solaredge2mqtt.service:run"]},
|
|
41
|
+
project_urls={"Bug Reports": "https://github.com/deroetzi/solaredge2mqtt/issues"},
|
|
42
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
# This file was generated by 'versioneer.py' (0.29) from
|
|
3
|
+
# revision-control system data, or from the parent directory name of an
|
|
4
|
+
# unpacked source archive. Distribution tarballs contain a pre-generated copy
|
|
5
|
+
# of this file.
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
version_json = '''
|
|
10
|
+
{
|
|
11
|
+
"date": "2023-12-17T21:22:44+0100",
|
|
12
|
+
"dirty": false,
|
|
13
|
+
"error": null,
|
|
14
|
+
"full-revisionid": "bcbec905adce10daca8fe3026b6157af112eca26",
|
|
15
|
+
"version": "0.1.1"
|
|
16
|
+
}
|
|
17
|
+
''' # END VERSION_JSON
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_versions():
|
|
21
|
+
return json.loads(version_json)
|
|
File without changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from loguru import logger
|
|
5
|
+
|
|
6
|
+
from solaredge2mqtt.models.base import EnumModel
|
|
7
|
+
|
|
8
|
+
LOGGING_DEVICE_INFO = "{device} ({info.manufacturer} {info.model} {info.serialnumber})"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class LoggingLevelEnum(EnumModel):
|
|
12
|
+
DEBUG = "DEBUG", logging.DEBUG
|
|
13
|
+
INFO = "INFO", logging.INFO
|
|
14
|
+
WARNING = "WARNING", logging.WARNING
|
|
15
|
+
ERROR = "ERROR", logging.ERROR
|
|
16
|
+
CRITICAL = "CRITICAL", logging.CRITICAL
|
|
17
|
+
|
|
18
|
+
def __init__(self, description: str, level: int):
|
|
19
|
+
# pylint: disable=super-init-not-called
|
|
20
|
+
self._description: str = description
|
|
21
|
+
self._level: int = level
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def description(self) -> str:
|
|
25
|
+
return self._description
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def level(self) -> int:
|
|
29
|
+
return self._level
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def initialize_logging(logging_level: LoggingLevelEnum) -> None:
|
|
33
|
+
logger.configure(handlers=[{"sink": sys.stdout, "level": logging_level.level}])
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from pydantic import Field
|
|
2
|
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
3
|
+
|
|
4
|
+
from solaredge2mqtt.core.logging import LoggingLevelEnum
|
|
5
|
+
from solaredge2mqtt.models.base import EnumModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ServiceSettings(BaseSettings):
|
|
9
|
+
environment: str = "production"
|
|
10
|
+
|
|
11
|
+
modbus_host: str
|
|
12
|
+
modbus_port: int = Field(1502)
|
|
13
|
+
modbus_timeout: int = Field(1)
|
|
14
|
+
modbus_unit: int = Field(1)
|
|
15
|
+
|
|
16
|
+
client_id: str = Field("solaredge2mqtt")
|
|
17
|
+
broker: str
|
|
18
|
+
port: int = Field(1883)
|
|
19
|
+
username: str
|
|
20
|
+
password: str
|
|
21
|
+
topic_prefix: str = Field("solaredge")
|
|
22
|
+
|
|
23
|
+
interval: int = Field(5)
|
|
24
|
+
|
|
25
|
+
logging_level: LoggingLevelEnum = LoggingLevelEnum.INFO
|
|
26
|
+
|
|
27
|
+
model_config = SettingsConfigDict(
|
|
28
|
+
env_file=".env",
|
|
29
|
+
env_prefix="se2mqtt_",
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class DevelopmentSettings(ServiceSettings):
|
|
34
|
+
debug: bool = Field(True)
|
|
35
|
+
|
|
36
|
+
environment: str = "development"
|
|
37
|
+
|
|
38
|
+
model_config = SettingsConfigDict(
|
|
39
|
+
env_file=".env",
|
|
40
|
+
env_prefix="se2mqtt_",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class ServiceEnvironment(EnumModel):
|
|
45
|
+
PROD = "production", ServiceSettings
|
|
46
|
+
DEV = "development", DevelopmentSettings
|
|
47
|
+
|
|
48
|
+
def __init__(self, description: str, settings_class: ServiceSettings):
|
|
49
|
+
# pylint: disable=super-init-not-called
|
|
50
|
+
self._description: str = description
|
|
51
|
+
self._settings_class: ServiceSettings = settings_class
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def description(self) -> str:
|
|
55
|
+
return self._description
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def settings_class(self) -> ServiceSettings:
|
|
59
|
+
return self._settings_class
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class ServiceBaseSettings(BaseSettings):
|
|
63
|
+
environment: ServiceEnvironment = ServiceEnvironment.PROD
|
|
64
|
+
|
|
65
|
+
model_config = SettingsConfigDict(
|
|
66
|
+
env_file=".env", env_prefix="se2mqtt_", extra="ignore"
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def service_settings() -> ServiceSettings:
|
|
71
|
+
environment = ServiceBaseSettings().environment
|
|
72
|
+
return environment.settings_class()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class PowerFlow(BaseModel):
|
|
5
|
+
pv_production: int
|
|
6
|
+
inverter: int
|
|
7
|
+
inverter_consumption: int
|
|
8
|
+
inverter_delivery: int
|
|
9
|
+
house_consumption: int
|
|
10
|
+
grid: int
|
|
11
|
+
grid_consumption: int
|
|
12
|
+
grid_delivery: int
|
|
13
|
+
battery: int
|
|
14
|
+
battery_charge: int
|
|
15
|
+
battery_discharge: int
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from pydantic import model_serializer
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class EnumModel(Enum):
|
|
6
|
+
def __new__(cls, *args):
|
|
7
|
+
obj = object.__new__(cls)
|
|
8
|
+
obj._value_ = args[0]
|
|
9
|
+
return obj
|
|
10
|
+
|
|
11
|
+
def __str__(self) -> str:
|
|
12
|
+
return str(self._value_)
|
|
13
|
+
|
|
14
|
+
def __repr__(self) -> str:
|
|
15
|
+
return str(self._value_)
|
|
16
|
+
|
|
17
|
+
def __eq__(self, obj) -> bool:
|
|
18
|
+
return isinstance(obj, self.__class__) and self.value == obj.value
|
|
19
|
+
|
|
20
|
+
def __hash__(self):
|
|
21
|
+
return hash(self.value)
|
|
22
|
+
|
|
23
|
+
@classmethod
|
|
24
|
+
def from_string(cls, value: str):
|
|
25
|
+
for item in cls.__members__.values():
|
|
26
|
+
if item.value == value:
|
|
27
|
+
return item
|
|
28
|
+
raise ValueError(f"No enum value {value} found.")
|
|
29
|
+
|
|
30
|
+
@model_serializer
|
|
31
|
+
def serialize(self):
|
|
32
|
+
return self.value
|