module NightLight.Core.Models open System type Message = { Topic: string; Payload: string } type Event = | ReceivedZigbeeEvent of Message | TimeChanged of DateTime type ParseZigbeeEventError = | UnknownTopic of string | InvalidJson | MissingTypeField | MissingDataField | MissingFriendlyNameField | InvalidTypeField | InvalidFriendlyNameField | UnknownType | MissingActionField | InvalidActionField type OnEventReceivedError = | ParseZigbeeEventError of ParseZigbeeEventError | TimeIsUnknown type Room = | Bathroom | LivingRoom | Bedroom type Bulb = | IkeaBulb | PaulmannBulb type DeviceFriendlyName = | DeviceFriendlyName of string member this.Get = match this with | DeviceFriendlyName deviceFriendlyName -> deviceFriendlyName type LightControl = | NonRemote | RemoteLeft | RemoteRight type Light = | VardagsrumFonsterlampa | VardagsrumVagglampa | VardagsrumGolvlampa | BadrumTaklampa | SovrumNattduksbordlampa type LightProps = { FriendlyName: DeviceFriendlyName Room: Room Bulb: Bulb ControlledWithRemote: LightControl } let lightProps light = match light with | VardagsrumFonsterlampa -> { FriendlyName = DeviceFriendlyName "Vardagsrum - Fönsterlampa" Room = Bedroom Bulb = IkeaBulb ControlledWithRemote = RemoteRight } | VardagsrumVagglampa -> { FriendlyName = DeviceFriendlyName "Vardagsrum - Vägglampa" Room = LivingRoom Bulb = PaulmannBulb ControlledWithRemote = NonRemote } | VardagsrumGolvlampa -> { FriendlyName = DeviceFriendlyName "Vardagsrum - Golvlampa" Room = LivingRoom Bulb = PaulmannBulb ControlledWithRemote = NonRemote } | BadrumTaklampa -> { FriendlyName = DeviceFriendlyName "Badrum - Taklampa" Room = Bathroom Bulb = IkeaBulb ControlledWithRemote = NonRemote } | SovrumNattduksbordlampa -> { FriendlyName = DeviceFriendlyName "Sovrum - Nattduksbordlampa" Room = Bedroom Bulb = IkeaBulb ControlledWithRemote = RemoteLeft } let lights = [ VardagsrumFonsterlampa VardagsrumVagglampa VardagsrumGolvlampa BadrumTaklampa SovrumNattduksbordlampa ] let remoteControlFriendlyName = DeviceFriendlyName "Fjärrkontroll" type internal State = | On | Off type internal Brightness = | Brightness of int member this.Scale(b: float) = match this with | Brightness brightness -> Brightness <| int (float brightness * b) type internal Color = | ColorByCoordinates of float * float | ColorByTemperature of int type internal LightState = { State: State Brightness: Brightness Color: Color }