Skip to content

Commit 7ae51cf

Browse files
authored
Merge pull request #36 from manexim/develop
Release version 0.5.0
2 parents 547ed28 + 7c19eea commit 7ae51cf

23 files changed

+531
-121
lines changed

.github/workflows/main.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
lint:
7+
8+
runs-on: ubuntu-latest
9+
10+
container:
11+
image: valalang/lint
12+
13+
steps:
14+
- uses: actions/checkout@v1
15+
- name: Lint
16+
run: io.elementary.vala-lint -d .

data/com.github.manexim.home.appdata.xml.in

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@
2121
<binary>com.github.manexim.home</binary>
2222
</provides>
2323
​<releases>
24+
<release date="2019-11-03" version="0.5.0">
25+
<description>
26+
<p>New:</p>
27+
<ul>
28+
<li>Use color picker to set color of smart bulbs</li>
29+
</ul>
30+
<p>Improved:</p>
31+
<ul>
32+
<li>Show an error page if network is not available</li>
33+
</ul>
34+
<p>Fixed:</p>
35+
<ul>
36+
</ul>
37+
<p>Translations:</p>
38+
<ul>
39+
<li>Russian (by camellan)</li>
40+
<li>French (by NathanBnm)</li>
41+
<li>German (by meisenzahl)</li>
42+
<li>Japanese (by ryonakano)</li>
43+
<li>Portuguese (by aimproxy)</li>
44+
<li>Polish (by oskarkunik)</li>
45+
</ul>
46+
</description>
47+
</release>
2448
<release date="2019-08-07" version="0.4.2">
2549
<description>
2650
<p>New:</p>

debian/changelog

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
com.github.manexim.home (0.5.0) bionic; urgency=medium
2+
3+
[NEW]
4+
* Use color picker to set color of smart bulbs
5+
[IMPROVED]
6+
* Show an error page if network is not available
7+
[FIXED]
8+
[TRANSLATIONS]
9+
* Russian (by camellan)
10+
* French (by NathanBnm)
11+
* German (by meisenzahl)
12+
* Japanese (by ryonakano)
13+
* Portuguese (by aimproxy)
14+
* Polish (by oskarkunik)
15+
16+
-- Marius Meisenzahl <[email protected]> Sun, 03 Nov 2019 14:24:03 +0100
17+
118
com.github.manexim.home (0.4.2) bionic; urgency=medium
219

320
[NEW]

src/Application.vala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public class Application : Granite.Application {
3636

3737
var css_provider = new Gtk.CssProvider ();
3838
css_provider.load_from_resource ("com/github/manexim/home/styles/application.css");
39-
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
39+
Gtk.StyleContext.add_provider_for_screen (
40+
Gdk.Screen.get_default (), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
41+
);
4042
}
4143

4244
public static int main (string[] args) {

src/colors/HSB.vala

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,72 @@
1919
* Authored by: Marius Meisenzahl <[email protected]>
2020
*/
2121

22-
public class Colors.HSB {}
22+
public class Colors.HSB {
23+
public uint16 hue;
24+
public uint8 saturation;
25+
public uint8 brightness;
26+
27+
public HSB () {}
28+
29+
public HSB.from_rgb (RGB rgb) {
30+
double min, max, delta;
31+
double h, s, b;
32+
33+
double red = rgb.red / 255.0;
34+
double green = rgb.green / 255.0;
35+
double blue = rgb.blue / 255.0;
36+
37+
min = red;
38+
min = green < min ? green : min;
39+
min = blue < min ? blue : min;
40+
41+
max = red;
42+
max = green > max ? green : max;
43+
max = blue > max ? blue : max;
44+
45+
b = max;
46+
delta = max - min;
47+
48+
if (max != 0) {
49+
s = delta / max;
50+
} else {
51+
s = 0;
52+
h = 0;
53+
54+
hue = (uint16) (h + 0.5);
55+
saturation = (uint8) (s * 100 + 0.5);
56+
brightness = (uint8) (b * 100 + 0.5);
57+
58+
return;
59+
}
60+
61+
if (max == min) {
62+
h = 0;
63+
s = 0;
64+
65+
hue = (uint16) (h + 0.5);
66+
saturation = (uint8) (s * 100 + 0.5);
67+
brightness = (uint8) (b * 100 + 0.5);
68+
69+
return;
70+
}
71+
72+
if (red == max) {
73+
h = (green - blue) / delta;
74+
} else if (green == max) {
75+
h = 2 + (blue - red) / delta;
76+
} else {
77+
h = 4 + (red - green) / delta;
78+
}
79+
80+
h *= 60;
81+
82+
if (h < 0) {
83+
h += 360;
84+
}
85+
86+
hue = (uint16) (h + 0.5);
87+
saturation = (uint8) (s * 100 + 0.5);
88+
brightness = (uint8) (b * 100 + 0.5);
89+
}
90+
}

src/colors/RGB.vala

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,75 @@ public class Colors.RGB {
2929
public RGB.from_hex (string hex) {
3030
hex.scanf ("%02x%02x%02x", &red, &green, &blue);
3131
}
32+
33+
public RGB.from_hsb (HSB hsb) {
34+
int i;
35+
double f, p, q, t;
36+
double r, g, b;
37+
38+
double hue, saturation, brightness;
39+
hue = (double) hsb.hue;
40+
saturation = (double) (hsb.saturation / 100.0);
41+
brightness = (double) (hsb.brightness / 100.0);
42+
43+
if (saturation == 0) {
44+
r = brightness;
45+
g = brightness;
46+
b = brightness;
47+
48+
red = (uint8) (r * 255 + 0.5);
49+
green = (uint8) (g * 255 + 0.5);
50+
blue = (uint8) (b * 255 + 0.5);
51+
52+
return;
53+
}
54+
55+
hue /= 60;
56+
i = (int) hue;
57+
f = hue - i;
58+
p = brightness * (1 - saturation);
59+
q = brightness * (1 - saturation * f);
60+
t = brightness * (1 - saturation * (1 - f));
61+
62+
switch (i) {
63+
case 0:
64+
r = brightness;
65+
g = t;
66+
b = p;
67+
break;
68+
case 1:
69+
r = q;
70+
g = brightness;
71+
b = p;
72+
break;
73+
case 2:
74+
r = p;
75+
g = brightness;
76+
b = t;
77+
break;
78+
case 3:
79+
r = p;
80+
g = q;
81+
b = brightness;
82+
break;
83+
case 4:
84+
r = t;
85+
g = p;
86+
b = brightness;
87+
break;
88+
default:
89+
r = brightness;
90+
g = p;
91+
b = q;
92+
break;
93+
}
94+
95+
red = (uint8) (r * 255 + 0.5);
96+
green = (uint8) (g * 255 + 0.5);
97+
blue = (uint8) (b * 255 + 0.5);
98+
}
99+
100+
public string to_hex () {
101+
return "#%02x%02x%02x".printf (red, green, blue);
102+
}
32103
}

src/config/Constants.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ namespace Config {
2323
public const string APP_ID = "com.github.manexim.home";
2424
public const string APP_AUTHOR = "Manexim";
2525
public const string APP_NAME = "Home";
26-
public const string APP_VERSION = "0.4.2";
26+
public const string APP_VERSION = "0.5.0";
2727
}

src/controllers/DeviceController.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public abstract class Controllers.DeviceController : Object {
3434

3535
public abstract void switch_brightness (uint16 brightness);
3636

37+
public abstract void switch_hsb (uint16 hue, uint16 saturation, uint16 brightness);
38+
3739
public abstract void switch_color_temperature (uint16 color_temperature);
3840

3941
public abstract void switch_power (bool on);

src/lifx/Controller.vala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ public class Lifx.Controller : Controllers.DeviceController {
5151
lamp.brightness = brightness;
5252
}
5353

54+
public override void switch_hsb (uint16 hue, uint16 saturation, uint16 brightness) {
55+
var lamp = device as Lifx.Lamp;
56+
service.set_color (lamp, hue, saturation, brightness, 0, 0);
57+
58+
lamp.hue = hue;
59+
lamp.saturation = saturation;
60+
lamp.brightness = brightness;
61+
}
62+
5463
public override void switch_color_temperature (uint16 color_temperature) {
5564
var lamp = device as Lifx.Lamp;
5665
service.set_color (lamp, 0, 0, lamp.brightness, color_temperature, 0);

src/lifx/Packet.vala

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,26 @@ public class Lifx.Packet {
7474

7575
// payload
7676
payload = new Json.Object ();
77-
const uint8 i = 36;
77+
const uint8 INDEX = 36;
7878

7979
switch (type) {
8080
case 3: // StateService
81-
payload.set_int_member ("service", buffer.read_uint8 (i));
82-
payload.set_int_member ("port", buffer.read_uint32_le (i + 1));
81+
payload.set_int_member ("service", buffer.read_uint8 (INDEX));
82+
payload.set_int_member ("port", buffer.read_uint32_le (INDEX + 1));
8383
break;
8484
case 13: // StateHostInfo
85-
payload.set_double_member ("signal", buffer.read_float_le (i));
86-
payload.set_int_member ("tx", buffer.read_uint32_le (i + 4));
87-
payload.set_int_member ("rx", buffer.read_uint32_le (i + 8));
85+
payload.set_double_member ("signal", buffer.read_float_le (INDEX));
86+
payload.set_int_member ("tx", buffer.read_uint32_le (INDEX + 4));
87+
payload.set_int_member ("rx", buffer.read_uint32_le (INDEX + 8));
8888
break;
8989
case 15: // StateHostFirmware
90-
payload.set_double_member ("signal", buffer.read_float_le (i));
91-
payload.set_int_member ("tx", buffer.read_uint32_le (i + 4));
92-
payload.set_int_member ("rx", buffer.read_uint32_le (i + 8));
90+
payload.set_double_member ("signal", buffer.read_float_le (INDEX));
91+
payload.set_int_member ("tx", buffer.read_uint32_le (INDEX + 4));
92+
payload.set_int_member ("rx", buffer.read_uint32_le (INDEX + 8));
9393
break;
9494
case 22: // StatePower
9595
Types.Power power = Types.Power.UNKNOWN;
96-
uint16 power_t = buffer.read_uint16_le (i);
96+
uint16 power_t = buffer.read_uint16_le (INDEX);
9797
if (power_t > 0) {
9898
power = Types.Power.ON;
9999
} else if (power_t == 0) {
@@ -102,10 +102,10 @@ public class Lifx.Packet {
102102
payload.set_int_member ("level", power);
103103
break;
104104
case 25: // StateLabel
105-
payload.set_string_member ("label", (string) buffer.slice (i, i + 32).raw);
105+
payload.set_string_member ("label", (string) buffer.slice (INDEX, INDEX + 32).raw);
106106
break;
107107
case 33: // StateVersion
108-
uint32 product = buffer.read_uint32_le (i + 4);
108+
uint32 product = buffer.read_uint32_le (INDEX + 4);
109109
string model = "";
110110
bool supports_color = false;
111111
bool supports_infrared = false;
@@ -255,26 +255,26 @@ public class Lifx.Packet {
255255
payload.set_boolean_member ("supportsMultizone", supports_multizone);
256256
break;
257257
case 107: // State
258-
payload.set_int_member ("hue", buffer.read_uint16_le (i));
259-
payload.set_int_member ("saturation", buffer.read_uint16_le (i + 2));
260-
payload.set_int_member ("brightness", buffer.read_uint16_le (i + 4));
261-
payload.set_int_member ("kelvin", buffer.read_uint16_le (i + 6));
258+
payload.set_int_member ("hue", buffer.read_uint16_le (INDEX));
259+
payload.set_int_member ("saturation", buffer.read_uint16_le (INDEX + 2));
260+
payload.set_int_member ("brightness", buffer.read_uint16_le (INDEX + 4));
261+
payload.set_int_member ("kelvin", buffer.read_uint16_le (INDEX + 6));
262262

263263
// power
264264
Types.Power power = Types.Power.UNKNOWN;
265-
uint16 power_t = buffer.read_uint16_le (i + 10);
265+
uint16 power_t = buffer.read_uint16_le (INDEX + 10);
266266
if (power_t > 0) {
267267
power = Types.Power.ON;
268268
} else if (power_t == 0) {
269269
power = Types.Power.OFF;
270270
}
271271
payload.set_int_member ("power", power);
272272

273-
payload.set_string_member ("label", (string) buffer.slice (i + 12, i + 44).raw);
273+
payload.set_string_member ("label", (string) buffer.slice (INDEX + 12, INDEX + 44).raw);
274274
break;
275275
case 118: // StatePower
276276
Types.Power power = Types.Power.UNKNOWN;
277-
uint16 power_t = buffer.read_uint16_le (i);
277+
uint16 power_t = buffer.read_uint16_le (INDEX);
278278
if (power_t > 0) {
279279
power = Types.Power.ON;
280280
} else if (power_t == 0) {
@@ -284,7 +284,7 @@ public class Lifx.Packet {
284284
break;
285285
default:
286286
var a = new Json.Array ();
287-
var raw = buffer.slice (i, (uint8) size).raw;
287+
var raw = buffer.slice (INDEX, (uint8) size).raw;
288288

289289
for (uint8 j = 0; j < raw.length; j++) {
290290
a.add_int_element (raw[j]);
@@ -326,11 +326,11 @@ public class Lifx.Packet {
326326
// frame address
327327
Buffer buf2 = new Buffer.alloc (16);
328328
for (uint8 i = 0; i < 8; i++) {
329-
buf2.write_uint8(target_parts[i], i);
329+
buf2.write_uint8 (target_parts[i], i);
330330
}
331331

332332
// header
333-
Buffer buf3 = new Buffer.alloc(12);
333+
Buffer buf3 = new Buffer.alloc (12);
334334
buf3.write_uint16_le (type, 8);
335335

336336
uint8 byte14 = (ack_required << 1) | res_required;

0 commit comments

Comments
 (0)