@@ -55,211 +55,6 @@ pub fn main() !void {
log.err("end going to exit", .{});
}
const Z2m = struct {
const bridge = struct {
const state = struct {};
const info = struct {
commit: ?[]const u8 = null,
config: ?struct {} = null,
config_schema: ?struct {} = null,
coordinator: ?struct {
ieee_address: []const u8,
meta: struct {},
type: []const u8,
} = null,
log_level: ?[]const u8 = null,
network: ?struct {
channel: usize,
extended_pan_id: usize,
pan_id: usize,
},
permit_join: bool,
restart_required: bool,
version: []const u8,
zigbee_herdsman: struct {
version: []const u8,
},
zigbee_herdsman_converters: struct {
version: []const u8,
},
};
const logging = struct {
level: []const u8,
message: []const u8,
};
const groups = struct {
friendly_name: []const u8,
id: usize,
members: []struct {
endpoint: usize,
ieee_address: []const u8,
},
scenes: []struct {
id: usize,
name: []const u8,
},
};
const definitions = struct {};
const extensions = struct {};
const devices = struct {
definition: ?Definition = null,
date_code: ?[]const u8 = null,
disabled: ?bool = null,
endpoints: ?Endpoints = null,
friendly_name: ?[]const u8 = null,
ieee_address: ?[]const u8 = null,
interview_completed: ?bool = null,
interviewing: ?bool = null,
network_address: ?usize = null,
supported: ?bool = null,
type: ?[]const u8 = null,
manufacturer: ?[]const u8 = null,
model_id: ?[]const u8 = null,
power_source: ?[]const u8 = null,
software_build_id: ?[]const u8 = null,
pub const Definition = struct {
description: ?[]const u8,
exposes: ?[]Exposed = null,
model: ?[]const u8 = null,
options: ?[]struct {} = null,
supports_ota: ?bool = null,
vendor: ?[]const u8 = null,
};
pub const Exposed = struct {
features: ?[]struct {
access: ?usize = null,
description: ?[]const u8 = null,
label: ?[]const u8 = null,
name: ?[]const u8 = null,
property: ?[]const u8 = null,
type: ?[]const u8 = null,
value_off: ?[]const u8 = null,
value_on: ?[]const u8 = null,
value_toggle: ?[]const u8 = null,
} = null,
description: ?[]const u8 = null,
name: ?[]const u8 = null,
};
pub const Endpoints = struct {
@"1": ?EndpointObject = null,
@"2": ?EndpointObject = null,
@"3": ?EndpointObject = null,
@"4": ?EndpointObject = null,
@"242": ?EndpointObject = null,
};
pub const EndpointObject = struct {
bindings: ?[]struct {
cluster: ?[]const u8,
target: ?struct {
endpoint: ?usize,
ieee_address: ?[]const u8,
type: ?[]const u8,
},
configured_reportings: ?[]struct {
attribute: []const u8,
cluster: []const u8,
maximum_report_interval: usize,
minimum_report_interval: usize,
reportable_change: usize,
} = null,
scenes: ?[]struct {} = null,
} = null,
clusters: ?struct {
input: ?[][]const u8,
output: ?[][]const u8,
} = null,
};
};
};
};
pub const Rules = struct {
// edge falling device/name/attribute
//
// do <complex target>
// set <device> [verb] <noun>
// when office/mmw0/presence goes false set office/lights off
// when office/mmw0/presence goes true set office/lights on
//
// sequence
//
//
pub const Rule = struct {
rule: Kind,
target: []const u8,
action: Action = .{},
pub const Kind = union(enum) {
edge: Direction,
slope: struct {
direction: Direction,
vect: f64,
},
};
pub const Direction = enum {
falling,
rising,
};
pub const Action = struct {};
};
pub fn parse(a: Allocator, str: []const u8) ![]Rule {
var list = std.ArrayList(Rule).init(a);
errdefer list.deinit();
var tokens = std.mem.tokenizeScalar(u8, str, ' ');
while (tokens.next()) |next| {
if (eqlAny(next, "edge")) {
const peek = tokens.peek() orelse return error.InvalidSyntax;
if (eqlAny(peek, "falling")) {
try list.append(.{
.rule = .{ .edge = .falling },
.target = "",
});
_ = tokens.next();
} else {
try list.append(.{
.rule = .{ .edge = .rising },
.target = "",
});
_ = tokens.next();
}
}
}
return try list.toOwnedSlice();
}
test parse {
const a = std.testing.allocator;
const empty = try parse(a, "");
try std.testing.expectEqual(&[0]Rule{}, empty);
const one = try parse(a, "edge falling");
defer a.free(one);
try std.testing.expectEqualDeep(&[1]Rule{.{
.rule = .{ .edge = .falling },
.target = "",
}}, one);
const one_ri = try parse(a, "edge rising");
defer a.free(one_ri);
try std.testing.expectEqualDeep(&[1]Rule{.{
.rule = .{ .edge = .rising },
.target = "",
}}, one_ri);
}
};
pub const Device = struct {
name: []const u8,
address: []const u8,
@@ -538,6 +333,8 @@ test "main" {
}
const mqtt = @import("mqtt");
const Rules = @import("rules.zig");
const Z2m = @import("z2m-data.zig").Z2m;
const std = @import("std");
const Allocator = std.mem.Allocator;