Skip to content

Commit

Permalink
SN detection fix and improvements (#75)
Browse files Browse the repository at this point in the history
* Fix serial number detection
* Add missing exports
* enhance `set_powersave`

---------

Co-authored-by: Torben Nehmer <[email protected]>
  • Loading branch information
torbennehmer and torbennehmer authored May 9, 2023
1 parent 55dae84 commit 30cc0c2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
* Steff @steff333
* is00709 @is00709
* Gregor Wolf @gregorwolf
* Max Dhom @mdhom
* Max Dhom @mdhom
* Torben Nehmer @torbennehmer
2 changes: 2 additions & 0 deletions e3dc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
__all__ = [
"E3DC",
"AuthenticationError",
"NotAvailableError",
"PollError",
"SendError",
"CommunicationError",
"RSCPAuthenticationError",
"RSCPKeyError",
Expand Down
40 changes: 19 additions & 21 deletions e3dc/_e3dc.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _set_serial(self, serial):
self.pvis = self.pvis or [{"index": 0}]
if not self.serialNumberPrefix:
self.serialNumberPrefix = "S10-"
if self.serialNumber.startswith("74"):
elif self.serialNumber.startswith("74"):
self.model = "S10E_Compact"
self.powermeters = self.powermeters or [{"index": 0}]
self.pvis = self.pvis or [{"index": 0}]
Expand Down Expand Up @@ -1984,27 +1984,25 @@ def set_powersave(self, enable, keepAlive=False):
0 if success
-1 if error
"""
if enable:
res = self.sendRequest(
(
"EMS_REQ_SET_POWER_SETTINGS",
"Container",
[("EMS_POWERSAVE_ENABLED", "UChar8", 1)],
),
keepAlive=keepAlive,
)
else:
res = self.sendRequest(
(
"EMS_REQ_SET_POWER_SETTINGS",
"Container",
[("EMS_POWERSAVE_ENABLED", "UChar8", 0)],
),
keepAlive=keepAlive,
)
res = self.sendRequest(
(
"EMS_REQ_SET_POWER_SETTINGS",
"Container",
[("EMS_POWERSAVE_ENABLED", "UChar8", int(enable))],
),
keepAlive=keepAlive,
)

# validate return code for EMS_RES_POWERSAVE_ENABLED is 0
if res[2][0][2] == 0:
# Returns value of EMS_REQ_SET_POWER_SETTINGS, we get a success flag here,
# that we normalize and push outside.
# [ "EMS_SET_POWER_SETTINGS",
# "Container",
# [
# ["EMS_RES_POWERSAVE_ENABLED", "Char8", 0]
# ]
# ]

if rscpFindTagIndex(res, "EMS_RES_POWERSAVE_ENABLED") == 0:
return 0
else:
return -1
Expand Down

0 comments on commit 30cc0c2

Please sign in to comment.