-
Notifications
You must be signed in to change notification settings - Fork 8
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
Mark Hale
committed
Oct 1, 2024
1 parent
5d6bc5e
commit be68300
Showing
5 changed files
with
84 additions
and
52 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
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,20 @@ | ||
import os | ||
import sys | ||
from script_utils import SCRIPT_HOME | ||
sys.path.insert(1, os.path.join(os.path.dirname(__file__), f"{SCRIPT_HOME}/ext")) | ||
|
||
import dbus | ||
|
||
|
||
class SystemBus(dbus.bus.BusConnection): | ||
def __new__(cls): | ||
return dbus.bus.BusConnection.__new__(cls, dbus.bus.BusConnection.TYPE_SYSTEM) | ||
|
||
|
||
class SessionBus(dbus.bus.BusConnection): | ||
def __new__(cls): | ||
return dbus.bus.BusConnection.__new__(cls, dbus.bus.BusConnection.TYPE_SESSION) | ||
|
||
|
||
def dbusConnection(): | ||
return SessionBus() if 'DBUS_SESSION_BUS_ADDRESS' in os.environ else SystemBus() |
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
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,42 @@ | ||
import os | ||
import sys | ||
from script_utils import SCRIPT_HOME | ||
sys.path.insert(1, os.path.join(os.path.dirname(__file__), f"{SCRIPT_HOME}/ext")) | ||
|
||
from dbusmonitor import VE_INTERFACE | ||
|
||
|
||
class ServiceNameResolver: | ||
@staticmethod | ||
def is_name(service_name): | ||
return service_name.startswith("name:") | ||
|
||
@staticmethod | ||
def get_name(service_name): | ||
return service_name[len("name:"):] | ||
|
||
def __init__(self, conn): | ||
self.conn = conn | ||
self._custom_names = None | ||
|
||
def _get_service_names(self): | ||
if self._custom_names is None: | ||
self._custom_names = {} | ||
service_names = self.conn.list_names() | ||
for service_name in service_names: | ||
if service_name.startswith("com.victronenergy."): | ||
try: | ||
custom_name = self.conn.call_blocking(service_name, "/CustomName", VE_INTERFACE, "GetValue", "", []) | ||
self._custom_names[custom_name] = service_name | ||
except: | ||
pass | ||
return self._custom_names | ||
|
||
def resolve_service_name(self, name): | ||
if ServiceNameResolver.is_name(name): | ||
custom_name = ServiceNameResolver.get_name(name) | ||
service_name = self._get_service_names().get(custom_name) | ||
if not service_name: | ||
raise ValueError(f"Unknown name: {custom_name}") | ||
else: | ||
return name |
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 @@ | ||
v3.9 | ||
v3.12 |