Пример #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());
        }
Пример #2
0
        public void Poll()
        {
            if (Type == DeviceType.BinarySwitch)
            {
                BinarySwitch.Poll();
                return;
            }

            if (Type == DeviceType.MultilevelSwitch)
            {
                MultilevelSwitch.Poll();
                return;
            }

            if (ColorSwitch != null)
            {
                ColorSwitch.Poll();
            }

            if (Type == DeviceType.Thermostat)
            {
                if (TemperatureSensor != null)
                {
                    TemperatureSensor.Poll();
                }

                if (Thermostat.Core != null)
                {
                    Thermostat.Core.PollCurrentAction();
                    Thermostat.Core.PollMode();
                    Thermostat.Core.PollSupportedModes();
                }

                if (Thermostat.Fan != null)
                {
                    Thermostat.Fan.PollCurrentAction();
                    Thermostat.Fan.PollMode();
                    Thermostat.Fan.PollSupportedModes();
                }

                if (Thermostat.Setpoints != null)
                {
                    Thermostat.Setpoints.PollSupportedSetpoints();
                    Thermostat.Setpoints.PollSetpointTemperatures();
                }
            }
        }