Example #1
0
 /// <summary>
 /// Select the specified device in our tree view.
 /// </summary>
 /// <param name="aIdentifier"></param>
 void SelectDevice(string aIdentifier)
 {
     foreach (TreeNode n in iTreeViewDevices.Nodes)
     {
         SmartHome.Device d = (SmartHome.Device)n.Tag;
         if (d.Identifier == aIdentifier)
         {
             iTreeViewDevices.SelectedNode = n;
             n.ExpandAll();
         }
     }
 }
Example #2
0
        /// <summary>
        /// Update our UI controls based on application state.
        /// We mostly check the properties of the device currently selected.
        /// </summary>
        private void UpdateControls()
        {
            // Switch Socket
            iGroupBoxSwitchSocket.Enabled = false;
            iButtonSwitchToggle.Enabled   = false;
            iButtonSwitchOn.Enabled       = false;
            iButtonSwitchOff.Enabled      = false;
            // Radiator Thermostat
            iGroupBoxRadiatorThermostat.Enabled = false;
            iNumericUpDownTemperature.Enabled   = false;
            iComboBoxThermostat.Enabled         = false;

            if (iTreeViewDevices.SelectedNode == null ||
                !(iTreeViewDevices.SelectedNode.Tag is SmartHome.Device))
            {
                return;
            }

            SmartHome.Device device = (SmartHome.Device)iTreeViewDevices.SelectedNode.Tag;
            // Enable controls related to switch socket
            if (device.IsSwitchSocket)
            {
                iGroupBoxSwitchSocket.Enabled = true;
                iButtonSwitchToggle.Enabled   = true;
                iButtonSwitchOn.Enabled       = true;
                iButtonSwitchOff.Enabled      = true;
            }

            if (device.IsRadiatorThermostat)
            {
                iGroupBoxRadiatorThermostat.Enabled = true;
                iComboBoxThermostat.Enabled         = true;
                if (device.Thermostat.IsOnMax)
                {
                    iComboBoxThermostat.SelectedItem = SmartHome.Thermostat.Radiator.On;
                }
                else if (device.Thermostat.IsOff)
                {
                    iComboBoxThermostat.SelectedItem = SmartHome.Thermostat.Radiator.Off;
                }
                else
                {
                    iComboBoxThermostat.SelectedItem  = SmartHome.Thermostat.Radiator.Regulated;
                    iNumericUpDownTemperature.Enabled = true;
                    iNumericUpDownTemperature.Value   = (decimal)device.Thermostat.TargetTemperatureInCelsius;
                }
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void iNumericUpDownTemperature_ValueChanged(object sender, EventArgs e)
        {
            if (iTreeViewDevices.SelectedNode == null ||
                !(iTreeViewDevices.SelectedNode.Tag is SmartHome.Device))
            {
                return;
            }

            SmartHome.Device device = (SmartHome.Device)iTreeViewDevices.SelectedNode.Tag;
            if (!await device.SetTargetTemperature((float)iNumericUpDownTemperature.Value))
            {
                // Authenticate anew before trying one last time
                await Authenticate();

                SelectDevice(device.Identifier);
                await device.SetTargetTemperature((float)iNumericUpDownTemperature.Value);
            }
            await UpdateDeviceList(device.Identifier);
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void iButtonSwitchOff_Click(object sender, EventArgs e)
        {
            if (iTreeViewDevices.SelectedNode == null ||
                !(iTreeViewDevices.SelectedNode.Tag is SmartHome.Device))
            {
                return;
            }

            // Switch off if valid
            SmartHome.Device device = (SmartHome.Device)iTreeViewDevices.SelectedNode.Tag;
            if (await device.SwitchOff())
            {
                // Authenticate anew before trying one last time
                await Authenticate();

                SelectDevice(device.Identifier);
                await device.SwitchOff();
            }
        }
Example #5
0
        private async void iButtonSwitchToggle_Click(object sender, EventArgs e)
        {
            if (iTreeViewDevices.SelectedNode == null ||
                !(iTreeViewDevices.SelectedNode.Tag is SmartHome.Device))
            {
                return;
            }

            // Toggle our switch if valid
            SmartHome.Device device = (SmartHome.Device)iTreeViewDevices.SelectedNode.Tag;
            if (!await device.SwitchToggle())
            {
                // Authenticate anew before trying one last time
                await Authenticate();

                SelectDevice(device.Identifier);
                // I reckon we should still be able to use that device even though our device list was updated
                await device.SwitchToggle();
            }
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void iComboBoxThermostat_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (iTreeViewDevices.SelectedNode == null ||
                !(iTreeViewDevices.SelectedNode.Tag is SmartHome.Device))
            {
                return;
            }

            SmartHome.Device device = (SmartHome.Device)iTreeViewDevices.SelectedNode.Tag;

            SmartHome.Thermostat.Radiator thermostat = SmartHome.Thermostat.Radiator.Off;
            Enum.TryParse <SmartHome.Thermostat.Radiator>(iComboBoxThermostat.SelectedValue.ToString(), out thermostat);
            if (thermostat == SmartHome.Thermostat.Radiator.Regulated)
            {
                // Set target temperature
                if (!await device.SetTargetTemperature((float)iNumericUpDownTemperature.Value))
                {
                    // Authenticate anew before trying one last time
                    await Authenticate();

                    SelectDevice(device.Identifier);
                    await device.SetTargetTemperature((float)iNumericUpDownTemperature.Value);
                }
            }
            else
            {
                // Turn it on of off
                if (!await device.SetTargetTemperatureCode((int)thermostat))
                {
                    // Authenticate anew before trying one last time
                    await Authenticate();

                    SelectDevice(device.Identifier);
                    await device.SetTargetTemperatureCode((int)thermostat);
                }
            }

            await UpdateDeviceList(device.Identifier);
        }