From 82514592041fd7812f130919d88a54a177bf8322 Mon Sep 17 00:00:00 2001 From: RicArch97 Date: Tue, 16 Jun 2020 20:15:34 +0200 Subject: [PATCH] Changed the brightness parameter to a float between 0 en 1 --- crownstone_cloud/lib/cloudModels/crownstones.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/crownstone_cloud/lib/cloudModels/crownstones.py b/crownstone_cloud/lib/cloudModels/crownstones.py index a83bedb..473bed1 100644 --- a/crownstone_cloud/lib/cloudModels/crownstones.py +++ b/crownstone_cloud/lib/cloudModels/crownstones.py @@ -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: @@ -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))