104 lines
2.5 KiB
FSharp
104 lines
2.5 KiB
FSharp
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<Light>
|
|
|> Array.map (fun case -> FSharpValue.MakeUnion(case, [||]) :?> Light)
|
|
|> Array.toList
|
|
|
|
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 }
|