Skip to content

Commit

Permalink
Changed the brightness parameter to a float between 0 en 1
Browse files Browse the repository at this point in the history
  • Loading branch information
RicArch97 committed Jun 16, 2020
1 parent ed55766 commit 8251459
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions crownstone_cloud/lib/cloudModels/crownstones.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,17 @@ def turn_off_sync(self) -> None:
"""Sync turn off this crownstone"""
self.loop.run_until_complete(self.turn_off())

async def set_brightness(self, percentage: int) -> None:
async def set_brightness(self, brightness: float) -> None:
"""
Set the brightness of this crownstone, if dimming enabled
:param percentage: the brightness percentage (0 - 100)
:param brightness: brightness value between (0 - 1)
"""
if self.dimming_enabled:
if self.dimming_synced_to_crownstone:
if percentage < 0 or percentage > 100:
raise ValueError("Enter a percentage between 0 and 100")
if brightness < 0 or brightness > 1:
raise ValueError("Enter a value between 0 and 1")
else:
brightness = percentage / 100
await RequestHandler.put('Stones', 'setSwitchStateRemotely', model_id=self.cloud_id,
command='switchState', value=brightness)
else:
Expand All @@ -151,10 +150,10 @@ async def set_brightness(self, percentage: int) -> None:
else:
_LOGGER.error("Dimming is not enabled for this crownstone. Go to the crownstone app to enable it")

def set_brightness_sync(self, percentage: int) -> None:
def set_brightness_sync(self, brightness: float) -> None:
"""
Sync set the brightness of this crownstone, if dimming enabled
:param percentage: the brightness percentage (0 - 100)
:param brightness: the brightness percentage (0 - 1)
"""
self.loop.run_until_complete(self.set_brightness(percentage))
self.loop.run_until_complete(self.set_brightness(brightness))

0 comments on commit 8251459

Please sign in to comment.