-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zone.hs
36 lines (30 loc) · 954 Bytes
/
Zone.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module Zone
(
ZoneId
, Zone(zoneDefault)
, loadZones
, zoneTemperature
) where
import qualified Data.Map as Map
import Text.XML.Light (parseXML)
import Xml
import Thermometer
type ZoneId = String
data Zone = Zone
{ zoneOff :: Temperature
, zoneStandby :: Temperature
, zoneOn :: Temperature
, zoneDefault :: Temperature
} deriving (Show)
loadZones filename = do
str <- readFile filename
return $ foldr extract Map.empty (rootChildren $ parseXML str)
where extract e = Map.insert (attr "id" e) Zone
{ zoneOff = read $ attr "off" e
, zoneStandby = read $ attr "standby" e
, zoneOn = read $ attr "on" e
, zoneDefault = read $ attr "off" e -- TODO allow default value in zones.xml
}
zoneTemperature "off" = zoneOff
zoneTemperature "standby" = zoneStandby
zoneTemperature "on" = zoneOn