Ejemplo n.º 1
0
        /// <summary>
        /// Populate our tree view with our devices information.
        /// </summary>
        /// <param name="aDeviceList"></param>
        void PopulateDevicesTree(SmartHome.DeviceList aDeviceList)
        {
            iTreeViewDevices.Nodes.Clear();
            UpdateControls();

            // For each device
            foreach (SmartHome.Device device in aDeviceList.Devices)
            {
                // Add a new node
                TreeNode deviceNode = iTreeViewDevices.Nodes.Add(device.Id, $"{device.Name} - {device.ProductName} by {device.Manufacturer}");
                deviceNode.Tag = device;

                // Check the functions of that device
                foreach (SmartHome.Function f in Enum.GetValues(typeof(SmartHome.Function)))
                {
                    if (device.Has(f))
                    {
                        // Add a new node for each supported function
                        TreeNode functionNode = deviceNode.Nodes.Add(f.ToString());
                        if (f == SmartHome.Function.TemperatureSensor)
                        {
                            // Add temperature sensor data
                            functionNode.Nodes.Add($"{device.Temperature.Reading} °C");
                            functionNode.Nodes.Add($"Offset: {device.Temperature.OffsetReading} °C");
                        }
                        else if (f == SmartHome.Function.SwitchSocket)
                        {
                            // Add switch socket data
                            functionNode.Nodes.Add($"Mode: {device.Switch.Mode.ToString()}");
                            functionNode.Nodes.Add($"Switched {device.Switch.State.ToString()}");
                            functionNode.Nodes.Add($"Lock: {device.Switch.Lock.ToString()}");
                            functionNode.Nodes.Add($"Device lock: {device.Switch.DeviceLock.ToString()}");
                        }
                        else if (f == SmartHome.Function.RadiatorThermostat)
                        {
                            // Add radiator thermostat data
                            functionNode.Nodes.Add($"Comfort temperature: {device.Thermostat.ComfortTemperatureInCelsius.ToString()} °C");
                            functionNode.Nodes.Add($"Economy temperature: {device.Thermostat.EconomyTemperatureInCelsius.ToString()} °C");
                            functionNode.Nodes.Add($"Current temperature: {device.Thermostat.CurrentTemperatureInCelsius.ToString()} °C");
                            functionNode.Nodes.Add($"Target temperature: {device.Thermostat.TargetTemperatureInCelsius.ToString()} °C");
                            functionNode.Nodes.Add($"Battery {device.Thermostat.Battery.ToString()}");
                            functionNode.Nodes.Add($"Lock: {device.Thermostat.Lock.ToString()}");
                            functionNode.Nodes.Add($"Device lock: {device.Thermostat.DeviceLock.ToString()}");
                        }
                        else if (f == SmartHome.Function.PowerMeter)
                        {
                            // Add power meter data
                            functionNode.Nodes.Add($"Power: {device.PowerMeter.PowerInWatt}W");
                            functionNode.Nodes.Add($"Energy: {device.PowerMeter.EnergyInKiloWattPerHour}kWh");
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Asynchronously update our device list
        /// </summary>
        async Task UpdateDeviceListAsync()
        {
            if (Program.FritzBoxClient == null)
            {
                return;
            }

            iDeviceList = await Program.FritzBoxClient.GetDeviceList();

            if (iDeviceList == null)
            {
                // Authenticate
                await Program.FritzBoxClient.Authenticate(Properties.Settings.Default.FritzBoxLogin, Properties.Settings.Default.DecryptFritzBoxPassword());

                // Try again
                iDeviceList = await Program.FritzBoxClient.GetDeviceList();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update our device list
        /// </summary>
        /// <returns></returns>
        async Task UpdateDeviceList()
        {
            SmartHome.DeviceList deviceList = await iClient.GetDeviceList();

            PopulateDevicesTree(deviceList);
        }