예제 #1
0
        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,
            });
        }
예제 #2
0
        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,
            });
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }