Created
March 6, 2018 17:36
-
-
Save FruitieX/9897c87089e44c3e6c4e094bf09c3a51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newtype Light = Light | |
{ color :: LightColor | |
, prevColor :: LightColor | |
--, transitionStart :: Instant | |
, transitionStart :: Milliseconds | |
, transitionTime :: Milliseconds | |
} | |
type Lights = Map LightId Light | |
type StupidIntermediateThingy = | |
{ color :: LightColor | |
, prevColor :: LightColor | |
, transitionStart :: Number | |
, transitionTime :: Number | |
} | |
type StupidIntermediateStrMapThingy = StrMap StupidIntermediateThingy | |
-- WTF instant creates a Maybe Instant | |
-- (so i replaced Instant with Milliseconds so i dont need to deal with this) | |
toLight :: StupidIntermediateStrMapThingy -> Lights | |
toLight = | |
foldlWithIndex (\k m v -> do | |
let transitionStart = Milliseconds v.transitionStart | |
let transitionTime = Milliseconds v.transitionTime | |
insert (LightId k) (Light v { transitionStart = transitionStart, transitionTime = transitionTime }) m | |
) empty | |
registerLuminaireHandler :: forall e. Luminaires -> Handler (ref :: REF | e) | |
registerLuminaireHandler state = do | |
idParam <- getRouteParam "id" | |
gatewayParam :: Maybe String <- getBodyParam "gateway" | |
body :: Maybe String <- hush <$> runExcept <<< readString <$> getBody' | |
-- lmao | |
let (json' :: Maybe (Either MultipleErrors StupidIntermediateStrMapThingy)) = readJSON <$> body | |
let (json :: Maybe StupidIntermediateStrMapThingy) = hush =<< json' | |
let asd = toLight <$> json | |
pure unit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment