private void ImportCapability(string filePath) { try { string json = File.ReadAllText(filePath); var capability = JsonConvert.DeserializeObject <Capability>(json); var capabilityRequest = new CreateCapabilityRequest(capability.Id, capability.Attributes, capability.Commands); STClient.CreateCapability(capabilityRequest); ShowMessage($"Capability added!"); } catch (SmartThingsNet.Client.ApiException exp) { ShowErrorMessage($"Error {exp.ErrorCode}{Environment.NewLine}{exp.Message}"); } catch (Exception exp) { ShowErrorMessage($"Error {exp.Message}"); } finally { ImportItem(); } }
/// ----------------------------------------------------------------- /// <summary> /// </summary> // ----------------------------------------------------------------- protected ResponseBase CreateCapabilityRequestHandler(RequestBase irequest) { if (irequest.GetType() != typeof(CreateCapabilityRequest)) { return(OperationFailed("wrong type")); } CreateCapabilityRequest request = (CreateCapabilityRequest)irequest; // Get a handle to the scene for the request to be used later Scene scene; // if no scene is specified, then we'll just use a random one // in theory no scene needs to be set unless the services in each one are different if (String.IsNullOrEmpty(request._Scene)) { scene = m_sceneList[0]; } else if (!m_sceneCache.TryGetValue(request._Scene, out scene)) { return(OperationFailed("no scene specified")); } // Grab the account information and cache it for later use UserAccount account = null; if (request.UserID != UUID.Zero) { account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, request.UserID); } else if (!String.IsNullOrEmpty(request.FirstName) && !String.IsNullOrEmpty(request.LastName)) { account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, request.FirstName, request.LastName); } else if (!String.IsNullOrEmpty(request.EmailAddress)) { account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, request.EmailAddress); } if (account == null) { return(OperationFailed(String.Format("failed to locate account for user {0}", request.UserID.ToString()))); } // Authenticate the user with the hashed passwd from the request if (scene.AuthenticationService.Authenticate(account.PrincipalID, request.HashedPasswd, 0) == String.Empty) { return(OperationFailed(String.Format("failed to authenticate user {0}", account.PrincipalID.ToString()))); } if (!AuthorizeCapability(scene, account)) { return(OperationFailed(String.Format("user {0} is not authorized to access this interface", account.PrincipalID.ToString()))); } // OK... we have validated all the requirements for access to the dispatcher messages // so its now time to build & save the capability HashSet <String> dlist = new HashSet <String>(request.DomainList); // Clamp the lifespan for externally requested capabilities, region modules can register // caps with longer or infinite lifespans if (request.LifeSpan <= 0) { return(OperationFailed(String.Format("lifespan must be greater than 0 {0}", request.LifeSpan))); } int span = Math.Min(request.LifeSpan, m_maxLifeSpan); // add it to the authentication cache UUID capability = UUID.Random(); m_capCache.AddCapability(capability, account, dlist, scene.Name, span); return(new CapabilityResponse(capability, span)); }
public Capability CreateCapability(CreateCapabilityRequest capabilityRequest) { return(_capabilitiesApi.CreateCapability(_accessToken, capabilityRequest)); }
public Capability CreateCapability(CreateCapabilityRequest capabilityRequest) { return(_capabilitiesApi.CreateCapability(capabilityRequest)); }