public GridWindow() { InitializeComponent(); this.controller = new VeraController(new VeraConnectionInfo("192.168.0.222")); this.controller.DataReceived += new EventHandler <VeraDataReceivedEventArgs>(controller_DataReceived); this.controller.DataSent += new EventHandler <VeraDataSentEventArgs>(controller_DataSent); }
public override void OnStart() { PackageHost.WriteInfo("Initializing Vera"); vera = new VeraController(new VeraConnectionInfo(PackageHost.GetSettingValue <string>("VeraHost"))); vera.ErrorOccurred += (s, e) => PackageHost.WriteError("ErrorOccurred: {0}", e.Exception.ToString()); vera.DeviceUpdated += (s, e) => this.PushDevice(e.Device); vera.SceneUpdated += (s, e) => { if (e.Scene != null && !string.IsNullOrEmpty(e.Scene.Name)) { PackageHost.WriteInfo("Updating scene '{0}' ({1})", e.Scene.Name, e.Scene.Id); PackageHost.PushStateObject(e.Scene.Name, new Scene { Id = e.Scene.Id, IsActive = e.Scene.IsActive, LastUpdate = e.Scene.LastUpdate, Name = e.Scene.Name, Room = e.Scene.Room != null ? e.Scene.Room.Name : string.Empty, State = e.Scene.State }); } }; vera.DataReceived += (s, e) => { if (!string.IsNullOrEmpty(vera.SerialNumber)) { PackageHost.PushStateObject("Vera_" + vera.SerialNumber, new VeraDevice { DataVersion = e.DataVersion, LoadTime = e.LoadTime, State = vera.CurrentState.ToString(), Comment = vera.CurrentComment, Model = vera.Model, SerialNumber = vera.SerialNumber, Version = vera.Version }); } }; PackageHost.WriteInfo("Perform a full request ..."); vera.WaitForFullRequest(); PackageHost.WriteInfo("Starting listener ..."); vera.StartListener(); PackageHost.WriteInfo("Vera lite ready !"); }
/// <summary> /// Called when the package is started. /// </summary> public override void OnStart() { PackageHost.WriteInfo("Initializing Vera"); vera = new VeraController(new VeraConnectionInfo(PackageHost.GetSettingValue <string>("VeraHost"))); vera.ErrorOccurred += (s, e) => PackageHost.WriteError("ErrorOccurred: {0}", e.Exception.ToString()); vera.DeviceUpdated += (s, e) => this.PushDevice(e.Device); vera.SceneUpdated += (s, e) => { if (e.Scene != null && !string.IsNullOrEmpty(e.Scene.Name)) { PackageHost.WriteInfo("Updating scene '{0}' ({1})", e.Scene.Name, e.Scene.Id); PackageHost.PushStateObject(e.Scene.Name, new Scene { Id = e.Scene.Id, IsActive = e.Scene.IsActive, LastUpdate = e.Scene.LastUpdate, Name = e.Scene.Name, Room = e.Scene.Room != null ? e.Scene.Room.Name : string.Empty, State = e.Scene.State }); } }; vera.HouseModeChanged += (s, e) => { PushVeraDevice(); PackageHost.WriteInfo("The house mode has changed to '{0}' (from '{1}')", e.NewMode.ToString(), e.OldMode.ToString()); }; vera.DataReceived += (s, e) => { if (!string.IsNullOrEmpty(vera.SerialNumber)) { PushVeraDevice(); } }; PackageHost.WriteInfo("Perform a full request ..."); vera.WaitForFullRequest(); PackageHost.WriteInfo("Starting listener ..."); vera.StartListener(); PackageHost.WriteInfo("Vera lite ready !"); }
private static void ExecuteHotkey(Hotkey hotkey) { ParallelOptions parallelOptions = new ParallelOptions(); parallelOptions.MaxDegreeOfParallelism = 16; Parallel.ForEach(hotkey.effects, parallelOptions, effect => { switch (effect.type) { case EffectType.HttpGet: { if (!string.IsNullOrWhiteSpace(effect.data.httpget_url) && Uri.TryCreate(effect.data.httpget_url, UriKind.Absolute, out Uri result)) { http_fast.GET(effect.data.httpget_url); } break; } case EffectType.BroadLink: { BroadLinkController broadLink = ServiceWrapper.config.broadLinks.Get(effect.data.broadlink_name); if (broadLink == null) { Logger.Info("BroadLink \"" + effect.data.broadlink_name + "\" does not exist."); break; } broadLink.SendCommandSync(effect.data.broadlink_commandName, effect.data.broadlink_repeatCount); break; } case EffectType.iTach: { iTachController iTach = ServiceWrapper.config.iTachs.Get(effect.data.itach_name); if (iTach == null) { Logger.Info("iTach \"" + effect.data.itach_name + "\" does not exist."); break; } iTach.SendCommandSync(effect.data.itach_commandShortName, effect.data.itach_connectorAddress, effect.data.itach_repeatCount); break; } case EffectType.Vera: { VeraController vera = ServiceWrapper.config.veras.Get(effect.data.vera_name); if (vera == null) { Logger.Info("Vera \"" + effect.data.vera_name + "\" does not exist."); break; } vera.Send(effect.data); break; } case EffectType.HomeAssistant: { HomeAssistantServer hassServer = ServiceWrapper.config.homeAssistantServers.Get(effect.data.hass_servername); if (hassServer == null) { Logger.Info("HomeAssistant Server \"" + effect.data.hass_servername + "\" does not exist."); break; } hassServer.CallService(effect.data.hass_entityid, effect.data.hass_method.Value, effect.data.hass_value); break; } default: Logger.Info("Unhandled hotkey effect type: " + effect.type + " in hotkey with name \"" + hotkey.name + "\""); break; } }); }