Skip to content

Commit

Permalink
replace suds to zeep for chargepoint interface in platform.driver
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyilin123 authored and craig8 committed Aug 12, 2024
1 parent adf79e1 commit 6b77994
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ activated environment:

::

pip install suds-jurko
pip install zeep

Alternatively requirements can be installed from requirements.txt using:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,6 @@ def parse_config(self, config_dict, registry_config_str):
return

for regDef in registry_config_str:
print(regDef)
_log.debug(f'RegDef is {regDef}')
# Skip lines that have no address yet.
if not regDef['Attribute Name']:
continue
Expand Down Expand Up @@ -559,7 +557,7 @@ def parse_config(self, config_dict, registry_config_str):
description=description,
port_number=port_num,
username=config_dict['username'],
timeout=config_dict['cacheExpiration']
timeout=config_dict.get('cacheExpiration',0)
)

self.insert_register(register)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@
import gevent.event
import gevent.queue
import logging
#import suds
import zeep
from gevent import monkey
from .service import CPAPIException
from datetime import datetime, timedelta

monkey.patch_all()
_log = logging.getLogger(__name__)
#SERVICE_WSDL_URL = "https://webservices.chargepoint.com/cp_api_5.0.wsdl"
SERVICE_WSDL_URL = "http://localhost:8080/cp_api_5.1.wsdl"

SERVICE_WSDL_URL = "https://webservices.chargepoint.com/cp_api_5.1.wsdl"
# Queue for Web API requests and responses. It is managed by the long running
# web_service() greenlet.
web_service_queue = gevent.queue.Queue()
Expand Down Expand Up @@ -254,7 +252,6 @@ def web_service():
web_cache[item_key] = cache_item

if not client_set:
#client_set.add(suds.client.Client(SERVICE_WSDL_URL))
client_set.add(zeep.Client(SERVICE_WSDL_URL))
client = client_set.pop()
gevent.spawn(web_call, item, client)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from . import service as cps
#import suds
import zeep
import io

Expand Down Expand Up @@ -177,6 +176,5 @@
else:
print("Some other error happened")

#except suds.WebFault as a:
except zeep.exception.Fault as e:
print("Sorry, your API credentials are invalid. Please contact Chargepoint for assistance.")
Original file line number Diff line number Diff line change
@@ -1 +1 @@
suds-jurko==0.6
zeep==4.2.1
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
# ===----------------------------------------------------------------------===
# }}}

#import suds.client
#import suds.wsse
import zeep
from zeep.wsse.username import UsernameToken
from zeep import Settings
import logging

logger = logging.getLogger('chargepoint')

SERVICE_WSDL_URL = "https://webservices.chargepoint.com/cp_api_5.0.wsdl"

SERVICE_WSDL_URL = "https://webservices.chargepoint.com/cp_api_5.1.wsdl"
CPAPI_SUCCESS = '100'

XMPP_EVENTS = [
Expand Down Expand Up @@ -158,13 +156,13 @@ class CPStation:
"""Wrapper around the getStations() return by Chargepoint API.
Data surrounding a Chargepoint Station can generally be categorized as static or dynamic. Chargepoint API has two
basic calls, getLoad and getStation, that each return station data. getLoad returns the stationLoadData SUDS
object, and getStation returns the stationDataExtended SUDS object. These are each kept as separate meta-data
basic calls, getLoad and getStation, that each return station data. getLoad returns the stationLoadData object,
and getStation returns the stationDataExtended object. These are each kept as separate meta-data
parameters.
:param cps: Chargepoint Service object.
:param sld: stationLoadData SUDS object.
:param sde: stationDataExtended SUDS object.
:param sld: stationLoadData object.
:param sde: stationDataExtended object.
(stationDataExtended){
stationID = "1:00001"
Expand Down Expand Up @@ -760,8 +758,8 @@ class CPService:
"""
Python wrapper around the Chargepoint WebServices API.
Current Version: 5.0
Docs: ChargePoint_Web_Services_API_Guide_Ver4.1_Rev5.pdf
Current Version: 5.1
Docs: ChargePoint_Web_Services_API_Guide_Ver5.1_Rev1.13.pdf
"""

def __init__(self, username=None, password=None):
Expand All @@ -775,7 +773,7 @@ def __init__(self, username=None, password=None):

@property
def _client(self):
"""Initialize the SUDS client if necessary."""
"""Initialize the ZEEP client if necessary."""

if self._zeep_client is None:
self._zeep_client = zeep.Client(SERVICE_WSDL_URL)
Expand All @@ -790,11 +788,10 @@ def _soap_service(self):

def set_security_token(self):
# Add SOAP Security tokens
#security = suds.wsse.Security()
#token = suds.wsse.UsernameToken(self._username, self._password)
#security.tokens.append(token)
#self._zeep_client.set_options(wsse=security)
self._zeep_client = zeep.Client(SERVICE_WSDL_URL, wsse=UsernameToken(self._username, self._password))
#TODO:might need to put this in config
#NOTE: wihtout this setting, zeep will not get result
settins = Settings(strict=False, xml_huge_tree=True, xsd_ignore_sequence_order=True)
self._zeep_client = zeep.Client(SERVICE_WSDL_URL, wsse=UsernameToken(self._username, self._password),settings=settins)

def set_client(self, client):
self._zeep_client = client
Expand Down Expand Up @@ -823,7 +820,7 @@ def clearAlarms(self, **kwargs):
:returns SOAP reply object. If successful, there will be a responseCode of '100'.
"""

searchQuery = self._client.factory.create('clearAlarmsSearchQuery')
searchQuery = self._client.get_type('ns0:clearAlarmsSearchQuery')()
for k, v in kwargs.items():
setattr(searchQuery, k, v)
response = self._soap_service.clearAlarms(searchQuery)
Expand All @@ -839,7 +836,7 @@ def clearShedState(self, **kwargs):
:returns SOAP reply object. If successful, there will be a responseCode of '100'.
"""

searchQuery = self._client.factory.create('shedQueryInputData')
searchQuery = self._client.get_type('ns0:shedQueryInputData')()
if 'stationID' in kwargs.keys():
setattr(searchQuery, 'shedStation', {'stationID': kwargs['stationID']})
elif 'sgID' in kwargs.keys():
Expand Down Expand Up @@ -893,7 +890,7 @@ def getAlarms(self, **kwargs):
}
"""

searchQuery = self._client.factory.create('getAlarmsSearchQuery')
searchQuery = self._client.get_type('ns0:getAlarmsSearchQuery')()
for k, v in kwargs.items():
setattr(searchQuery, k, v)
response = self._soap_service.getAlarms(searchQuery)
Expand Down Expand Up @@ -968,7 +965,7 @@ def getChargingSessionData(self, **kwargs):
}
"""

searchQuery = self._client.factory.create('sessionSearchdata')
searchQuery = self._client.get_type('ns0:sessionSearchdata')()
for k, v in kwargs.items():
setattr(searchQuery, k, v)
response = self._soap_service.getChargingSessionData(searchQuery)
Expand Down Expand Up @@ -1021,7 +1018,8 @@ def getLoad(self, **kwargs):
"""

# @ToDo: Figure out what type of request searchQuery should be here.
searchQuery = self._client.factory.create('stationSearchRequestExtended')
# @Note: Looks like it should be {sgID: xsd:int, stationID: xsd:string, sessionID: xsd:long}
searchQuery = {}
for k, v in kwargs.items():
setattr(searchQuery, k, v)
response = self._soap_service.getLoad(searchQuery)
Expand Down Expand Up @@ -1062,7 +1060,7 @@ def getOrgsAndStationGroups(self, **kwargs):
}
"""

searchQuery = self._client.factory.create('getOrgsAndStationGroupsSearchQuery')
searchQuery = self._client.get_type('ns0:getOrgsAndStationGroupsSearchQuery')()
for k, v in kwargs.items():
setattr(searchQuery, k, v)
response = self._soap_service.getOrgsAndStationGroups(searchQuery)
Expand Down Expand Up @@ -1217,7 +1215,7 @@ def getStationRights(self, **kwargs):
}
"""

searchQuery = self._client.factory.create('stationRightsSearchRequest')
searchQuery = self._client.get_type('ns0:stationRightsSearchRequest')()
for k, v in kwargs.items():
setattr(searchQuery, k, v)
response = self._soap_service.getStationRights(searchQuery)
Expand Down Expand Up @@ -1362,7 +1360,8 @@ def getStations(self, **kwargs):
moreFlag = 0
}
"""
searchQuery = self._client.factory.create('stationSearchRequestExtended')

searchQuery = self._client.get_type('ns0:stationSearchRequestExtended')()
for k, v in kwargs.items():
setattr(searchQuery, k, v)
response = self._soap_service.getStations(searchQuery)
Expand Down Expand Up @@ -1449,7 +1448,7 @@ def getUsers(self, **kwargs):
}
"""

searchQuery = self._client.factory.create('getUsersSearchRequest')
searchQuery = self._client.get_type('ns0:getUsersSearchRequest')()
for k, v in kwargs.items():
setattr(searchQuery, k, v)
response = self._soap_service.getUsers(searchQuery)
Expand Down Expand Up @@ -1487,7 +1486,8 @@ def shedLoad(self, **kwargs):
:returns SOAP reply object. If successful, there will be a responseCode of '100'.
"""
searchQuery = self._client.factory.create('shedLoadQueryInputData')

searchQuery = self._client.get_type('ns0:shedLoadQueryInputData')()
port = kwargs.pop('portNumber', None)
query_params = {'stationID': kwargs['stationID']}
if port:
Expand Down
2 changes: 0 additions & 2 deletions update_scripts/update.driver

This file was deleted.

0 comments on commit 6b77994

Please sign in to comment.