Skip to content

Commit

Permalink
Add new features: obtain images and save those to to files
Browse files Browse the repository at this point in the history
  • Loading branch information
tillsteinbach committed Jul 5, 2021
1 parent 4daa5c0 commit 21f74b4
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 15 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
- No unreleased changes so far

## [0.11.0] - 2021-07-05
### Added
- Support to work with car images / status images

## [0.10.2] - 2021-07-03
### Fixed
- Bug with addresses fixed in API 0.11.1
Expand Down Expand Up @@ -117,7 +121,8 @@ All notable changes to this project will be documented in this file.
## [0.1.0] - 2021-05-26
Initial release

[unreleased]: https://github.com/tillsteinbach/WeConnect-cli/compare/v0.10.2..HEAD
[unreleased]: https://github.com/tillsteinbach/WeConnect-cli/compare/v0.11.0..HEAD
[0.11.0]: https://github.com/tillsteinbach/WeConnect-cli/releases/tag/v0.11.0
[0.10.2]: https://github.com/tillsteinbach/WeConnect-cli/releases/tag/v0.10.2
[0.10.1]: https://github.com/tillsteinbach/WeConnect-cli/releases/tag/v0.10.1
[0.10.0]: https://github.com/tillsteinbach/WeConnect-cli/releases/tag/v0.10.0
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ user@mail.de@weconnect-sh:/vehicles/WVWABCE13SD057505/status/parkingPosition$ ca
[parkingPosition] (last captured 2021-06-01T19:05:04+00:00)
Latitude: 51.674535
Longitude: 16.154376
user@mail.de@weconnect-sh:/vehicles/WVWZZZ3CZME112096/status/parkingPosition$ exit
user@mail.de@weconnect-sh:/vehicles/WVWABCE13SD057505/status/parkingPosition$ exit
Bye
```
### Caching
Expand All @@ -125,6 +125,40 @@ login test@test.de
password testpassword123
```
You can also provide the location of the netrc file using the --netrc option

### Images
You can also work with images from the API
Either you have a look at the commandline
```
weconnect-cli get /vehicles/WVWABCE13SD057505/pictures/car
zjo]?![[[[]!!??I*{{rlllcc?uzo7zjjuunT#Jwfy25Fmd
*JywJ##TTuua]1t7LLjLLLjz7ot[Ir]att11[[aaeeeeoooeozjzet[>
1T2p6p5Fmh4Jeut1eoeLT#nL1ou##jeLne]!]!1j[[][[[[[]]I}I][1tee?
=[nypmqgdXbbYgzaTuTfzI}}}I!t}jTwjjJL}llllc}Tz?I*}}*****ssr*}}I[1[l
rcsoCF6pmgddVhgg6aaCL1##1IIIIII}!ettTwt%%v%cr?]{eI{v%cccllrrrsr*I??aw!}
Q@GEVgqTnw2yw##TTuuLjj7oaat[]!?IIIIII??!!!7nt{>="i%c{![oea[[taeeeeeeet1eeeetta]i
a7uJCJ#nLjz7ot1]!?II}**{{srlllrs*}}}}}I?]1e7juLLLLzL1%}1[11teat!rI?I*{srlccvccls{{srri:
ufzx%lrcv)<\)||"""""|||)\\<<>)%l{**{rs}[7u#TuLz77zjuTL7]I{lx%vi><<\)ii\\\\\\\\\<>>%rss*{cv"
Ypje{cx%%%%%%v%xxxcccllrs{*?[ezLuTJwf36dGdFw6Vg#Ii\\)xlxi|///////////////////////++++;_'^\v)"
Y&&F7t!I!?!?t1jt[[1ttttaju5hggV&DkgpdBDXSo}?ttr";:_..-^"|/==^^^^^^^^^;^;;;;;;;;;;;;^">i|__/\/
#L#e]1*%v%ii\v<\>>ii%v%xclI1e1ajhZFuo#hS#[II*v/)l***c\,`:^^;;;;;;;;;;;;;^^^^==++/=,;/%s][c:;=^
33]||vrr***{*{{rxllrrrrrsrlrllrs{{{{***}I?}r%<"%r1}]ts]{\_;;;===++////""""""||||||/;^){s![!\"}r
]z}i:,:\EGPE6q6VE44d};^==^^=+/"|\ir*?!1tsc)|/=c1?*I]![[?{\,+""/////""|)\<>)vxcrs{***>)!?*}[%{oe
=/"\=^'^t77joo7nJwfyc_'::^+""|)\>%}????#a=""+/!I!*r1nIs!tv|<vxlr{*}I??!???}*{rlxv)<|^|]u{}7%?
>wt)=+^_-` `. . . ._``://"/""|)\)ls{}!d{;\i%]!aos{e[*e7vl**{srlc%%vii))>><<\\/^;^^=/%1!oI"
Ewz[><<<<<>)%{{srcv)v))vlrsrrrlll*e7zz7ei)I]{Ia71e{}IjT?)^;,:'_-`. -^+///>xi/
.g `:;==/\l[1[I%<)""""+///"||)|+====+="||/"v?l*e]]nf?|` `_:,'-
`_''''':'_. -;+|\<vs*?Ic<^
`:^^^=+=^:
```
but it makes more sense to save the image to a file:
```bash
weconnect-cli save /vehicles/WVWABCE13SD057505/pictures/car car.png
ls -alh car.png
-rw-r--r-- 1 tillsteinbach staff 135K 5 Jul 15:07 car.png
```
If there is information regarding door, light and window status provided for your car you can also use the 'status' picture

## Tested with
- Volkswagen ID.3 Modelyear 2021
- Volkswagen Passat GTE Modelyear 2021
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
weconnect==0.11.1
weconnect==0.12.0
ascii_magic>=1.5.5
52 changes: 40 additions & 12 deletions weconnect_cli/weconnect_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import tempfile
import cmd

import ascii_magic

from weconnect import weconnect, addressable, errors

from .__version import __version__
Expand Down Expand Up @@ -72,6 +74,8 @@ def main(): # noqa: C901 # pylint: disable=too-many-statements,too-many-branche
help='If set charging locations will be added to the result around the given coordinates')
parser.add_argument('--chargingLocationRadius', type=NumberRangeArgument(0, 100000),
help='Radius in meters around the chargingLocation to search for chargers')
parser.add_argument('--no-capabilities', dest='noCapabilities', help='Do not add capabilities', action='store_true')
parser.add_argument('--no-pictures', dest='noPictures', help='Do not add pictures', action='store_true')

parser.set_defaults(command='shell')

Expand All @@ -83,10 +87,14 @@ def main(): # noqa: C901 # pylint: disable=too-many-statements,too-many-branche
parserGet = subparsers.add_parser('get', aliases=['g'], help='Get ressources by id and exit')
parserGet.add_argument('id', metavar='ID', type=str, help='Id to fetch')
parserGet.set_defaults(command='get')
parserGet = subparsers.add_parser('set', aliases=['s'], help='Set ressources by id and exit')
parserGet.add_argument('id', metavar='ID', type=str, help='Id to set')
parserGet.add_argument('value', metavar='VALUE', type=str, help='Value to set')
parserGet.set_defaults(command='set')
parserSet = subparsers.add_parser('set', aliases=['s'], help='Set ressources by id and exit')
parserSet.add_argument('id', metavar='ID', type=str, help='Id to set')
parserSet.add_argument('value', metavar='VALUE', type=str, help='Value to set')
parserSet.set_defaults(command='set')
parserSave = subparsers.add_parser('save', help='Save ressources by id to file')
parserSave.add_argument('id', metavar='ID', type=str, help='Id to save')
parserSave.add_argument('filename', metavar='FILENAME', type=str, help='File to save to')
parserSave.set_defaults(command='save')
parserEvents = subparsers.add_parser(
'events', aliases=['e'], help='Continously retrieve events and show on console')
parserEvents.set_defaults(command='events')
Expand All @@ -101,6 +109,8 @@ def main(): # noqa: C901 # pylint: disable=too-many-statements,too-many-branche

logging.basicConfig(level=LOG_LEVELS[logLevel])

ascii_magic.init_terminal()

username = None
password = None

Expand Down Expand Up @@ -155,14 +165,14 @@ def main(): # noqa: C901 # pylint: disable=too-many-statements,too-many-branche

if args.command == 'shell':
try:
weConnect.update()
weConnect.update(updateCapabilities=(not args.noCapabilities), updatePictures=(not args.noCapabilities))
# disable caching
weConnect.clearCache(maxAge=None)
WeConnectShell(weConnect).cmdloop()
WeConnectShell(weConnect, noCapabilities=args.noCapabilities, noPictures=args.noCapabilities).cmdloop()
except KeyboardInterrupt:
pass
elif args.command == 'list':
weConnect.update()
weConnect.update(updateCapabilities=(not args.noCapabilities), updatePictures=(not args.noPictures))
allElements = weConnect.getLeafChildren()
for element in allElements:
if args.setters:
Expand All @@ -171,7 +181,7 @@ def main(): # noqa: C901 # pylint: disable=too-many-statements,too-many-branche
else:
print(element.getGlobalAddress())
elif args.command == 'get':
weConnect.update()
weConnect.update(updateCapabilities=(not args.noCapabilities), updatePictures=(not args.noPictures))
element = weConnect.getByAddressString(args.id)
if element:
if isinstance(element, dict):
Expand All @@ -182,7 +192,7 @@ def main(): # noqa: C901 # pylint: disable=too-many-statements,too-many-branche
print(f'id {args.id} not found', file=sys.stderr)
sys.exit(-1)
elif args.command == 'set':
weConnect.update()
weConnect.update(updateCapabilities=(not args.noCapabilities), updatePictures=(not args.noPictures))
element = weConnect.getByAddressString(args.id)
if element:
try:
Expand All @@ -200,6 +210,21 @@ def main(): # noqa: C901 # pylint: disable=too-many-statements,too-many-branche
else:
print(f'id {args.id} not found', file=sys.stderr)
sys.exit(-1)
elif args.command == 'save':
weConnect.update(updateCapabilities=(not args.noCapabilities), updatePictures=(not args.noPictures))
element = weConnect.getByAddressString(args.id)
if element:
try:
element.saveToFile(args.filename)
except ValueError as valueError:
print(f'id {args.id} cannot be saved: {valueError}', file=sys.stderr)
sys.exit(-1)
except AttributeError:
print(f'id {args.id} cannot be saved', file=sys.stderr)
sys.exit(-1)
else:
print(f'id {args.id} not found', file=sys.stderr)
sys.exit(-1)
elif args.command == 'events':
if args.noCache:
LOG.warning('ignoring --no-cache parameter in events mode')
Expand All @@ -221,7 +246,7 @@ def observer(element, flags):
weConnect.addObserver(observer, addressable.AddressableLeaf.ObserverEvent.VALUE_CHANGED,
priority=addressable.AddressableLeaf.ObserverPriority.USER_MID)
while True:
weConnect.update()
weConnect.update(updateCapabilities=(not args.noCapabilities), updatePictures=(not args.noPictures))
time.sleep(args.interval)
else:
LOG.error('command not implemented')
Expand All @@ -243,9 +268,12 @@ class WeConnectShell(cmd.Cmd):
prompt = 'error'
intro = "Welcome! Type ? to list commands"

def __init__(self, weConnect, completekey='tab', stdin=None, stdout=None,):
def __init__(self, weConnect, completekey='tab', stdin=None, stdout=None, noCapabilities=False, noPictures=False):
self.weconnect = weConnect
self.pwd = weConnect
self.noCapabilities = noCapabilities
self.noPictures = noPictures

super().__init__(completekey=completekey, stdin=stdin, stdout=stdout)
self.setPrompt(self.weconnect.getGlobalAddress())

Expand Down Expand Up @@ -316,7 +344,7 @@ def help_update(self): # pylint: disable=no-self-use

def do_update(self, arguments):
del arguments
self.weconnect.update()
self.weconnect.update(updateCapabilities=(not self.noCapabilities), updatePictures=(not self.noPictures))
print('update done')

def help_cat(self): # pylint: disable=no-self-use
Expand Down

0 comments on commit 21f74b4

Please sign in to comment.