Skip to content
Permalink
Browse files

Add automation toggle

  • Loading branch information
andrew-codechimp committed Jan 4, 2020
1 parent dfdcff7 commit adf3ee5df919a8f33999a8bc330c24005d171c91
Showing with 29 additions and 8 deletions.
  1. +8 −8 HA Menu.xcodeproj/project.pbxproj
  2. +20 −0 HA Menu/MenuItemController.swift
  3. +1 −0 HA Menu/Models/HaEntity.swift
@@ -583,15 +583,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 14;
DEVELOPMENT_TEAM = VZ3Z8BPWPW;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "HA Menu/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.12;
MARKETING_VERSION = 1.14;
PRODUCT_BUNDLE_IDENTIFIER = "org.codechimp.HA-Menu";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
@@ -606,15 +606,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 14;
DEVELOPMENT_TEAM = VZ3Z8BPWPW;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "HA Menu/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.12;
MARKETING_VERSION = 1.14;
PRODUCT_BUNDLE_IDENTIFIER = "org.codechimp.HA-Menu";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
@@ -711,15 +711,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 14;
DEVELOPMENT_TEAM = VZ3Z8BPWPW;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "HA Menu Launcher/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.12;
MARKETING_VERSION = 1.14;
PRODUCT_BUNDLE_IDENTIFIER = "org.codechimp.HA-Menu-Launcher";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
@@ -735,15 +735,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 14;
DEVELOPMENT_TEAM = VZ3Z8BPWPW;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "HA Menu Launcher/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.12;
MARKETING_VERSION = 1.14;
PRODUCT_BUNDLE_IDENTIFIER = "org.codechimp.HA-Menu-Launcher";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
@@ -157,6 +157,8 @@ final class MenuItemController: NSObject, NSMenuDelegate {
itemType = EntityTypes.lightType
case "input_boolean":
itemType = EntityTypes.inputBooleanType
case "automation":
itemType = EntityTypes.automation
default:
itemType = nil
}
@@ -231,6 +233,8 @@ final class MenuItemController: NSObject, NSMenuDelegate {
menuItem.action = #selector(self.toggleLight(_:))
case EntityTypes.inputBooleanType:
menuItem.action = #selector(self.toggleInputBoolean(_:))
case EntityTypes.automation:
menuItem.action = #selector(self.toggleAutomation(_:))
}

menuItem.target = self
@@ -339,6 +343,22 @@ final class MenuItemController: NSObject, NSMenuDelegate {
task.resume()
}

@objc func toggleAutomation(_ sender: NSMenuItem) {
let params = ["entity_id": sender.representedObject] as! Dictionary<String, String>

var request = createAuthURLRequest(url: URL(string: "\(prefs.server)/api/services/automation/toggle")!)

request.httpMethod = "POST"
request.httpBody = try? JSONSerialization.data(withJSONObject: params, options: [])

let session = URLSession.shared
let task = session.dataTask(with: request, completionHandler: { data, response, error -> Void in
print(String(data: data!, encoding: String.Encoding.utf8)!)
})

task.resume()
}

public func menuWillOpen(_ menu: NSMenu){
self.updateDynamicMenuItems()
}
@@ -12,6 +12,7 @@ enum EntityTypes: Int, CaseIterable {
case switchType = 2
case lightType = 3
case inputBooleanType = 4
case automation = 5
}

struct HaEntity {

0 comments on commit adf3ee5

Please sign in to comment.
You can’t perform that action at this time.