Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix float type (Single/Double) deserialization. #164

Merged
merged 2 commits into from May 21, 2019

Conversation

Adminiuga
Copy link
Collaborator

struct.unpack('<f', data) requires buffer size in bytes to match the format string exactly. zigpy.types.Single.deserialize(b'1234') would work, but zigpy.types.Single.deserialize(b'12345') not.
Deserializing a buffer containing more than just float data fails:

2019-05-21 00:00:24 ERROR (MainThread) [bellows.ezsp] Exception running handler
Traceback (most recent call last):
  File "/home/ha/src/bellows/bellows/ezsp.py", line 243, in handle_callback
    handler(*args)
  File "/home/ha/src/bellows/bellows/zigbee/application.py", line 211, in ezsp_callback_handler
    self._handle_frame(*args)
  File "/home/ha/src/bellows/bellows/zigbee/application.py", line 244, in _handle_frame
    tsn, command_id, is_reply, args = self.deserialize(device, aps_frame.sourceEndpoint, aps_frame.clusterId, message)
  File "/home/ha/src/zigpy/zigpy/application.py", line 86, in deserialize
    return sender.deserialize(endpoint_id, cluster_id, data)
  File "/home/ha/src/zigpy/zigpy/device.py", line 148, in deserialize
    return self.endpoints[endpoint_id].deserialize(cluster_id, data)
  File "/home/ha/src/zigpy/zigpy/endpoint.py", line 192, in deserialize
    return cluster.deserialize(tsn, frame_type, is_reply, command_id, data)
  File "/home/ha/src/zigpy/zigpy/zcl/__init__.py", line 95, in deserialize
    value, data = t.deserialize(data, schema)
  File "/home/ha/src/zigpy/zigpy/types/__init__.py", line 9, in deserialize
    value, data = type_.deserialize(data)
  File "/home/ha/src/zigpy/zigpy/types/basic.py", line 184, in deserialize
    item, data = r._itemtype.deserialize(data)
  File "/home/ha/src/zigpy/zigpy/types/struct.py", line 24, in deserialize
    v, data = field_type.deserialize(data)
  File "/home/ha/src/zigpy/zigpy/zcl/foundation.py", line 61, in deserialize
    self.value, data = python_type.deserialize(data)
  File "/home/ha/src/zigpy/zigpy/types/basic.py", line 133, in deserialize
    return struct.unpack('<f', data)[0], data[4:]
struct.error: unpack requires a buffer of 4 bytes

@coveralls
Copy link

coveralls commented May 21, 2019

Pull Request Test Coverage Report for Build 474

  • 8 of 8 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 472: 0.0%
Covered Lines: 2632
Relevant Lines: 2632

💛 - Coveralls

Raise if buffer size is incorrect.
@Adminiuga Adminiuga merged commit dc29452 into zigpy:dev May 21, 2019
@Adminiuga Adminiuga deleted the fixes/float-deserialize branch May 21, 2019 13:47
Adminiuga added a commit that referenced this pull request May 23, 2019
* Fix float type deserialization.
* Refactor float types.
Raise if buffer size is incorrect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants