Skip to content

Commit 7cd3645

Browse files
Wrap charging point update items in new encoding function and check cellular signal type
1 parent 1576a65 commit 7cd3645

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

tculink/carwings_proto/applications/cp.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def handle_cp(xml_data, files):
208208
'lat': chg['coordinates']['lat'],
209209
'lon': chg['coordinates']['long'],
210210
'dynamic_field': 'DC charger'
211-
})
211+
})
212212
name_items.append(chg.get('name', 'Charging Station')[:32])
213213
secondary_items.append(chg.get('name', 'Charging Station')[:32])
214214
for station in [plug for plug in chg["evses"] if plug["connectors"][0]['standard'] == "CHADEMO"]:
@@ -503,18 +503,18 @@ def handle_cp(xml_data, files):
503503

504504
cpinfo_obj = {
505505
'poi_id': charger['ID'],
506-
'name': unidecode(charger['AddressInfo'].get('Title', 'Charging Station') or "Charging Station")[:30],
506+
'name': encode_utf8(charger['AddressInfo'].get('Title', 'Charging Station') or "Charging Station", limit=31),
507507
'code': '',
508-
'county': unidecode(charger["AddressInfo"].get("Town", '') or "")[:30],
509-
'region': unidecode(charger["AddressInfo"].get('StateOrProvince', '') or "")[:30],
510-
'city': unidecode(charger["AddressInfo"].get("Town", '') or "")[:30],
511-
'town': unidecode(charger["AddressInfo"].get("Postcode", '') or "")[:30],
508+
'county': encode_utf8(charger["AddressInfo"].get("Town", '') or "", limit=31),
509+
'region': encode_utf8(charger["AddressInfo"].get('StateOrProvince', '') or "", limit=31),
510+
'city': encode_utf8(charger["AddressInfo"].get("Town", '') or "", limit=31),
511+
'town': encode_utf8(charger["AddressInfo"].get("Postcode", '') or "", limit=31),
512512
'meta1': '',
513513
'meta2': '',
514514
'meta3': '',
515515
'lat': charger["AddressInfo"]["Latitude"],
516516
'lon': charger["AddressInfo"]["Longitude"],
517-
'address': unidecode(charger["AddressInfo"].get("AddressLine1", "") or "")[:30],
517+
'address': encode_utf8(charger["AddressInfo"].get("AddressLine1", "") or "", limit=30),
518518
'mesh_id': 65535,
519519
'phone': phone_num,
520520
'sites': [],

tculink/carwings_proto/autodj/channels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@
209209

210210
def translate_chan_name(chan, non_unicode=False):
211211
new_chan = chan.copy()
212-
new_chan['name1'] = str(_(chan['name1']))[:31]
213-
new_chan['name2'] = str(_(chan['name2']))[:127]
212+
new_chan['name1'] = str(_(chan['name1']))
213+
new_chan['name2'] = str(_(chan['name2']))
214214
if non_unicode:
215215
new_chan['name1'] = unidecode(new_chan['name1'])
216216
new_chan['name2'] = unidecode(new_chan['name2'])

tculink/carwings_proto/dataobjects.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def construct_fvtchn_payload(channels):
3434

3535
return payload
3636

37+
# codes: 0xb, 0xc
3738
def construct_gnrlms_payload(code, title, message):
3839
payload = bytearray()
3940
payload += b'\x00'*9
@@ -417,6 +418,7 @@ def build_autodj_payload(
417418
raise ValueError("Footer type 2 data must be 10 bytes")
418419
payload.extend(footer['data'])
419420
elif ftype in (3, 8):
421+
# reference to itemFlag1 in footer type 3
420422
payload += (footer['data'] & 0xFF).to_bytes(1, "big") # uint8
421423
elif ftype == 4:
422424
len1 = footer['len1']
@@ -428,6 +430,8 @@ def build_autodj_payload(
428430
payload += (len2 & 0xFF).to_bytes(1, "big") # uint8
429431
payload.extend(data2)
430432
elif ftype == 6:
433+
# data is array of itemFlag1 values, which also have fifth bit as 1 in mapPointFlag.
434+
# This sorts AutoDJ items in order you specify them here. using their itemFlag1.
431435
data = footer['data']
432436
l = len(data)
433437
if l > 255:
@@ -445,6 +449,8 @@ def build_autodj_payload(
445449
elif ftype == 10:
446450
a = footer['a']
447451
b = footer['b']
452+
# data is array of itemFlag1 values, which also have fifth bit as 1 in mapPointFlag.
453+
# This sorts AutoDJ items in order you specify them here. using their itemFlag1.
448454
data = footer['data']
449455
l = len(data)
450456
if l > 255:

tculink/carwings_proto/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def update_car_info(xml_data):
5252
car_obj.odometer = odometer
5353
if signal_level is None:
5454
signal_level = -1
55+
if type(signal_level) != int:
56+
signal_level = 0
5557
car_obj.signal_level = signal_level
5658
car_obj.carrier = carrier
5759
if status is not None:

0 commit comments

Comments
 (0)