From fa6f442c8704b3bf89f7f2abe9d413e01e8a9bdd Mon Sep 17 00:00:00 2001 From: thinkbrown Date: Tue, 28 Feb 2017 22:20:17 -0500 Subject: [PATCH 1/4] Added support for non-colored dimmable lights --- luminance/views/entity.py | 22 ++++++++++++++-------- luminance/views/util.py | 4 ++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/luminance/views/entity.py b/luminance/views/entity.py index e65dda9..c68c770 100644 --- a/luminance/views/entity.py +++ b/luminance/views/entity.py @@ -9,6 +9,7 @@ from gi.repository import Gtk from .util import hsv_to_gdk_rgb +from .util import is_dimmable_light from .. import get_resource_path @@ -55,15 +56,20 @@ def __init__(self, model, *args, **kwargs): entity_name_label.set_text(self.model.name) self.color_chooser = builder.get_object('color-chooser') - + print(self.model) if self.model.on: - self.color_chooser.set_rgba( - hsv_to_gdk_rgb( - self.model.hue, - self.model.saturation, - self.model.brightness + if is_dimmable_light(self.model): + self.color_chooser.set_rgba( + hsv_to_gdk_rgb( + self.model.hue, + self.model.saturation, + self.model.brightness + ) + ) + else: + self.color_chooser.set_rgba( + Gdk.RGBA(1, 1, 1) ) - ) self.brightness_scale = builder.get_object('brightness-scale') self.brightness_scale.set_value(self.model.brightness) @@ -83,7 +89,7 @@ def model(self): return self._model def _on_color_activate(self, *args): - if self.model.on and self.color_chooser.get_visible(): + if self.model.on and is_dimmable_light(self.model) and self.color_chooser.get_visible(): rgba = self.color_chooser.get_rgba() hsv = colorsys.rgb_to_hsv(rgba.red, rgba.green, rgba.blue) diff --git a/luminance/views/util.py b/luminance/views/util.py index 25175c9..ef10796 100644 --- a/luminance/views/util.py +++ b/luminance/views/util.py @@ -15,3 +15,7 @@ def hsv_to_gdk_rgb(hue, sat, bri): ) return Gdk.RGBA(red=rgb[0], green=rgb[1], blue=rgb[2]) + + +def is_dimmable_light(model): + return not hasattr(model, 'group_id') and model.type != "Dimmable light" \ No newline at end of file From 1061e55179e59698ebd1074d91c1bf9d866d2343 Mon Sep 17 00:00:00 2001 From: thinkbrown Date: Tue, 28 Feb 2017 22:21:59 -0500 Subject: [PATCH 2/4] Removed print message --- luminance/views/entity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luminance/views/entity.py b/luminance/views/entity.py index c68c770..76f9172 100644 --- a/luminance/views/entity.py +++ b/luminance/views/entity.py @@ -56,7 +56,7 @@ def __init__(self, model, *args, **kwargs): entity_name_label.set_text(self.model.name) self.color_chooser = builder.get_object('color-chooser') - print(self.model) + if self.model.on: if is_dimmable_light(self.model): self.color_chooser.set_rgba( From f49a7e78040d60f98aa18ef0611659590de03c09 Mon Sep 17 00:00:00 2001 From: thinkbrown Date: Tue, 28 Feb 2017 22:23:31 -0500 Subject: [PATCH 3/4] Made function naming make sense --- luminance/views/entity.py | 6 +++--- luminance/views/util.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/luminance/views/entity.py b/luminance/views/entity.py index 76f9172..d093f73 100644 --- a/luminance/views/entity.py +++ b/luminance/views/entity.py @@ -9,7 +9,7 @@ from gi.repository import Gtk from .util import hsv_to_gdk_rgb -from .util import is_dimmable_light +from .util import is_nondimmable_light from .. import get_resource_path @@ -58,7 +58,7 @@ def __init__(self, model, *args, **kwargs): self.color_chooser = builder.get_object('color-chooser') if self.model.on: - if is_dimmable_light(self.model): + if is_nondimmable_light(self.model): self.color_chooser.set_rgba( hsv_to_gdk_rgb( self.model.hue, @@ -89,7 +89,7 @@ def model(self): return self._model def _on_color_activate(self, *args): - if self.model.on and is_dimmable_light(self.model) and self.color_chooser.get_visible(): + if self.model.on and is_nondimmable_light(self.model) and self.color_chooser.get_visible(): rgba = self.color_chooser.get_rgba() hsv = colorsys.rgb_to_hsv(rgba.red, rgba.green, rgba.blue) diff --git a/luminance/views/util.py b/luminance/views/util.py index ef10796..0c06c70 100644 --- a/luminance/views/util.py +++ b/luminance/views/util.py @@ -17,5 +17,5 @@ def hsv_to_gdk_rgb(hue, sat, bri): return Gdk.RGBA(red=rgb[0], green=rgb[1], blue=rgb[2]) -def is_dimmable_light(model): +def is_nondimmable_light(model): return not hasattr(model, 'group_id') and model.type != "Dimmable light" \ No newline at end of file From 0936b9f4d561d2af99ac565d5f3ce65e88314d98 Mon Sep 17 00:00:00 2001 From: thinkbrown Date: Tue, 28 Feb 2017 22:55:24 -0500 Subject: [PATCH 4/4] Made function naming make sense --- luminance/views/entity.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/luminance/views/entity.py b/luminance/views/entity.py index d093f73..289a43c 100644 --- a/luminance/views/entity.py +++ b/luminance/views/entity.py @@ -30,12 +30,13 @@ def __init__(self, model, *args, **kwargs): self.add(self.content) def _on_row_activated(self, listbox, row): - DetailWindow( - row.model, - modal=True, - transient_for=self.get_toplevel(), - type_hint=Gdk.WindowTypeHint.DIALOG - ).present() + if is_nondimmable_light(row.model): + DetailWindow( + row.model, + modal=True, + transient_for=self.get_toplevel(), + type_hint=Gdk.WindowTypeHint.DIALOG + ).present() class ListBoxRow(Gtk.ListBoxRow): @@ -75,6 +76,8 @@ def __init__(self, model, *args, **kwargs): self.brightness_scale.set_value(self.model.brightness) self.color_chooser_popover_button = builder.get_object('color-chooser-popover-button') + if not is_nondimmable_light(self.model): + self.color_chooser_popover_button.set_sensitive(False) entity_switch = builder.get_object('entity-switch') entity_switch.set_state(self.model.on) @@ -105,7 +108,8 @@ def _on_brightness_scale_change(self, scale, delta, value): def _on_entity_switch_state_set(self, switch, value): self.model.on = value self.brightness_scale.set_sensitive(value) - self.color_chooser_popover_button.set_sensitive(value) + if is_nondimmable_light(self.model): + self.color_chooser_popover_button.set_sensitive(value) class DetailWindow(Gtk.Window):