Skip to content

Commit e8f5c12

Browse files
committed
Add bool to controller get project - to control if getting segmented
1 parent 4647c10 commit e8f5c12

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

ihcsdk/ihcclient.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Implements the connection to the ihc controller
33
"""
4+
45
# pylint: disable=bare-except
56
import base64
67
import datetime
@@ -112,7 +113,7 @@ def get_project_in_segments(self, info=None) -> str:
112113
"""Get the ihc project per segments.
113114
Param: info .. reuse existing project info. If not provided, the get_project_info() is called internally.
114115
"""
115-
if info == None:
116+
if info is None:
116117
info = self.get_project_info()
117118
if info:
118119
projectMajor = info.get("projectMajorRevision", 0)
@@ -355,8 +356,8 @@ def __get_value(resource_value):
355356
"WSIntegerValue": lambda v: int(
356357
v.find("./ns2:integer", IHCSoapClient.ihcns).text
357358
),
358-
"WSFloatingPointValue": lambda v: round(
359-
float( v.find("./ns2:floatingPointValue", IHCSoapClient.ihcns).text),2
359+
"WSFloatingPointValue": lambda v: round(
360+
float(v.find("./ns2:floatingPointValue", IHCSoapClient.ihcns).text), 2
360361
),
361362
"WSEnumValue": lambda v: v.find("./ns2:enumName", IHCSoapClient.ihcns).text,
362363
"WSTimerValue": lambda v: int(
@@ -476,7 +477,7 @@ def wait_for_resource_value_changes(self, wait: int = 10):
476477
if change_list is False:
477478
return False
478479
last_changes = {}
479-
for (id, value) in change_list:
480+
for id, value in change_list:
480481
last_changes[id] = value
481482
return last_changes
482483

ihcsdk/ihccontroller.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
Wraps the ihcclient in a more user friendly interface to handle lost connection
33
Notify thread to handle change notifications
44
"""
5+
56
# pylint: disable=invalid-name, bare-except, too-many-instance-attributes
67
from datetime import datetime, timedelta
78
import logging
89
import requests
9-
import sys
1010
import threading
1111
import time
1212
from ihcsdk.ihcclient import IHCSoapClient, IHCSTATE_READY
1313

1414
_LOGGER = logging.getLogger(__name__)
1515

16+
1617
class IHCController:
1718
"""
1819
Implements the notification thread and
@@ -49,17 +50,17 @@ def is_ihc_controller(url: str) -> bool:
4950
return False
5051
return True
5152
except requests.exceptions.RequestException as exp:
52-
_LOGGER.warning( "is_ihc_controller %s",exp)
53+
_LOGGER.warning("is_ihc_controller %s", exp)
5354
return False
5455

5556
def authenticate(self) -> bool:
5657
"""Authenticate and enable the registered notifications"""
5758
with IHCController._mutex:
58-
_LOGGER.debug( "Authenticating login on ihc controller")
59+
_LOGGER.debug("Authenticating login on ihc controller")
5960
if not self.client.authenticate(self._username, self._password):
60-
_LOGGER.debug( "Authentication failed")
61+
_LOGGER.debug("Authentication failed")
6162
return False
62-
_LOGGER.debug( "Authentication was successful")
63+
_LOGGER.debug("Authentication was successful")
6364
if self._ihcevents:
6465
self.client.enable_runtime_notifications(self._ihcevents.keys())
6566
return True
@@ -131,15 +132,18 @@ def set_runtime_value_time(
131132
self.re_authenticate()
132133
return self.client.set_runtime_value_time(ihcid, hours, minutes, seconds)
133134

134-
def get_project(self) -> str:
135+
def get_project(self, insegments: bool = True) -> str:
135136
"""Get the ihc project and make sure controller is ready before"""
136137
with IHCController._mutex:
137138
if self._project is None:
138139
if self.client.get_state() != IHCSTATE_READY:
139140
ready = self.client.wait_for_state_change(IHCSTATE_READY, 10)
140141
if ready != IHCSTATE_READY:
141142
return None
142-
self._project = self.client.get_project_in_segments()
143+
if insegments:
144+
self._project = self.client.get_project_in_segments()
145+
else:
146+
self._project = self.client.get_project()
143147
return self._project
144148

145149
def add_notify_event(self, resourceid: int, callback, delayed=False):
@@ -165,7 +169,7 @@ def add_notify_event(self, resourceid: int, callback, delayed=False):
165169

166170
def _notify_fn(self):
167171
"""The notify thread function."""
168-
_LOGGER.debug( "Starting notify thread")
172+
_LOGGER.debug("Starting notify thread")
169173
while self._notifyrunning:
170174
try:
171175
with IHCController._mutex:
@@ -178,7 +182,7 @@ def _notify_fn(self):
178182
if changes is False:
179183
self.re_authenticate(True)
180184
continue
181-
for (ihcid, value) in changes:
185+
for ihcid, value in changes:
182186
if ihcid in self._ihcevents:
183187
for callback in self._ihcevents[ihcid]:
184188
if (
@@ -188,7 +192,7 @@ def _notify_fn(self):
188192
callback(ihcid, value)
189193
self._ihcvalues[ihcid] = value
190194
except Exception as exp:
191-
_LOGGER.error( "Exception in notify thread %s",exp)
195+
_LOGGER.error("Exception in notify thread %s", exp)
192196
self.re_authenticate(True)
193197

194198
def re_authenticate(self, notify: bool = False) -> bool:
@@ -200,10 +204,12 @@ def re_authenticate(self, notify: bool = False) -> bool:
200204
"""
201205
timeout = datetime.now() + timedelta(seconds=self.reauthenticatetimeout)
202206
while True:
203-
_LOGGER.debug( "Reauthenticating login on ihc controller")
207+
_LOGGER.debug("Reauthenticating login on ihc controller")
204208
if self.authenticate():
205209
return True
206-
_LOGGER.debug( "Authenticate failed - Reauthenticating login on ihc controller in 10 sec")
210+
_LOGGER.debug(
211+
"Authenticate failed - Reauthenticating login on ihc controller in 10 sec"
212+
)
207213

208214
# if called from the notify and notify a cancled we do not want to retry
209215
if notify:

0 commit comments

Comments
 (0)