diff --git a/README.md b/README.md index 3e6e782..39582a3 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,14 @@ it. * [requests](https://github.com/kennethreitz/requests) 2.10 or later * Hue bridge (tested with the first generation only) +#### Requirements installation for Debian based distributions + +You will need the following packages installed prior to running [installation (build)](https://github.com/craigcabrey/luminance#installing) on Debian-based distributions. + +``` +sudo apt install autoconf autogen build-essential python-gi-dev libgtk-3-dev gsettings-desktop-schemas-dev libgnome-desktop-3-dev libxml2-utils && pip3 install phue +``` + ### Installing 1. Clone this repository. diff --git a/luminance/views/entity.py b/luminance/views/entity.py index e65dda9..cff1987 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_nondimmable_light from .. import get_resource_path @@ -24,17 +25,21 @@ def __init__(self, model, *args, **kwargs): self.list = builder.get_object('list') for entity in model: - self.list.add(ListBoxRow(entity)) + try: + self.list.add(ListBoxRow(entity)) + except KeyError as e: + print("{} not supported. ".format(entity)) 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): @@ -57,18 +62,28 @@ def __init__(self, model, *args, **kwargs): self.color_chooser = builder.get_object('color-chooser') if self.model.on: - self.color_chooser.set_rgba( - hsv_to_gdk_rgb( - self.model.hue, - self.model.saturation, - self.model.brightness + if is_nondimmable_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) + try: + self.brightness_scale.set_value(self.model.brightness) + except KeyError as e: + print("Failed setting the brightness for ", self.model) 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) @@ -83,7 +98,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_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) @@ -99,7 +114,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): @@ -123,13 +139,18 @@ def __init__(self, model, *args, id=None, **kwargs): self.brightness_scale.set_value(self.model.brightness) self.color_chooser = builder.get_object('color-chooser') - self.color_chooser.set_rgba( - hsv_to_gdk_rgb( - self.model.hue, - self.model.saturation, - self.model.brightness + if is_nondimmable_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.alert_long_button = builder.get_object('alert-long-button') self.alert_short_button = builder.get_object('alert-short-button') @@ -172,7 +193,7 @@ def _on_close_click(self, *args): self.destroy() def _on_color_activate(self, *args): - if self.model.on 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 25175c9..0c06c70 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_nondimmable_light(model): + return not hasattr(model, 'group_id') and model.type != "Dimmable light" \ No newline at end of file