Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature prepare 0.11 #11

Merged
merged 2 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
# Copyright (c) Ansible Project
# Adapted by SirUli for FroniusSmartmeter
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

name: Bug report
description: Create a report to help us improve

body:
- type: markdown
attributes:
value: |
Verify first that your issue is not [already reported on GitHub][issue search].
Also test if the latest release is affected too.
*Complete **all** sections as described, this form is processed automatically.*

[issue search]: https://github.com/SirUli/FroniusSmartmeter/search?q=is%3Aissue&type=issues


- type: textarea
attributes:
label: Summary
description: Explain the problem briefly below.
placeholder: >-
When I try to do X with the script from the main branch on GitHub, Y
breaks in a way Z under the env E. Here are all the details I know
about this problem...
validations:
required: true

- type: dropdown
attributes:
label: Issue Type
# FIXME: Once GitHub allows defining the default choice, update this
options:
- Bug Report
validations:
required: true

- type: textarea
attributes:
label: FroniusSmartmeter Version
description: >-
Paste the displayed version from the SetupHelper between
triple backticks.
value: |
```console (paste below)

```
validations:
required: true

- type: textarea
attributes:
label: Steps to Reproduce
description: |
Describe exactly how to reproduce the problem.

**HINT:** You can paste https://gist.github.com links for larger files.
validations:
required: true

- type: textarea
attributes:
label: Expected Results
description: >-
Describe what you expected to happen when running the steps above.
placeholder: >-
I expected X to happen because I assumed Y.
that it did not.
validations:
required: true

- type: textarea
attributes:
label: Actual Results
description: |
Describe what actually happened.
...
51 changes: 51 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
# Copyright (c) Ansible Project
# Adapted by SirUli for FroniusSmartmeter
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

name: Feature request
description: Suggest an idea for this project

body:
- type: markdown
attributes:
value: |
Verify first that your issue is not [already reported on GitHub][issue search].
Also test if the latest release is affected too.
*Complete **all** sections as described, this form is processed automatically.*

[issue search]: https://github.com/SirUli/FroniusSmartmeter/search?q=is%3Aissue&type=issues


- type: textarea
attributes:
label: Summary
description: Describe the new feature/improvement briefly below.
placeholder: >-
I am trying to do X with the FroniusSmartmeter from the main branch on GitHub and
I think that implementing a feature Y would be very helpful for me and
every other user because of Z.
validations:
required: true

- type: dropdown
attributes:
label: Issue Type
# FIXME: Once GitHub allows defining the default choice, update this
options:
- Feature Idea
validations:
required: true

- type: textarea
attributes:
label: Additional Information
description: |
Describe how the feature would be used, why it is needed and what it would solve.

**HINT:** You can paste https://gist.github.com links for larger files.
validations:
required: false
...
13 changes: 13 additions & 0 deletions .sourcery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ignore: # A list of paths or files which Sourcery will ignore.
- .git
- venv

rule_settings:
enable:
- default
disable: [] # A list of rule IDs Sourcery will never suggest.
rule_types:
- refactoring
- suggestion
- comment
python_version: '3.8' # A string specifying the lowest Python version your project supports. Sourcery will not suggest refactorings requiring a higher Python version.
42 changes: 17 additions & 25 deletions fronius-smartmeter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
Used https://github.com/victronenergy/velib_python/blob/master/dbusdummyservice.py as basis for this service.
Reading information from the Fronius Smart Meter via http REST API and puts the info on dbus.
"""

import contextlib
try:
import gobject
except ImportError:
Expand All @@ -32,10 +34,8 @@
except ImportError:
import _thread as thread # for daemon = True / Python 3.x

# our own packages
sys.path.insert(
1, os.path.join(os.path.sep, "data", "SetupHelper", "ext", "velib_python")
)
# use an established Victron service to maintain compatiblity
sys.path.insert(1, os.path.join('/opt/victronenergy/dbus-systemcalc-py', 'ext', 'velib_python'))
from vedbus import VeDbusService, VeDbusItemImport

log = logging.getLogger("DbusFroniusSmartMeter")
Expand All @@ -47,7 +47,7 @@ def role_changed(self, path, val):
if val not in self.allowed_roles:
return False
old, inst = self.get_role_instance()
self.settings["instance"] = "%s:%s" % (val, inst)
self.settings["instance"] = f"{val}:{inst}"
return True

def get_role_instance(self):
Expand All @@ -72,13 +72,12 @@ def detect(self):
except socket.timeout:
continue
info = json.loads(data)
sw = info.get("LoggerInfo", {}).get("SoftwareVersion", None)
if sw:
if sw := info.get("LoggerInfo", {}).get("SoftwareVersion", None):
self._firmware = ".".join(
str(s)
for s in [sw["Major"], sw["Minor"], sw["Release"], sw["Build"]]
)
log.info("Found device @%s, firmware %s" % (addr[0], self._firmware))
log.info(f"Found device @{addr[0]}, firmware {self._firmware}")
return addr[0]
return None

Expand All @@ -92,31 +91,26 @@ def detect_dbus(self):
return None
for name in dbusConn.list_names():
if name.startswith("com.victronenergy.pvinverter."):
log.info("Getting IP from %s" % name)
log.info(f"Getting IP from {name}")
conn = VeDbusItemImport(dbusConn, name, "/Mgmt/Connection").get_value()
self._firmware = VeDbusItemImport(
dbusConn, name, "/DataManagerVersion"
).get_value()
log.info("Connection Info: %s, Firmware %s" % (conn, self._firmware))
log.info(f"Connection Info: {conn}, Firmware {self._firmware}")
return conn.split(" ")[0]
return None

def __init__(self, servicename, deviceinstance, ip=None):
self.settings = {"instance": "grid:%d" % deviceinstance}

self._latency = None
self._firmware = "0.1"
self._testdata = None
self._latency = None
if ip == "test":
self._testdata = "testdata/GetMeterRealtimeData.cgi"

self._ip = ip or self.detect_dbus() or self.detect()
self._url = (
"http://"
+ self._ip
+ "/solar_api/v1/GetMeterRealtimeData.cgi?"
+ "Scope=Device&DeviceId=0&DataCollection=MeterRealtimeData"
)
self._url = f"http://{self._ip}/solar_api/v1/GetMeterRealtimeData.cgi?Scope=Device&DeviceId=0&DataCollection=MeterRealtimeData"
data = self._get_meter_data()

log.debug("%s /DeviceInstance = %d" % (servicename, deviceinstance))
Expand All @@ -125,7 +119,8 @@ def __init__(self, servicename, deviceinstance, ip=None):
# Create the management objects, as specified in the ccgx dbus-api document
self._dbusservice.add_path("/Mgmt/ProcessName", __file__)
self._dbusservice.add_path(
"/Mgmt/ProcessVersion", "Running on Python " + platform.python_version()
"/Mgmt/ProcessVersion",
f"Running on Python {platform.python_version()}",
)
self._dbusservice.add_path("/Mgmt/Connection", self._ip)

Expand Down Expand Up @@ -204,15 +199,15 @@ def __init__(self, servicename, deviceinstance, ip=None):
gobject.timeout_add(700, self._safe_update)

def _handlechangedvalue(self, path, value):
log.debug("someone else updated %s to %s" % (path, value))
log.debug(f"someone else updated {path} to {value}")
return True # accept the change

def _safe_update(self):
try:
self._update()
self._retries = 0
except Exception as e:
log.error("Error running update %s" % e)
log.error(f"Error running update {e}")
self._retries += 1
self._failures += 1
if self._retries > 10:
Expand Down Expand Up @@ -351,15 +346,12 @@ def main():
)
args = parser.parse_args()
if args.ip:
log.info("User supplied IP: %s" % args.ip)
log.info(f"User supplied IP: {args.ip}")
else:
log.info("Auto detecting IP")

try:
with contextlib.suppress(NameError):
thread.daemon = True # allow the program to quit
except NameError:
# Python 3
pass

from dbus.mainloop.glib import DBusGMainLoop

Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.10
v1.11