Skip to content

Commit

Permalink
Ensure IOTileDeviceSlug only considers 48 bits when converting format…
Browse files Browse the repository at this point in the history
…ted ids
  • Loading branch information
dkarchmer committed Mar 2, 2018
1 parent 86cb07c commit b378b33
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
### v0.8.7 (2018-03-02)

* Ensure IOTileDeviceSlug only considers 48 bits when converting formatted ids

### v0.8.6 (2018-02-27)

* Allow params to be passed to POST, PATCH, PUT and DELETE

### v0.8.5 (2018-02-23)

* Fix get stream acknowledgment to get the right dictionary field (Issue #28)
Expand Down
14 changes: 12 additions & 2 deletions iotile_cloud/utils/gid.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,19 @@ def __init__(self, id):
return

if isinstance(id, int):
did = int2did(id)
did = int2did(id)
else:
did = id
assert isinstance(id, str)
parts = gid_split(id)
if len(parts) == 1:
did = parts[0]
else:
did = gid_join(parts[1:])

# Convert to int and back to get rid of anything above 48 bits
id = gid2int(did)
did = int2did(id)

self.set_from_single_id_slug('d', 4, did)


Expand Down
9 changes: 8 additions & 1 deletion tests/test_gid.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ def test_device_slug(self):

id = IOTileDeviceSlug('0005')
self.assertEqual(str(id), 'd--0000-0000-0000-0005')

self.assertEqual(id.formatted_id(), '0000-0000-0000-0005')

id = IOTileDeviceSlug('d--1234-0000-0000-0001')
self.assertEqual(str(id), 'd--0000-0000-0000-0001')
self.assertEqual(id.get_id(), 1)

id = IOTileDeviceSlug('1234-0000-0000-0001')
self.assertEqual(str(id), 'd--0000-0000-0000-0001')
self.assertEqual(id.get_id(), 1)

def test_block_slug(self):
id = IOTileBlockSlug(5)
self.assertEqual(str(id), 'b--0000-0000-0000-0005')
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '0.8.6'
version = '0.8.7'

0 comments on commit b378b33

Please sign in to comment.