public static async Task <DeviceState> ToDeviceUpdate(this NodeValueUpdate update) { var command = await update.GetNodeCommand(); if (!ZWaveCommands.ZWaveCommandsToRosieCommandsDictionary.TryGetValue(command.Id, out var rosieKey)) { return(null); } if (command.ShouldIgnore()) { return(null); } var node = await NodeDatabase.Shared.GetDevice(update.NodeId); var dataType = command.GetDataType(update); //TODO change value if needed return(new DeviceState { DeviceId = node.Id, DataType = dataType, Value = update?.Value?.Value, PropertyKey = rosieKey, }); }
public static async Task <DeviceState> ToDeviceUpdate(this NodeValueUpdate update) { var command = await update.GetNodeCommand(); if (command.ShouldIgnore()) { return(null); } var node = await NodeDatabase.Shared.GetDevice(update.NodeId); var statusKey = command.StatusKey(); var dataType = command.GetDataType(update); return(new DeviceState { DeviceId = node.Id, DataType = dataType, Value = update.Value.Value, Key = statusKey, }); }
public static DataTypes GetDataType(this NodeCommand command, NodeValueUpdate update) { var commandId = command?.Id; switch (commandId) { case "37 - 0": return(DataTypes.Bool); case "49 - 1": return(DataTypes.Decimal); } if (update.Value.Values != null) { return(DataTypes.List); } var s = update.Value.Value?.ToString(); if (string.IsNullOrEmpty(s)) { return(DataTypes.String); } int i; if (int.TryParse(s, out i)) { return(DataTypes.Int); } double d; if (double.TryParse(s, out d)) { return(DataTypes.Decimal); } return(DataTypes.String); }
public static async Task <NodeCommand> GetNodeCommand(this NodeValueUpdate update) { var command = await NodeDatabase.Shared.DatabaseConnection.Table <NodeCommand>().Where(x => x.ClassId == update.Value.ClassId && x.Index == update.Value.Index).FirstOrDefaultAsync(); return(command); }