Skip to content

Commit

Permalink
prepare 0.18.0. release
Browse files Browse the repository at this point in the history
  • Loading branch information
tillsteinbach committed Aug 9, 2021
1 parent 5ae2205 commit dde35c2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
- Currently no unreleased changes

## [0.18.0] - 2021-08-09
### Added
- Possibility to fetch chargers without updating chargersList
- Possibility to remove registered observers

## [0.17.0] - 2021-08-07
### Added
- New API elements for GUEST_USER, UNKNOWN enrollment status and delayed and timeout of operations
Expand Down Expand Up @@ -199,7 +204,8 @@ Minor fix in observer interface
## [0.1.0] - 2021-05-26
Initial release

[unreleased]: https://github.com/tillsteinbach/WeConnect-python/compare/v0.17.0...HEAD
[unreleased]: https://github.com/tillsteinbach/WeConnect-python/compare/v0.18.0...HEAD
[0.18.0]: https://github.com/tillsteinbach/WeConnect-python/releases/tag/v0.18.0
[0.17.0]: https://github.com/tillsteinbach/WeConnect-python/releases/tag/v0.17.0
[0.16.0]: https://github.com/tillsteinbach/WeConnect-python/releases/tag/v0.16.0
[0.15.1]: https://github.com/tillsteinbach/WeConnect-python/releases/tag/v0.15.1
Expand Down
4 changes: 4 additions & 0 deletions weconnect/addressable.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def addObserver(self, observer, flag, priority=None, onUpdateComplete=False):
self.__observers.add((observer, flag, priority, onUpdateComplete))
LOG.debug('%s: Observer added with flags: %s', self.getGlobalAddress(), flag)

def removeObserver(self, observer, flag=None):
self.__observers = self.__observers = filter(lambda observerEntry: observerEntry[0] == observer
or (flag is not None and observerEntry[1] == flag), self.__observers)

def getObservers(self, flags, onUpdateComplete=False):
return [observerEntry[0] for observerEntry in self.getObserverEntries(flags, onUpdateComplete)]

Expand Down
47 changes: 47 additions & 0 deletions weconnect/weconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,53 @@ def setChargingStationSearchParameters(self, latitude, longitude, searchRadius=N
self.market = market
self.useLocale = useLocale

def getChargingStations(self, latitude, longitude, searchRadius=None, market=None, useLocale=None, force=False): # noqa: C901
chargingStationMap = AddressableDict(localAddress='', parent=None)
data = None
cacheDate = None
url = f'https://mobileapi.apps.emea.vwapps.io/charging-stations/v2?latitude={latitude}&longitude={longitude}'
if market is not None:
url += f'&market={market}'
if useLocale is not None:
url += f'&locale={useLocale}'
if searchRadius is not None:
url += f'&searchRadius={searchRadius}'
if self.__userId is not None:
url += f'&userId={self.__userId}'
if force or (self.maxAge is not None and url in self.__cache):
data, cacheDateString = self.__cache[url]
cacheDate = datetime.fromisoformat(cacheDateString)
if data is None or self.maxAge is None or (cacheDate is not None and cacheDate < (datetime.utcnow() - timedelta(seconds=self.maxAge))):
try:
stationsResponse = self.__session.get(url, allow_redirects=True)
except requests.exceptions.ConnectionError as conenctionError:
raise RetrievalError from conenctionError
if stationsResponse.status_code == requests.codes['ok']:
data = stationsResponse.json()
elif stationsResponse.status_code == requests.codes['unauthorized']:
LOG.info('Server asks for new authorization')
self.login()
stationsResponse = self.__session.get(url, allow_redirects=False)
if stationsResponse.status_code == requests.codes['ok']:
data = stationsResponse.json()
else:
raise RetrievalError('Could not retrieve data even after re-authorization.'
f' Status Code was: {stationsResponse.status_code}')
else:
raise RetrievalError(f'Status Code from WeConnect server was: {stationsResponse.status_code}')
if data is not None:
if 'chargingStations' in data and data['chargingStations']:
for stationDict in data['chargingStations']:
if 'id' not in stationDict:
break
stationId = stationDict['id']
station = ChargingStation(weConnect=self, stationId=stationId, parent=chargingStationMap, fromDict=stationDict,
fixAPI=self.fixAPI)
chargingStationMap[stationId] = station

self.__cache[url] = (data, str(datetime.utcnow()))
return chargingStationMap

def updateChargingStations(self, force=False): # noqa: C901
if self.latitude is not None and self.longitude is not None:
data = None
Expand Down

0 comments on commit dde35c2

Please sign in to comment.