Skip to content

Instantly share code, notes, and snippets.

@vikingosegundo
Created December 6, 2021 22:55
Show Gist options
  • Save vikingosegundo/9511db87d8a12cd6c65a5a829d77e7b4 to your computer and use it in GitHub Desktop.
Save vikingosegundo/9511db87d8a12cd6c65a5a829d77e7b4 to your computer and use it in GitHub Desktop.
// MARK: - Executable Documentation
#if targetEnvironment(simulator)
enum LightingFeature {
static func Documentation () -> [(Message._Lighting,Message._Lighting,Message._Lighting)]{
let l = Light(id: "1", name: "1")
let r = Room(id: "a", title: "a")
let e = LightError.unknown
let docs: [(Message._Lighting,Message._Lighting,Message._Lighting)] =
// These are examples for every lighting command and their possible responses. These colums do show all commands the Lighting Module
// will understand and that are constructable. So to speak: it is the complete vocabulary.
// The first column contains commands that the user triggers directly or indirectly.
// The second column shows responses for the success case and
// the third column shows reponses for the failure case.
[ //|---------------- Command --------------| |----------------- Response Success ----------------| |---------------- Response Failure -----------------|
(.load (.lights), .loading (.lights([l]), .succeeded), .loading (.lights([]), .failed(e))),
(.load (.rooms ), .loading (.rooms ([r]), .succeeded), .loading (.rooms ([]), .failed(e))),
(.turn (l,.on ), .turning (l,.on, .succeeded), .turning (l,.on, .failed(e))),
(.turn (l,.off ), .turning (l,.off, .succeeded), .turning (l,.off, .failed(e))),
(.apply(.values(.ct ( 200, 0.5)),on:l), .applying(.values(.ct ( 200, 0.5)),on:l,.succeeded), .applying(.values(.ct ( 200, 0.5)),on:l,.failed(e))),
(.apply(.values(.hsb(0.5,0.5,0.5)),on:l), .applying(.values(.hsb(0.5,0.5,0.5)),on:l,.succeeded), .applying(.values(.hsb(0.5,0.5,0.5)),on:l,.failed(e))),
(.apply(.values(.bri( 0.5)),on:l), .applying(.values(.bri( 0.5)),on:l,.succeeded), .applying(.values(.bri( 0.5)),on:l,.failed(e))),
(.increase(.colortemp, by:10.pt, on:l), .increasing(.colortemp, by:10.pt, on:l,.succeeded), .increasing(.colortemp, by:10.pt, on:l,.failed(e))),
(.increase(.hue, by:10.pt, on:l), .increasing(.hue, by:10.pt, on:l,.succeeded), .increasing(.hue, by:10.pt, on:l,.failed(e))),
(.increase(.saturation,by:10.pt, on:l), .increasing(.saturation,by:10.pt, on:l,.succeeded), .increasing(.saturation,by:10.pt, on:l,.failed(e))),
(.increase(.brightness,by:10.pt, on:l), .increasing(.brightness,by:10.pt, on:l,.succeeded), .increasing(.brightness,by:10.pt, on:l,.failed(e))),
(.decrease(.colortemp, by:10.pt, on:l), .decreasing(.colortemp, by:10.pt, on:l,.succeeded), .decreasing(.colortemp, by:10.pt, on:l,.failed(e))),
(.decrease(.hue, by:10.pt, on:l), .decreasing(.hue, by:10.pt, on:l,.succeeded), .decreasing(.hue, by:10.pt, on:l,.failed(e))),
(.decrease(.saturation,by:10.pt, on:l), .decreasing(.saturation,by:10.pt, on:l,.succeeded), .decreasing(.saturation,by:10.pt, on:l,.failed(e))),
(.decrease(.brightness,by:10.pt, on:l), .decreasing(.brightness,by:10.pt, on:l,.succeeded), .decreasing(.brightness,by:10.pt, on:l,.failed(e))),
(.change (.name("1a"), on:l), .changing (.name("1a"), on:l,.succeeded), .changing (.name("1a"), on:l,.failed(e))),
(.change (.display(.slider), on:l), .changing (.display(.slider), on:l,.succeeded), .changing (.display(.slider), on:l,.failed(e))),
(.change (.display(.scrubbing), on:l), .changing (.display(.scrubbing), on:l,.succeeded), .changing (.display(.scrubbing), on:l,.failed(e))),
]
// SwiftUI Example:
// let roothandler: (Message) -> () = { _ in }
// _ = Button { roothandler( .lighting(.decrease(.hue,by:10.pt,on:l)) ) } label: { Image(systemName:"paintpalette") }
return docs
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment