Exemplo n.º 1
0
        private void HandleRequestZoneStatus(clsOmniLinkMessageQueueItem M, byte[] B, bool Timeout)
        {
            if (Timeout)
            {
                return;
            }

            clsOL2MsgExtendedStatus MSG = new clsOL2MsgExtendedStatus(OmniLink.Controller.Connection, B);

            for (byte i = 0; i < MSG.ZoneStatusCount(); i++)
            {
                clsZone zone = OmniLink.Controller.Zones[MSG.ObjectNumber(i)];
                zone.CopyExtendedStatus(MSG, i);
                MqttClient.PublishAsync(zone.ToTopic(Topic.state), zone.ToState(), MqttQualityOfServiceLevel.AtMostOnce, true);
            }
        }
Exemplo n.º 2
0
        private void HandleUnsolicitedExtendedStatus(byte[] B)
        {
            clsOL2MsgExtendedStatus MSG = new clsOL2MsgExtendedStatus(Controller.Connection, B);

            switch (MSG.ObjectType)
            {
            case enuObjectType.Area:
                for (byte i = 0; i < MSG.AreaCount(); i++)
                {
                    Controller.Areas[MSG.ObjectNumber(i)].CopyExtendedStatus(MSG, i);
                    OnAreaStatus?.Invoke(this, new AreaStatusEventArgs()
                    {
                        ID   = MSG.ObjectNumber(i),
                        Area = Controller.Areas[MSG.ObjectNumber(i)]
                    });
                }
                break;

            case enuObjectType.Auxillary:
                for (byte i = 0; i < MSG.AuxStatusCount(); i++)
                {
                    Controller.Zones[MSG.ObjectNumber(i)].CopyAuxExtendedStatus(MSG, i);
                    OnZoneStatus?.Invoke(this, new ZoneStatusEventArgs()
                    {
                        ID   = MSG.ObjectNumber(i),
                        Zone = Controller.Zones[MSG.ObjectNumber(i)]
                    });
                }
                break;

            case enuObjectType.Zone:
                for (byte i = 0; i < MSG.ZoneStatusCount(); i++)
                {
                    Controller.Zones[MSG.ObjectNumber(i)].CopyExtendedStatus(MSG, i);
                    OnZoneStatus?.Invoke(this, new ZoneStatusEventArgs()
                    {
                        ID   = MSG.ObjectNumber(i),
                        Zone = Controller.Zones[MSG.ObjectNumber(i)]
                    });
                }
                break;

            case enuObjectType.Thermostat:
                for (byte i = 0; i < MSG.ThermostatStatusCount(); i++)
                {
                    lock (tstat_lock)
                    {
                        Controller.Thermostats[MSG.ObjectNumber(i)].CopyExtendedStatus(MSG, i);
                        OnThermostatStatus?.Invoke(this, new ThermostatStatusEventArgs()
                        {
                            ID         = MSG.ObjectNumber(i),
                            Thermostat = Controller.Thermostats[MSG.ObjectNumber(i)],
                            EventTimer = false
                        });

                        if (!tstats.ContainsKey(MSG.ObjectNumber(i)))
                        {
                            tstats.Add(MSG.ObjectNumber(i), DateTime.Now);
                        }
                        else
                        {
                            tstats[MSG.ObjectNumber(i)] = DateTime.Now;
                        }

                        if (Global.verbose_thermostat_timer)
                        {
                            log.Debug("Unsolicited status received for Thermostat " + Controller.Thermostats[MSG.ObjectNumber(i)].Name);
                        }
                    }
                }
                break;

            case enuObjectType.Unit:
                for (byte i = 0; i < MSG.UnitStatusCount(); i++)
                {
                    Controller.Units[MSG.ObjectNumber(i)].CopyExtendedStatus(MSG, i);
                    OnUnitStatus?.Invoke(this, new UnitStatusEventArgs()
                    {
                        ID   = MSG.ObjectNumber(i),
                        Unit = Controller.Units[MSG.ObjectNumber(i)]
                    });
                }
                break;

            case enuObjectType.Message:
                for (byte i = 0; i < MSG.MessageCount(); i++)
                {
                    Controller.Messages[MSG.ObjectNumber(i)].CopyExtendedStatus(MSG, i);
                    OnMessageStatus?.Invoke(this, new MessageStatusEventArgs()
                    {
                        ID      = MSG.ObjectNumber(i),
                        Message = Controller.Messages[MSG.ObjectNumber(i)]
                    });
                }
                break;

            default:
                if (Global.verbose_unhandled)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (byte b in MSG.ToByteArray())
                    {
                        sb.Append(b.ToString() + " ");
                    }

                    log.Debug("Unhandled ExtendedStatus" + MSG.ObjectType.ToString() + " " + sb.ToString());
                }
                break;
            }
        }