ZWave.CommandClasses.MeterReport.GetUnit C# (CSharp) Method

GetUnit() public static method

public static GetUnit ( MeterType type, byte scale ) : string
type MeterType
scale byte
return string
        public static string GetUnit(MeterType type, byte scale)
        {
            var electricityUnits = new[] { "kWh", "kVAh", "W", "pulses", "V", "A", "Power Factor", "" };
            var gasUnits = new[] { "cubic meters", "cubic feet", "", "pulses", "", "", "", "" };
            var waterUnits = new[] { "cubic meters", "cubic feet", "US gallons",  "pulses", "", "", "", ""};

            switch (type)
            {
                case MeterType.Electric: return electricityUnits[scale];
                case MeterType.Gas: return gasUnits[scale];
                case MeterType.Water: return waterUnits[scale];
                default: return string.Empty;
            }
        }

Usage Example

Ejemplo n.º 1
0
        internal MeterSupportedReport(Node node, byte[] payload) : base(node)
        {
            if (payload.Length < 2)
            {
                throw new ReponseFormatException($"The response was not in the expected format. {GetType().Name}: Payload: {BitConverter.ToString(payload)}");
            }

            CanReset = (payload[0] & 0x80) != 0;
            Type     = (MeterType)Enum.ToObject(typeof(MeterType), payload[0] & 0x1F);

            var units = new List <string>();

            for (byte i = 0; i < 8; ++i)
            {
                if ((payload[1] & (1 << i)) == (1 << i))
                {
                    units.Add(MeterReport.GetUnit(Type, i));
                }
            }
            Units = units.ToArray();
        }