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 Light = | RightBedroomLamp | LivingRoomWallLamp | LivingRoomFloorLamp | BathroomCeilingLamp | LeftBedroomLamp type LightProps = { FriendlyName: DeviceFriendlyName Room: Room Bulb: Bulb } let lightProps light = match light with | RightBedroomLamp -> { FriendlyName = DeviceFriendlyName "Vardagsrum - Fönsterlampa" Room = Bedroom Bulb = IkeaBulb } | LivingRoomWallLamp -> { FriendlyName = DeviceFriendlyName "Vardagsrum - Vägglampa" Room = LivingRoom Bulb = PaulmannBulb } | LivingRoomFloorLamp -> { FriendlyName = DeviceFriendlyName "Vardagsrum - Golvlampa" Room = LivingRoom Bulb = PaulmannBulb } | BathroomCeilingLamp -> { FriendlyName = DeviceFriendlyName "Badrum - Taklampa" Room = Bathroom Bulb = IkeaBulb } | LeftBedroomLamp -> { FriendlyName = DeviceFriendlyName "Sovrum - Nattduksbordlampa" Room = Bedroom Bulb = IkeaBulb } let lights = [ RightBedroomLamp LivingRoomWallLamp LivingRoomFloorLamp BathroomCeilingLamp LeftBedroomLamp ] 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 }