From f55b398d03a57be35418ff7376eae6880dad59d3 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 3 Nov 2019 14:34:04 +0100 Subject: [PATCH] Satisfy linter --- src/lifx/Packet.vala | 38 +++++++++++++-------------- src/philips/hue/BridgeController.vala | 17 ++++++------ src/philips/hue/Service.vala | 36 ++++++++++++++----------- src/utils/Buffer.vala | 4 +-- 4 files changed, 50 insertions(+), 45 deletions(-) diff --git a/src/lifx/Packet.vala b/src/lifx/Packet.vala index 647f85c..4694f7a 100644 --- a/src/lifx/Packet.vala +++ b/src/lifx/Packet.vala @@ -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) { @@ -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; @@ -255,14 +255,14 @@ 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) { @@ -270,11 +270,11 @@ public class Lifx.Packet { } 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) { @@ -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]); diff --git a/src/philips/hue/BridgeController.vala b/src/philips/hue/BridgeController.vala index ff89564..a58917f 100644 --- a/src/philips/hue/BridgeController.vala +++ b/src/philips/hue/BridgeController.vala @@ -43,11 +43,12 @@ public class Philips.Hue.BridgeController { session.send_message (message); - // replace with - // because otherwise the node can not be found - GLib.Regex r = ".*().*"; Xml.Doc* doc; try { + // replace with + // because otherwise the node can not be found + var r = new Regex (".*().*"); + var patched = r.replace ( (string) message.response_body.data, (ssize_t) message.response_body.length, 0, "" ); @@ -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; @@ -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; @@ -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") ); @@ -244,7 +245,7 @@ public class Philips.Hue.BridgeController { on_updated_lamp (lamp); } } - } catch (GLib.Error e) { + } catch (Error e) { stderr.printf (e.message); } } diff --git a/src/philips/hue/Service.vala b/src/philips/hue/Service.vala index 736765f..bdf311c 100644 --- a/src/philips/hue/Service.vala +++ b/src/philips/hue/Service.vala @@ -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)) { @@ -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); } } diff --git a/src/utils/Buffer.vala b/src/utils/Buffer.vala index ee0f4a0..fd20db0 100644 --- a/src/utils/Buffer.vala +++ b/src/utils/Buffer.vala @@ -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) {