mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-15 16:41:00 -06:00
Fixes #1247. ## Summary Adds 3 sensors for displays: "Displays" (a count), "Primary Display Name" (the name of the display with the menu bar on it), and "Primary Display ID" (the ID of the primary). ## Link to pull request in Documentation repository Documentation: home-assistant/companion.home-assistant#421 ## Any other notes - `sensor.displays` - states like `0`, `1`, `2`, … - attributes of `"Display IDs": ["id1", "id2", …]` and `"Display Names": ["name1", "name2", …]` - `sensor.primary_display_name` - states like `"None"`, `"Built-in Retina Display"`, etc. - `sensor.primary_display_id` - states like `"BE82E2E6-EA40-4963-93AD-A0BDC9D2F18F"`, `"1AB60A12-6BB3-4503-96BD-F5B481F5830E"` etc.
23 lines
552 B
Swift
23 lines
552 B
Swift
import AppKit
|
|
|
|
class MacBridgeScreenImpl: NSObject, MacBridgeScreen {
|
|
let screen: NSScreen
|
|
|
|
init(screen: NSScreen) {
|
|
self.screen = screen
|
|
}
|
|
|
|
var identifier: String {
|
|
guard let displayID = screen.deviceDescription[.init("NSScreenNumber")] as? CGDirectDisplayID,
|
|
let uuid = CGDisplayCreateUUIDFromDisplayID(displayID)?.takeRetainedValue() else {
|
|
return "(error)"
|
|
}
|
|
|
|
return CFUUIDCreateString(nil, uuid) as String
|
|
}
|
|
|
|
var name: String {
|
|
screen.localizedName
|
|
}
|
|
}
|