Skip to content

Commit 45d24bf

Browse files
Added button and input_button
1 parent 957a512 commit 45d24bf

File tree

7 files changed

+92
-10
lines changed

7 files changed

+92
-10
lines changed

HA Menu.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -621,15 +621,15 @@
621621
CODE_SIGN_IDENTITY = "Apple Development";
622622
CODE_SIGN_STYLE = Automatic;
623623
COMBINE_HIDPI_IMAGES = YES;
624-
CURRENT_PROJECT_VERSION = 29;
624+
CURRENT_PROJECT_VERSION = 30;
625625
DEVELOPMENT_TEAM = VZ3Z8BPWPW;
626626
ENABLE_HARDENED_RUNTIME = YES;
627627
INFOPLIST_FILE = "HA Menu/Info.plist";
628628
LD_RUNPATH_SEARCH_PATHS = (
629629
"$(inherited)",
630630
"@executable_path/../Frameworks",
631631
);
632-
MARKETING_VERSION = 2.6.2;
632+
MARKETING_VERSION = 2.7.0;
633633
OTHER_SWIFT_FLAGS = "-D DEBUG";
634634
PRODUCT_BUNDLE_IDENTIFIER = "org.codechimp.HA-Menu";
635635
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -645,15 +645,15 @@
645645
CODE_SIGN_IDENTITY = "Apple Development";
646646
CODE_SIGN_STYLE = Automatic;
647647
COMBINE_HIDPI_IMAGES = YES;
648-
CURRENT_PROJECT_VERSION = 29;
648+
CURRENT_PROJECT_VERSION = 30;
649649
DEVELOPMENT_TEAM = VZ3Z8BPWPW;
650650
ENABLE_HARDENED_RUNTIME = YES;
651651
INFOPLIST_FILE = "HA Menu/Info.plist";
652652
LD_RUNPATH_SEARCH_PATHS = (
653653
"$(inherited)",
654654
"@executable_path/../Frameworks",
655655
);
656-
MARKETING_VERSION = 2.6.2;
656+
MARKETING_VERSION = 2.7.0;
657657
PRODUCT_BUNDLE_IDENTIFIER = "org.codechimp.HA-Menu";
658658
PRODUCT_NAME = "$(TARGET_NAME)";
659659
SWIFT_VERSION = 5.0;
@@ -750,15 +750,15 @@
750750
CODE_SIGN_IDENTITY = "Apple Development";
751751
CODE_SIGN_STYLE = Automatic;
752752
COMBINE_HIDPI_IMAGES = YES;
753-
CURRENT_PROJECT_VERSION = 29;
753+
CURRENT_PROJECT_VERSION = 30;
754754
DEVELOPMENT_TEAM = VZ3Z8BPWPW;
755755
ENABLE_HARDENED_RUNTIME = YES;
756756
INFOPLIST_FILE = "HA Menu Launcher/Info.plist";
757757
LD_RUNPATH_SEARCH_PATHS = (
758758
"$(inherited)",
759759
"@executable_path/../Frameworks",
760760
);
761-
MARKETING_VERSION = 2.6.2;
761+
MARKETING_VERSION = 2.7.0;
762762
PRODUCT_BUNDLE_IDENTIFIER = "org.codechimp.HA-Menu-Launcher";
763763
PRODUCT_NAME = "$(TARGET_NAME)";
764764
SKIP_INSTALL = YES;
@@ -774,15 +774,15 @@
774774
CODE_SIGN_IDENTITY = "Apple Development";
775775
CODE_SIGN_STYLE = Automatic;
776776
COMBINE_HIDPI_IMAGES = YES;
777-
CURRENT_PROJECT_VERSION = 29;
777+
CURRENT_PROJECT_VERSION = 30;
778778
DEVELOPMENT_TEAM = VZ3Z8BPWPW;
779779
ENABLE_HARDENED_RUNTIME = YES;
780780
INFOPLIST_FILE = "HA Menu Launcher/Info.plist";
781781
LD_RUNPATH_SEARCH_PATHS = (
782782
"$(inherited)",
783783
"@executable_path/../Frameworks",
784784
);
785-
MARKETING_VERSION = 2.6.2;
785+
MARKETING_VERSION = 2.7.0;
786786
PRODUCT_BUNDLE_IDENTIFIER = "org.codechimp.HA-Menu-Launcher";
787787
PRODUCT_NAME = "$(TARGET_NAME)";
788788
SKIP_INSTALL = YES;

HA Menu/AppDelegate.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ extension AppDelegate {
5656
"domain_scenes": true,
5757
"domain_scripts": true,
5858
"domain_covers": true,
59+
"domain_buttons": true,
60+
"domain_inputbuttons": true,
5961
"betaNotifications": false
6062
])
6163

HA Menu/MenuItemController.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ final class MenuItemController: NSObject, NSMenuDelegate {
243243
itemType = EntityTypes.sensorType
244244
case "cover":
245245
itemType = EntityTypes.coverType
246+
case "button":
247+
itemType = EntityTypes.buttonType
248+
case "input_button":
249+
itemType = EntityTypes.inputButtonType
246250

247251
default:
248252
itemType = nil
@@ -366,6 +370,16 @@ final class MenuItemController: NSObject, NSMenuDelegate {
366370
menuItem.state = NSControl.StateValue.off
367371
menuItem.offStateImage = NSImage(named: "PlayButtonImage")
368372
}
373+
else if haEntity.domainType == EntityDomains.buttonDomain {
374+
menuItem.action = #selector(self.pressEntity(_:))
375+
menuItem.state = NSControl.StateValue.off
376+
menuItem.offStateImage = NSImage(named: "PlayButtonImage")
377+
}
378+
else if haEntity.domainType == EntityDomains.inputButtonDomain {
379+
menuItem.action = #selector(self.pressEntity(_:))
380+
menuItem.state = NSControl.StateValue.off
381+
menuItem.offStateImage = NSImage(named: "PlayButtonImage")
382+
}
369383
else if haEntity.domainType == EntityDomains.sensorDomain {
370384
menuItem.title = haEntity.friendlyName + ": " + haEntity.state + haEntity.unitOfMeasurement
371385
menuItem.action = #selector(self.doNothing(_:))
@@ -468,7 +482,12 @@ final class MenuItemController: NSObject, NSMenuDelegate {
468482
let haEntity: HaEntity = sender.representedObject as! HaEntity
469483
haService.turnOnEntity(haEntity: haEntity)
470484
}
471-
485+
486+
@objc func pressEntity(_ sender: NSMenuItem) {
487+
let haEntity: HaEntity = sender.representedObject as! HaEntity
488+
haService.pressEntity(haEntity: haEntity)
489+
}
490+
472491
func checkForUpdate() {
473492
let parser = FeedParser(URL: releasesFeedURL)
474493

HA Menu/Models/HaEntity.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ enum EntityTypes: Int, CaseIterable {
1919
case scriptType = 9
2020
case sensorType = 10
2121
case coverType = 11
22+
case buttonType = 12
23+
case inputButtonType = 13
2224
case unknownType = 999
2325
}
2426

@@ -33,6 +35,8 @@ enum EntityDomains: String, CaseIterable {
3335
case groupDomain = "group"
3436
case sensorDomain = "sensor"
3537
case coverDomain = "cover"
38+
case buttonDomain = "button"
39+
case inputButtonDomain = "input_button"
3640
case unknownDomain = "unknown"
3741
}
3842

@@ -65,6 +69,10 @@ struct HaEntity {
6569
return EntityDomains.sensorDomain
6670
case EntityDomains.coverDomain.rawValue:
6771
return EntityDomains.coverDomain
72+
case EntityDomains.buttonDomain.rawValue:
73+
return EntityDomains.buttonDomain
74+
case EntityDomains.inputButtonDomain.rawValue:
75+
return EntityDomains.inputButtonDomain
6876

6977
case EntityDomains.groupDomain.rawValue:
7078
return EntityDomains.groupDomain
@@ -101,6 +109,10 @@ struct HaEntity {
101109
return EntityTypes.sensorType
102110
case EntityDomains.coverDomain:
103111
return EntityTypes.coverType
112+
case EntityDomains.buttonDomain:
113+
return EntityTypes.buttonType
114+
case EntityDomains.inputButtonDomain:
115+
return EntityTypes.inputButtonType
104116

105117
case EntityDomains.groupDomain:
106118
return EntityTypes.groupType

HA Menu/Models/HaService.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@ class HaService {
167167

168168
task.resume()
169169
}
170+
171+
func pressEntity(haEntity: HaEntity) {
172+
let params = ["entity_id": haEntity.entityId]
173+
let urlString = "\(prefs.server)/api/services/\(haEntity.domain)/press"
174+
175+
var request = createAuthURLRequest(url: URL(string: urlString)!)
176+
177+
request.httpMethod = "POST"
178+
request.httpBody = try? JSONSerialization.data(withJSONObject: params, options: [])
179+
180+
let session = URLSession.shared
181+
let task = session.dataTask(with: request, completionHandler: { data, response, error -> Void in
182+
print(String(data: data!, encoding: String.Encoding.utf8)!)
183+
})
184+
185+
task.resume()
186+
}
170187

171188

172189
}

HA Menu/Models/Preferences.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,26 @@ struct Preferences {
184184
UserDefaults.standard.synchronize()
185185
}
186186
}
187+
188+
var domainButtons: Bool {
189+
get {
190+
return UserDefaults.standard.bool(forKey: "domain_buttons")
191+
}
192+
set {
193+
UserDefaults.standard.set(newValue, forKey: "domain_buttons")
194+
UserDefaults.standard.synchronize()
195+
}
196+
}
197+
198+
var domainInputButtons: Bool {
199+
get {
200+
return UserDefaults.standard.bool(forKey: "domain_inputbuttons")
201+
}
202+
set {
203+
UserDefaults.standard.set(newValue, forKey: "domain_inputbuttons")
204+
UserDefaults.standard.synchronize()
205+
}
206+
}
187207

188208
var menuItems: [PrefMenuItem] {
189209
get {
@@ -211,6 +231,14 @@ struct Preferences {
211231
decodedResponse.append(PrefMenuItem(entityId: "cover", itemType: itemTypes.Domain, subMenu: true, enabled: domainCovers, friendlyName: "Covers"))
212232
}
213233

234+
if !domainExists(domain: "button", prefs: decodedResponse) {
235+
decodedResponse.append(PrefMenuItem(entityId: "button", itemType: itemTypes.Domain, subMenu: true, enabled: domainButtons, friendlyName: "Buttons"))
236+
}
237+
238+
if !domainExists(domain: "input_button", prefs: decodedResponse) {
239+
decodedResponse.append(PrefMenuItem(entityId: "input_button", itemType: itemTypes.Domain, subMenu: true, enabled: domainButtons, friendlyName: "Input Buttons"))
240+
}
241+
214242
return decodedResponse
215243
}
216244
catch {
@@ -237,6 +265,10 @@ struct Preferences {
237265

238266
decodedResponse.append(PrefMenuItem(entityId: "cover", itemType: itemTypes.Domain, subMenu: true, enabled: domainCovers, friendlyName: "Covers"))
239267

268+
decodedResponse.append(PrefMenuItem(entityId: "button", itemType: itemTypes.Domain, subMenu: true, enabled: domainButtons, friendlyName: "Buttons"))
269+
270+
decodedResponse.append(PrefMenuItem(entityId: "input_button", itemType: itemTypes.Domain, subMenu: true, enabled: domainInputButtons, friendlyName: "Input Buttons"))
271+
240272
// Init Groups from old setting
241273
for group in groups {
242274
decodedResponse.append(PrefMenuItem(entityId: group, itemType: itemTypes.Group, subMenu: false, enabled: true, friendlyName: ""))

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
A Mac OS Menu Bar app to perform common Home Assistant functions
55
Currently HA Menu supports
66
* Turning available switches, lights, automations and input_boolean's on and off
7-
* Activating scenes and scripts
7+
* Activating scenes, scripts, buttons and input_buttons
88
* input_select option menus
99
* Opening and Closing Covers
1010
* Viewing sensor values (Sensors have to be specifically added to a group)

0 commit comments

Comments
 (0)