module NightLight.Core.Models open System open FSharp.Reflection 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 Light = | BathroomCeilingLamp | LivingRoomWallLamp | LivingRoomFloorLamp | RightBedroomLamp | LeftBedroomLamp type LightProps = { FriendlyName: DeviceFriendlyName Room: Room Bulb: Bulb } let lightProps light = match light with | BathroomCeilingLamp -> { FriendlyName = DeviceFriendlyName "Badrum - Taklampa" Room = Bathroom Bulb = IkeaBulb } | LivingRoomWallLamp -> { FriendlyName = DeviceFriendlyName "Vardagsrum - Vägglampa" Room = LivingRoom Bulb = PaulmannBulb } | LivingRoomFloorLamp -> { FriendlyName = DeviceFriendlyName "Vardagsrum - Golvlampa" Room = LivingRoom Bulb = PaulmannBulb } | RightBedroomLamp -> { FriendlyName = DeviceFriendlyName "Vardagsrum - Fönsterlampa" Room = Bedroom Bulb = IkeaBulb } | LeftBedroomLamp -> { FriendlyName = DeviceFriendlyName "Sovrum - Nattduksbordlampa" Room = Bedroom Bulb = IkeaBulb } let lights = FSharpType.GetUnionCases typeof |> Array.map (fun case -> FSharpValue.MakeUnion(case, [||]) :?> Light) |> Array.toList let remoteControlFriendlyName = DeviceFriendlyName "Fjärrkontroll" let livingRoomRemoteControlFriendlyName = DeviceFriendlyName "Living Room Remote" type internal State = | On | Off member this.Invert() = match this with | On -> Off | Off -> On 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 LightSettings = { State: State Brightness: Brightness Color: Color }