Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
67 changes: 44 additions & 23 deletions luminance/views/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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):
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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):
Expand All @@ -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')
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions luminance/views/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"