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 c32ab31 commit f55b398
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 45 deletions.
38 changes: 19 additions & 19 deletions src/lifx/Packet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ public class Lifx.Packet {

switch (type) {
case 3: // StateService
payload.set_int_member ("service", buffer.read_uint8 (INDEX)));
payload.set_int_member ("port", buffer.read_uint32_le (INDEX) + 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 (INDEX)));
payload.set_int_member ("tx", buffer.read_uint32_le (INDEX) + 4));
payload.set_int_member ("rx", buffer.read_uint32_le (INDEX) + 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 (INDEX)));
payload.set_int_member ("tx", buffer.read_uint32_le (INDEX) + 4));
payload.set_int_member ("rx", buffer.read_uint32_le (INDEX) + 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 (INDEX));
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 (INDEX), INDEX + 32).raw);
payload.set_string_member ("label", (string) buffer.slice (INDEX, INDEX + 32).raw);
break;
case 33: // StateVersion
uint32 product = buffer.read_uint32_le (INDEX) + 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 (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));
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 (INDEX) + 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 (INDEX) + 12, INDEX + 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 (INDEX));
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 (INDEX), (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
17 changes: 9 additions & 8 deletions src/philips/hue/BridgeController.vala
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ public class Philips.Hue.BridgeController {

session.send_message (message);

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

var patched = r.replace (
(string) message.response_body.data, (ssize_t) message.response_body.length, 0, "<root>"
);
Expand Down Expand Up @@ -111,7 +112,7 @@ public class Philips.Hue.BridgeController {
_bridge.model = node->get_content ();

delete obj;
} catch (GLib.RegexError e) {
} catch (RegexError e) {
stderr.printf (e.message);
} finally {
delete doc;
Expand All @@ -120,7 +121,7 @@ public class Philips.Hue.BridgeController {
Xml.Parser.cleanup ();
}

public bool register () throws GLib.Error {
public bool register () throws Error {
#if DEMO_MODE
if (register_counter++ == 2) {
_bridge.power = Types.Power.ON;
Expand Down Expand Up @@ -158,8 +159,8 @@ public class Philips.Hue.BridgeController {
var obj = element.get_object ();

if (obj.has_member ("error")) {
throw new GLib.Error (
GLib.Quark.from_string (""),
throw new Error (
Quark.from_string (""),
(int) obj.get_object_member ("error").get_int_member ("type"),
obj.get_object_member ("error").get_string_member ("description")
);
Expand Down Expand Up @@ -244,7 +245,7 @@ public class Philips.Hue.BridgeController {
on_updated_lamp (lamp);
}
}
} catch (GLib.Error e) {
} catch (Error e) {
stderr.printf (e.message);
}
}
Expand Down
36 changes: 20 additions & 16 deletions src/philips/hue/Service.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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]*).*";
var r_hue_bridgeid = new GLib.Regex (".*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,22 +244,26 @@ public class Philips.Hue.Service {
}

private void found_bridge_ssdp (string bridgeid, string message) {
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)) {
url = mi.fetch (1);
protocol = mi.fetch (2);
host = mi.fetch (3);
port = mi.fetch (4);
path = mi.fetch (5);

var bridge = new Bridge ();
bridge.id = bridgeid.up ();
bridge.base_url = protocol + host + ":" + port + "/";

found_bridge (bridge);
try {
var r_location = new Regex (".*LOCATION:\\s*((http:\\/\\/)(.*):(\\d*)([^\\s]*)).*");
string url, protocol, host, port, path;
GLib.MatchInfo mi;
if (r_location.match (message, 0, out mi)) {
url = mi.fetch (1);
protocol = mi.fetch (2);
host = mi.fetch (3);
port = mi.fetch (4);
path = mi.fetch (5);

var bridge = new Bridge ();
bridge.id = bridgeid.up ();
bridge.base_url = protocol + host + ":" + port + "/";

found_bridge (bridge);

}
} catch (RegexError e) {
stderr.printf (e.message);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/Buffer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public class Buffer {

public uint16 read_uint16_le (uint8 offset) {
if (Platform.is_big_endian ()) {
return this.readUInt16Backwards (offset);
return this.read_uint16_backwards (offset);
}

return this.readUInt16Forwards (offset);
return this.read_uint16_forwards (offset);
}

private uint8 writer_uint16_backwards (uint16 value, uint8 offset) {
Expand Down

0 comments on commit f55b398

Please sign in to comment.