Esempio n. 1
0
        public void Update(IDeviceState state, bool fromDatabase = false)
        {
            //TODO: update more properties?

            if (!fromDatabase)
            {
                if (Name == null && state.Name != null)
                {
                    Name = state.Name;
                }

                if ((Type == null || Type.Equals(DeviceType.Unknown)) && state.Type != null)
                {
                    Type = state.Type;
                }
            }

            Location = (state.Location == null) ? null : new Location(state.Location.GetParts());

            IsConnected   = state.IsConnected;
            CurrentAction = state.CurrentAction;

            BinarySwitch.Update(state.BinarySwitchState ?? ReadOnlyBinarySwitchSwitchState.Blank());
            MultilevelSwitch.Update(state.MultilevelSwitchState ?? ReadOnlyMultilevelSwitchState.Blank());
            ColorSwitch.Update(state.ColorSwitchState ?? ReadOnlyColorSwitchState.Blank());
            BinarySensor.Update(state.BinarySensorState ?? ReadOnlyBinarySensorState.Blank());
            PowerSensor.Update(state.PowerSensorState ?? ReadOnlyMultilevelSensorState <IPower> .Blank());
            TemperatureSensor.Update(state.TemperatureSensorState ?? ReadOnlyMultilevelSensorState <ITemperature> .Blank());
            HumiditySensor.Update(state.HumiditySensorState ?? ReadOnlyMultilevelSensorState <IHumidity> .Blank());
            IlluminanceSensor.Update(state.IlluminanceSensorState ?? ReadOnlyMultilevelSensorState <IIlluminance> .Blank());
            Thermostat.Update(state.ThermostatState ?? ReadOnlyThermostatState.Blank());
        }
        public static OperationMessage RefreshState(this PowerSensor powerSensor)
        {
            ushort destinationAddress = (ushort)(powerSensor.Connector == null ? 0 : powerSensor.Connector.Node.Address);

            return(OperationMessage.PowerRead((ushort)powerSensor.Id, destinationAddress));
        }