Skip to content

Commit

Permalink
Satisfy linter
Browse files Browse the repository at this point in the history
  • Loading branch information
meisenzahl committed Nov 3, 2019
1 parent 52dc0b3 commit c32ab31
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 95 deletions.
4 changes: 3 additions & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public class Application : Granite.Application {

var css_provider = new Gtk.CssProvider ();
css_provider.load_from_resource ("com/github/manexim/home/styles/application.css");
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
Gtk.StyleContext.add_provider_for_screen (
Gdk.Screen.get_default (), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
);
}

public static int main (string[] args) {
Expand Down
44 changes: 22 additions & 22 deletions src/lifx/Packet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,26 @@ public class Lifx.Packet {

// payload
payload = new Json.Object ();
const uint8 i = 36;
const uint8 INDEX = 36;

switch (type) {
case 3: // StateService
payload.set_int_member ("service", buffer.read_uint8 (i));
payload.set_int_member ("port", buffer.read_uint32_le (i + 1));
payload.set_int_member ("service", buffer.read_uint8 (INDEX)));
payload.set_int_member ("port", buffer.read_uint32_le (INDEX) + 1));
break;
case 13: // StateHostInfo
payload.set_double_member ("signal", buffer.read_float_le (i));
payload.set_int_member ("tx", buffer.read_uint32_le (i + 4));
payload.set_int_member ("rx", buffer.read_uint32_le (i + 8));
payload.set_double_member ("signal", buffer.read_float_le (INDEX)));
payload.set_int_member ("tx", buffer.read_uint32_le (INDEX) + 4));
payload.set_int_member ("rx", buffer.read_uint32_le (INDEX) + 8));
break;
case 15: // StateHostFirmware
payload.set_double_member ("signal", buffer.read_float_le (i));
payload.set_int_member ("tx", buffer.read_uint32_le (i + 4));
payload.set_int_member ("rx", buffer.read_uint32_le (i + 8));
payload.set_double_member ("signal", buffer.read_float_le (INDEX)));
payload.set_int_member ("tx", buffer.read_uint32_le (INDEX) + 4));
payload.set_int_member ("rx", buffer.read_uint32_le (INDEX) + 8));
break;
case 22: // StatePower
Types.Power power = Types.Power.UNKNOWN;
uint16 power_t = buffer.read_uint16_le (i);
uint16 power_t = buffer.read_uint16_le (INDEX));
if (power_t > 0) {
power = Types.Power.ON;
} else if (power_t == 0) {
Expand All @@ -102,10 +102,10 @@ public class Lifx.Packet {
payload.set_int_member ("level", power);
break;
case 25: // StateLabel
payload.set_string_member ("label", (string) buffer.slice (i, i + 32).raw);
payload.set_string_member ("label", (string) buffer.slice (INDEX), INDEX + 32).raw);
break;
case 33: // StateVersion
uint32 product = buffer.read_uint32_le (i + 4);
uint32 product = buffer.read_uint32_le (INDEX) + 4);
string model = "";
bool supports_color = false;
bool supports_infrared = false;
Expand Down Expand Up @@ -255,26 +255,26 @@ public class Lifx.Packet {
payload.set_boolean_member ("supportsMultizone", supports_multizone);
break;
case 107: // State
payload.set_int_member ("hue", buffer.read_uint16_le (i));
payload.set_int_member ("saturation", buffer.read_uint16_le (i + 2));
payload.set_int_member ("brightness", buffer.read_uint16_le (i + 4));
payload.set_int_member ("kelvin", buffer.read_uint16_le (i + 6));
payload.set_int_member ("hue", buffer.read_uint16_le (INDEX)));
payload.set_int_member ("saturation", buffer.read_uint16_le (INDEX) + 2));
payload.set_int_member ("brightness", buffer.read_uint16_le (INDEX) + 4));
payload.set_int_member ("kelvin", buffer.read_uint16_le (INDEX) + 6));

// power
Types.Power power = Types.Power.UNKNOWN;
uint16 power_t = buffer.read_uint16_le (i + 10);
uint16 power_t = buffer.read_uint16_le (INDEX) + 10);
if (power_t > 0) {
power = Types.Power.ON;
} else if (power_t == 0) {
power = Types.Power.OFF;
}
payload.set_int_member ("power", power);

payload.set_string_member ("label", (string) buffer.slice (i + 12, i + 44).raw);
payload.set_string_member ("label", (string) buffer.slice (INDEX) + 12, INDEX + 44).raw);
break;
case 118: // StatePower
Types.Power power = Types.Power.UNKNOWN;
uint16 power_t = buffer.read_uint16_le (i);
uint16 power_t = buffer.read_uint16_le (INDEX));
if (power_t > 0) {
power = Types.Power.ON;
} else if (power_t == 0) {
Expand All @@ -284,7 +284,7 @@ public class Lifx.Packet {
break;
default:
var a = new Json.Array ();
var raw = buffer.slice (i, (uint8) size).raw;
var raw = buffer.slice (INDEX), (uint8) size).raw;

for (uint8 j = 0; j < raw.length; j++) {
a.add_int_element (raw[j]);
Expand Down Expand Up @@ -326,11 +326,11 @@ public class Lifx.Packet {
// frame address
Buffer buf2 = new Buffer.alloc (16);
for (uint8 i = 0; i < 8; i++) {
buf2.write_uint8(target_parts[i], i);
buf2.write_uint8 (target_parts[i], i);
}

// header
Buffer buf3 = new Buffer.alloc(12);
Buffer buf3 = new Buffer.alloc (12);
buf3.write_uint16_le (type, 8);

uint8 byte14 = (ack_required << 1) | res_required;
Expand Down
8 changes: 5 additions & 3 deletions src/lifx/Service.vala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public class Lifx.Service {
}
}

public void set_color (Lifx.Lamp lamp, uint16 hue, uint16 saturation, uint16 brightness, uint16 kelvin, uint32 duration=0) {
public void set_color (
Lifx.Lamp lamp, uint16 hue, uint16 saturation, uint16 brightness, uint16 kelvin, uint32 duration=0
) {
var packet = new Lifx.Packet ();
packet.type = 102;
packet.tagged = false;
Expand Down Expand Up @@ -186,9 +188,9 @@ public class Lifx.Service {

#if HAVE_SO_REUSEPORT
int32 enable = 1;
Posix.setsockopt(
Posix.setsockopt (
socket.fd, Platform.Socket.SOL_SOCKET, Platform.Socket.SO_REUSEPORT, &enable,
(Posix.socklen_t) sizeof(int)
(Posix.socklen_t) sizeof (int)
);
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/pages/HueBridgeOnboardingPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Pages.HueBridgeOnboardingPage : Gtk.Grid {
label = new Gtk.Label (_("Press the push-link button in the middle of the Hue bridge."));

spinner = new Gtk.Spinner ();
spinner.start ();
spinner.start ();

attach (icon, 0, 0, 1, 1);
attach (label, 0, 1, 1, 1);
Expand Down
10 changes: 5 additions & 5 deletions src/pages/LoadingPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public class Pages.LoadingPage : Gtk.Grid {
valign = Gtk.Align.CENTER;

var label = new Gtk.Label (_("Looking for smart home gadgets to control."));
label.halign = Gtk.Align.CENTER;
label.valign = Gtk.Align.CENTER;
label.halign = Gtk.Align.CENTER;
label.valign = Gtk.Align.CENTER;

var spinner = new Gtk.Spinner ();
spinner.halign = Gtk.Align.CENTER;
spinner.valign = Gtk.Align.CENTER;
spinner.start ();
spinner.halign = Gtk.Align.CENTER;
spinner.valign = Gtk.Align.CENTER;
spinner.start ();

attach (label, 0, 0, 1, 1);
attach (spinner, 0, 2, 1, 1);
Expand Down
33 changes: 18 additions & 15 deletions src/philips/hue/BridgeController.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ public class Philips.Hue.BridgeController {

// replace <root xmlns="urn:schemas-upnp-org:device-1-0"> with <root>
// because otherwise the node can not be found
GLib.Regex r = /.*(<root.*>).*/;
GLib.Regex r = ".*(<root.*>).*";
Xml.Doc* doc;
try {
var patched = r.replace ((string) message.response_body.data, (ssize_t) message.response_body.length, 0, "<root>");
var patched = r.replace (
(string) message.response_body.data, (ssize_t) message.response_body.length, 0, "<root>"
);

Xml.Parser.init ();

Expand All @@ -57,19 +59,19 @@ public class Philips.Hue.BridgeController {
stderr.printf ("failed to read the .xml file\n");
}

Xml.XPath.Context context = new Xml.XPath.Context(doc);
Xml.XPath.Context context = new Xml.XPath.Context (doc);
if (context == null) {
stderr.printf ("failed to create the xpath context\n");
}

Xml.XPath.Object* obj = context.eval_expression("/root/device/friendlyName");
Xml.XPath.Object* obj = context.eval_expression ("/root/device/friendlyName");
if (obj == null) {
stderr.printf ("failed to evaluate xpath\n");
}

Xml.Node* node = null;
if (obj->nodesetval != null && obj->nodesetval->item(0) != null) {
node = obj->nodesetval->item(0);
if (obj->nodesetval != null && obj->nodesetval->item (0) != null) {
node = obj->nodesetval->item (0);
} else {
stderr.printf ("failed to find the expected node\n");
}
Expand All @@ -78,14 +80,14 @@ public class Philips.Hue.BridgeController {

delete obj;

obj = context.eval_expression("/root/device/manufacturer");
obj = context.eval_expression ("/root/device/manufacturer");
if (obj == null) {
stderr.printf ("failed to evaluate xpath\n");
}

node = null;
if (obj->nodesetval != null && obj->nodesetval->item(0) != null) {
node = obj->nodesetval->item(0);
if (obj->nodesetval != null && obj->nodesetval->item (0) != null) {
node = obj->nodesetval->item (0);
} else {
stderr.printf ("failed to find the expected node\n");
}
Expand All @@ -94,14 +96,14 @@ public class Philips.Hue.BridgeController {

delete obj;

obj = context.eval_expression("/root/device/modelName");
obj = context.eval_expression ("/root/device/modelName");
if (obj == null) {
stderr.printf ("failed to evaluate xpath\n");
}

node = null;
if (obj->nodesetval != null && obj->nodesetval->item(0) != null) {
node = obj->nodesetval->item(0);
if (obj->nodesetval != null && obj->nodesetval->item (0) != null) {
node = obj->nodesetval->item (0);
} else {
stderr.printf ("failed to find the expected node\n");
}
Expand Down Expand Up @@ -149,7 +151,7 @@ public class Philips.Hue.BridgeController {

string response = (string) message.response_body.flatten ().data;

var parser = new Json.Parser();
var parser = new Json.Parser ();
parser.load_from_data (response, -1);

foreach (var element in parser.get_root ().get_array ().get_elements ()) {
Expand Down Expand Up @@ -184,7 +186,7 @@ public class Philips.Hue.BridgeController {
string response = (string) message.response_body.flatten ().data;

try {
var parser = new Json.Parser();
var parser = new Json.Parser ();
parser.load_from_data (response, -1);
var object = parser.get_root ().get_object ();
var lights = object.get_object_member ("lights");
Expand All @@ -207,7 +209,8 @@ public class Philips.Hue.BridgeController {

if (light.get_object_member ("state").has_member ("ct")) {
lamp.supports_color_temperature = true;
lamp.color_temperature = (uint16) (1000000.0 / light.get_object_member ("state").get_int_member ("ct"));
lamp.color_temperature = (uint16) (1000000.0 / light.get_object_member ("state")
.get_int_member ("ct"));
}

if (light.get_object_member ("state").has_member ("hue")) {
Expand Down
8 changes: 4 additions & 4 deletions src/philips/hue/Service.vala
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ public class Philips.Hue.Service {

#if HAVE_SO_REUSEPORT
int32 enable = 1;
Posix.setsockopt(
Posix.setsockopt (
socket.fd, Platform.Socket.SOL_SOCKET, Platform.Socket.SO_REUSEPORT, &enable,
(Posix.socklen_t) sizeof(int)
(Posix.socklen_t) sizeof (int)
);
#endif

Expand All @@ -144,7 +144,7 @@ public class Philips.Hue.Service {
size_t read = s.receive (buffer);
buffer[read] = 0; // null-terminate string

GLib.Regex r_hue_bridgeid = /.*hue-bridgeid:\s*([^\s]*).*/;
GLib.Regex r_hue_bridgeid = ".*hue-bridgeid:\\s*([^\\s]*).*";
string hue_bridgeid;
GLib.MatchInfo mi;
if (r_hue_bridgeid.match ((string) buffer, 0, out mi)) {
Expand Down Expand Up @@ -244,7 +244,7 @@ public class Philips.Hue.Service {
}

private void found_bridge_ssdp (string bridgeid, string message) {
GLib.Regex r_location = /.*LOCATION:\s*((http:\/\/)(.*):(\d*)([^\s]*)).*/;
GLib.Regex r_location = ".*LOCATION:\\s*((http:\/\/)(.*):(\\d*)([^\\s]*)).*";
string url, protocol, host, port, path;
GLib.MatchInfo mi;
if (r_location.match (message, 0, out mi)) {
Expand Down
4 changes: 2 additions & 2 deletions src/services/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class Settings : Granite.Services.Settings {
return true;
},
(value, expected_type) => {
return new Variant.string(value.get_boolean() ? "dark" : "no-preference");
return new Variant.string (value.get_boolean () ? "dark" : "no-preference");
},
null,
null
Expand All @@ -102,7 +102,7 @@ public class Settings : Granite.Services.Settings {
}

public Json.Object configuration_as_json () throws GLib.Error {
var parser = new Json.Parser();
var parser = new Json.Parser ();
parser.load_from_data (configuration, -1);
var object = parser.get_root ().get_object ();

Expand Down
4 changes: 2 additions & 2 deletions src/types/Power.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public enum Types.Power {
OFF = 0,
ON = 65535;

public string to_string() {
public string to_string () {
switch (this) {
case UNKNOWN:
return "unknown";
Expand All @@ -37,7 +37,7 @@ public enum Types.Power {
return "on";
default:
print ("ERROR: Unsupported value %d\n", this);
assert_not_reached();
assert_not_reached ();
}
}
}
Loading

0 comments on commit c32ab31

Please sign in to comment.