-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
169 additions
and
47 deletions.
There are no files selected for viewing
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
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
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
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
9 changes: 0 additions & 9 deletions
9
ambient7-webapp/src/main/scala/ru/maizy/ambient7/webapp/data/Co2Device.scala
This file was deleted.
Oops, something went wrong.
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
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
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
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
73 changes: 73 additions & 0 deletions
73
core/src/main/scala/ru/maizy/ambient7/core/config/reader/DevicesConfigReader.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package ru.maizy.ambient7.core.config.reader | ||
|
||
import ru.maizy.ambient7.core.config.{ Ambient7Options, Defaults, FromCliDevice, ParsingError } | ||
import ru.maizy.ambient7.core.data.AgentTags | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2017 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
|
||
trait DevicesConfigReader extends UniversalConfigReader { | ||
|
||
private def cliDeviceOpts(opts: Ambient7Options)(save: FromCliDevice => FromCliDevice): Ambient7Options = | ||
opts.copy(fromCliDevice = Some(save(opts.fromCliDevice.getOrElse(FromCliDevice())))) | ||
|
||
def fillDeviceFromCliOptions(): Unit = { | ||
|
||
cliParser.opt[String]("agent-name") | ||
.valueName { Defaults.INFLUXDB_AGENT_NAME } | ||
.action { (value, opts) => cliDeviceOpts(opts)(_.copy(agent = value)) } | ||
|
||
val saveTags = (value: String, opts: Ambient7Options) => cliDeviceOpts(opts)(_.copy(tags = AgentTags(value))) | ||
val validateTags = (value: String) => AgentTags.tryParseFromString(value) match { | ||
case Left(error) => cliParser.failure(error) | ||
case Right(_) => cliParser.success | ||
} | ||
|
||
cliParser.opt[String]("agent-tags") | ||
.valueName { "position=outdoor,altitude=200,some=val\\,ue" } | ||
.validate(validateTags) | ||
.action(saveTags) | ||
.text { "Any additional InfluxDB record tags"} | ||
|
||
// Deprecated | ||
cliParser.opt[String]("influxdb-tags") | ||
.action(saveTags) | ||
.validate(validateTags) | ||
.text { "Deprecated, use --agent-tags"} | ||
|
||
() | ||
} | ||
|
||
def fillDevicesOptions(): Unit = { | ||
// FIXME: implements | ||
|
||
() | ||
} | ||
|
||
def fillSelectedDeviceOptions(): Unit = { | ||
cliParser.opt[String]("device-id") | ||
.action { (value, opts) => opts.copy(selectedDeviceId = Some(value)) } | ||
.text { "Selected device" } | ||
|
||
// FIXME: implement device append (here or in case class) | ||
() | ||
} | ||
|
||
def co2DeviceRequired(): Unit = { | ||
appendCheck { opts => | ||
val fromCliDefined = opts.fromCliDevice.isDefined | ||
val agentByIdDefined = opts.selectedDeviceId.isDefined | ||
if (fromCliDefined && agentByIdDefined) { | ||
Left(ParsingError.withMessage("Either --agent-name or --device-id should be defined, but not both")) | ||
} else if (opts.selectedDeviceId.isDefined && opts.selectedCo2Device.isEmpty){ | ||
val id = opts.selectedDeviceId.getOrElse("wtf?") | ||
Left(ParsingError.withMessage(s"co2 device with id '$id' not found in config")) | ||
} else { | ||
Right(()) | ||
} | ||
} | ||
} | ||
} |
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
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
12 changes: 12 additions & 0 deletions
12
core/src/main/scala/ru/maizy/ambient7/core/data/Co2Device.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ru.maizy.ambient7.core.data | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2016-2017 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
case class Co2Device(id: String, agent: Co2Agent) extends Device { | ||
val deviceType = DeviceType.CO2 | ||
|
||
override def uid: String = s"co2__${id}__${agent.id}" | ||
} |
10 changes: 10 additions & 0 deletions
10
core/src/main/scala/ru/maizy/ambient7/core/data/Device.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ru.maizy.ambient7.core.data | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2017 | ||
* See LICENSE.txt for details. | ||
*/ | ||
trait Device { | ||
def deviceType: DeviceType.Type | ||
def uid: String | ||
} |
11 changes: 11 additions & 0 deletions
11
core/src/main/scala/ru/maizy/ambient7/core/data/DeviceType.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ru.maizy.ambient7.core.data | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2017 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
object DeviceType extends Enumeration { | ||
type Type = Value | ||
val CO2 = Value | ||
} |
10 changes: 10 additions & 0 deletions
10
core/src/main/scala/ru/maizy/ambient7/core/data/Devices.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ru.maizy.ambient7.core.data | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2017 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
case class Devices(co2Devices: List[Co2Device]) { | ||
def allDevices: List[Device] = co2Devices | ||
} |
13 changes: 0 additions & 13 deletions
13
core/src/main/scala/ru/maizy/ambient7/core/json/Co2AgentIdProtocol.scala
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
core/src/main/scala/ru/maizy/ambient7/core/json/Co2AgentProtocol.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ru.maizy.ambient7.core.json | ||
|
||
import ru.maizy.ambient7.core.data.Co2Agent | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2016-2017 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
trait Co2AgentProtocol extends BaseProtocol with AgentTagsProtocol { | ||
|
||
implicit val agentProtocol = jsonFormat(Co2Agent, "name", "tags") | ||
} |
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
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