-
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
28 changed files
with
379 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ db { | |
password = "" | ||
} | ||
|
||
influx-db { | ||
influxdb { | ||
database = "ambient7" | ||
|
||
baseurl = "http://localhost:8086/" | ||
|
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
95 changes: 95 additions & 0 deletions
95
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,95 @@ | ||
package ru.maizy.ambient7.core.config.reader | ||
|
||
import ru.maizy.ambient7.core.config.{ Ambient7Options, Defaults, FromCliDevice } | ||
import ru.maizy.ambient7.core.data.{ AgentTags, DeviceType } | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2017 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
|
||
trait DevicesConfigReader extends UniversalConfigReader { | ||
|
||
import UniversalConfigReader._ | ||
|
||
private def cliDeviceOpts( | ||
opts: Ambient7Options, deviceType: DeviceType.Type)(save: FromCliDevice => FromCliDevice): Ambient7Options = { | ||
|
||
val currentOpts = opts.fromCliDevice.getOrElse(FromCliDevice(deviceType = Some(deviceType))) | ||
val res = opts.copy( | ||
fromCliDevice = Some(save(currentOpts)) | ||
) | ||
res | ||
} | ||
|
||
def fillDeviceFromCliOptions(deviceType: DeviceType.Type): Unit = { | ||
|
||
cliParser.opt[String]("agent-name") | ||
.valueName { Defaults.INFLUXDB_AGENT_NAME } | ||
.action { (value, opts) => cliDeviceOpts(opts, deviceType)(_.copy(agent = value)) } | ||
|
||
val saveTags = (value: String, opts: Ambient7Options) => | ||
cliDeviceOpts(opts, deviceType)(_.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") | ||
.validate(validateTags) | ||
.action(saveTags) | ||
.text { "Deprecated, use --agent-tags"} | ||
|
||
appendCheck { opts => | ||
if (opts.fromCliDevice.isDefined && opts.fromCliDevice.exists(_.deviceType.isEmpty)) { | ||
failure("device type is required") | ||
} else { | ||
success | ||
} | ||
} | ||
|
||
() | ||
} | ||
|
||
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) | ||
() | ||
} | ||
|
||
// FIXME: rewrite? | ||
def co2DeviceRequired(): Unit = { | ||
appendCheck { opts => | ||
val fromCliDefined = opts.fromCliDevice.isDefined | ||
val agentByIdDefined = opts.selectedDeviceId.isDefined && | ||
!opts.selectedDeviceId.contains(Ambient7Options.CO2_FROM_CLI_ID) | ||
if (fromCliDefined && agentByIdDefined) { | ||
failure("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?") | ||
failure(s"co2 device with id '$id' not found in config") | ||
} else { | ||
success | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.