Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "Dimmable light" device type #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
38 changes: 24 additions & 14 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 @@ -29,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):
Expand All @@ -57,18 +59,25 @@ 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)

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 +92,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 +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):
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"