Skip to content

Commit 23a63cd

Browse files
authored
Fix multipleOf check in set_value. (#83)
1 parent 22679eb commit 23a63cd

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

gateway_addon/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .outlet import Outlet
1717
from .property import Property
1818

19-
__version__ = '0.11.0'
19+
__version__ = '0.12.0'
2020
API_VERSION = 2
2121

2222

gateway_addon/property.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,13 @@ def set_value(self, value):
141141
raise PropertyError('Value greater than maximum: {}'
142142
.format(self.description['maximum']))
143143

144-
if 'multipleOf' in self.description and \
145-
value % self.description['multipleOf'] != 0:
146-
raise PropertyError('Value is not a multiple of: {}'
147-
.format(self.description['multipleOf']))
144+
if 'multipleOf' in self.description:
145+
# note that we don't use the modulus operator here because it's
146+
# unreliable for floating point numbers
147+
multiple_of = self.description['multipleOf']
148+
if value / multiple_of - round(value / multiple_of) != 0:
149+
raise PropertyError('Value is not a multiple of: {}'
150+
.format(multiple_of))
148151

149152
if 'enum' in self.description and \
150153
len(self.description['enum']) > 0 and \

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
setup(
3131
name='gateway_addon',
32-
version='0.11.0',
32+
version='0.12.0',
3333
description='Bindings for Mozilla WebThings Gateway add-ons',
3434
long_description=long_description,
3535
url='https://github.com/mozilla-iot/gateway-addon-python',

0 commit comments

Comments
 (0)