Introduce the Models module in order to make others internal
This commit is contained in:
parent
915d01e086
commit
c377ec25dc
6 changed files with 31 additions and 26 deletions
|
|
@ -1,6 +1,6 @@
|
|||
module NightLight.Core
|
||||
|
||||
open System
|
||||
open NightLight.Models
|
||||
open NightLight.PartsOfDay
|
||||
open NightLight.ZigbeeEvents
|
||||
open NightLight.ZigbeeCommands
|
||||
|
|
@ -18,14 +18,6 @@ let internal generateZigbeeCommandToFixLight partOfDay light =
|
|||
|
||||
generateZigbeeCommand light.FriendlyName color brightness
|
||||
|
||||
type Event =
|
||||
| ReceivedZigbeeEvent of payload: string
|
||||
| TimeChanged of DateTime
|
||||
|
||||
type ParseEventError = ParseZigbeeEventError of ParseZigbeeEventError
|
||||
|
||||
type State = { Time: DateTime }
|
||||
|
||||
let onEventReceived (state: State) (event: Event) : Result<State * ZigbeeCommand seq, ParseEventError> =
|
||||
result {
|
||||
let partOfDay = getPartOfDay state.Time
|
||||
|
|
|
|||
22
NightLight.Core/Models.fs
Normal file
22
NightLight.Core/Models.fs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
module NightLight.Models
|
||||
|
||||
open System
|
||||
|
||||
type State = { Time: DateTime }
|
||||
|
||||
type Event =
|
||||
| ReceivedZigbeeEvent of payload: string
|
||||
| TimeChanged of DateTime
|
||||
|
||||
type ZigbeeCommand = ZigbeeCommand of Topic: string * Payload: string
|
||||
|
||||
type ParseZigbeeEventError =
|
||||
| InvalidJson
|
||||
| MissingTypeField
|
||||
| MissingDataField
|
||||
| MissingFriendlyNameField
|
||||
| InvalidTypeField
|
||||
| InvalidFriendlyNameField
|
||||
| UnknownType
|
||||
|
||||
type ParseEventError = ParseZigbeeEventError of ParseZigbeeEventError
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Models.fs" />
|
||||
<Compile Include="PartsOfDay.fs" />
|
||||
<Compile Include="Moods.fs" />
|
||||
<Compile Include="Lights.fs" />
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
module NightLight.ZigbeeCommands
|
||||
module internal NightLight.ZigbeeCommands
|
||||
|
||||
open System.Text.Json.Nodes
|
||||
open NightLight.Models
|
||||
open NightLight.Lights
|
||||
|
||||
type ZigbeeCommand = ZigbeeCommand of Topic: string * Payload: string
|
||||
|
||||
let internal generateZigbeeCommand friendlyName targetColor targetBrightness =
|
||||
let generateZigbeeCommand friendlyName targetColor targetBrightness =
|
||||
let commandObj = JsonObject()
|
||||
|
||||
match targetColor with
|
||||
|
|
|
|||
|
|
@ -1,20 +1,12 @@
|
|||
module NightLight.ZigbeeEvents
|
||||
module internal NightLight.ZigbeeEvents
|
||||
|
||||
open NightLight.Models
|
||||
open FsToolkit.ErrorHandling
|
||||
open FSharp.Data
|
||||
|
||||
type ZigbeeEvent = DeviceAnnounce of FriendlyName: string
|
||||
|
||||
type ParseZigbeeEventError =
|
||||
| InvalidJson
|
||||
| MissingTypeField
|
||||
| MissingDataField
|
||||
| MissingFriendlyNameField
|
||||
| InvalidTypeField
|
||||
| InvalidFriendlyNameField
|
||||
| UnknownType
|
||||
|
||||
let internal parseZigbeeEvent str =
|
||||
let parseZigbeeEvent str =
|
||||
result {
|
||||
let! jsonValue = JsonValue.TryParse str |> Result.requireSome InvalidJson
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue