-
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
18 changed files
with
179 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dependencies { | ||
api(project(":commons")) | ||
} |
12 changes: 12 additions & 0 deletions
12
rears/src/main/scala/io/github/tassiLuca/rears/Controller.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
19 changes: 19 additions & 0 deletions
19
smart-hub/src/main/scala/io/github/tassiLuca/hub/application/LightingHubManager.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,19 @@ | ||
package io.github.tassiLuca.hub.application | ||
|
||
import scala.concurrent.duration.DurationInt | ||
import gears.async.{Async, AsyncOperations, ReadableChannel} | ||
import io.github.tassiLuca.hub.core.{LightingSystemComponent, LuminosityEntry} | ||
import io.github.tassiLuca.hub.core.ports.{DashboardServiceComponent, LampsComponent} | ||
import io.github.tassiLuca.rears.Controller | ||
import io.github.tassiLuca.rears.bufferWithin | ||
|
||
trait LightingHubManager extends LightingSystemComponent with LampsComponent with DashboardServiceComponent: | ||
override val lightingSystem: LightingSystem = LightingSystem() | ||
|
||
def run(source: ReadableChannel[LuminosityEntry])(using Async, AsyncOperations): Unit = | ||
lightingSystem.asRunnable.run | ||
Controller.oneToOne( | ||
publisherChannel = source, | ||
consumer = lightingSystem, | ||
transformation = r => r.bufferWithin(10.seconds), | ||
).run |
16 changes: 11 additions & 5 deletions
16
smart-hub/src/main/scala/io/github/tassiLuca/hub/application/ThermostatHubManager.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 |
---|---|---|
@@ -1,26 +1,32 @@ | ||
package io.github.tassiLuca.hub.application | ||
|
||
import gears.async.{Async, AsyncOperations, ReadableChannel} | ||
import io.github.tassiLuca.hub.core.{AlertSystemComponent, DashboardComponent, HeaterComponent, SensorHealthCheckerComponent, TemperatureEntry, ThermostatComponent, ThermostatScheduler} | ||
import io.github.tassiLuca.hub.core.ports.{AlertSystemComponent, DashboardServiceComponent, HeaterComponent} | ||
import io.github.tassiLuca.hub.core.{ | ||
SensorHealthCheckerComponent, | ||
TemperatureEntry, | ||
ThermostatComponent, | ||
ThermostatScheduler, | ||
} | ||
import io.github.tassiLuca.rears.{Controller, bufferWithin} | ||
|
||
import concurrent.duration.DurationInt | ||
import scala.language.postfixOps | ||
|
||
trait ThermostatHubManager | ||
extends ThermostatComponent | ||
with HeaterComponent | ||
with SensorHealthCheckerComponent[TemperatureEntry] | ||
with HeaterComponent | ||
with AlertSystemComponent | ||
with DashboardComponent: | ||
override val thermostat: Thermostat = Thermostat(ThermostatScheduler.byHour(19.0)) | ||
with DashboardServiceComponent: | ||
override val thermostat: Thermostat = ??? | ||
override val sensorHealthChecker: SensorHealthChecker = SensorHealthChecker() | ||
|
||
def run(source: ReadableChannel[TemperatureEntry])(using Async, AsyncOperations): Unit = | ||
thermostat.asRunnable.run | ||
sensorHealthChecker.asRunnable.run | ||
Controller.oneToMany( | ||
source, | ||
publisherChannel = source, | ||
consumers = Set(thermostat, sensorHealthChecker), | ||
transformation = r => r.bufferWithin(10.seconds), | ||
).run |
11 changes: 0 additions & 11 deletions
11
smart-hub/src/main/scala/io/github/tassiLuca/hub/core/DashboardComponent.scala
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
smart-hub/src/main/scala/io/github/tassiLuca/hub/core/LightingSystemComponent.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,24 @@ | ||
package io.github.tassiLuca.hub.core | ||
|
||
import gears.async.Async | ||
import io.github.tassiLuca.hub.core.ports.{DashboardServiceComponent, LampsComponent} | ||
import io.github.tassiLuca.rears.{Consumer, State} | ||
|
||
import scala.util.Try | ||
|
||
trait LightingSystemComponent: | ||
context: LampsComponent & DashboardServiceComponent => | ||
|
||
val lightingSystem: LightingSystem | ||
|
||
trait LightingSystem | ||
extends Consumer[Seq[LuminosityEntry], Seq[LuminosityEntry]] | ||
with State[Seq[LuminosityEntry], Seq[LuminosityEntry]] | ||
|
||
object LightingSystem: | ||
def apply(): LightingSystem = LightingSystemImpl() | ||
|
||
private class LightingSystemImpl extends LightingSystem: | ||
override protected def react(e: Try[Seq[LuminosityEntry]])(using Async): Seq[LuminosityEntry] = | ||
println(s"[LIGHTING SYSTEM] Received $e") | ||
e.getOrElse(Seq()) |
5 changes: 3 additions & 2 deletions
5
smart-hub/src/main/scala/io/github/tassiLuca/hub/core/SensorHealthCheckerComponent.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
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
4 changes: 3 additions & 1 deletion
4
...iLuca/hub/core/AlertSystemComponent.scala → ...hub/core/ports/AlertSystemComponent.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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
package io.github.tassiLuca.hub.core | ||
package io.github.tassiLuca.hub.core.ports | ||
|
||
import gears.async.Async | ||
|
||
/** The component encapsulating the alert system. */ | ||
trait AlertSystemComponent: | ||
|
||
/** The alert system instance. */ | ||
val alertSystem: AlertSystem | ||
|
||
/** The alert system port though which is possible to notify alerts. */ | ||
trait AlertSystem: | ||
/** Notify an alert with the given [[message]]. */ | ||
def notify(message: String)(using Async): Unit |
16 changes: 16 additions & 0 deletions
16
smart-hub/src/main/scala/io/github/tassiLuca/hub/core/ports/DashboardServiceComponent.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,16 @@ | ||
package io.github.tassiLuca.hub.core.ports | ||
|
||
import io.github.tassiLuca.hub.core.Temperature | ||
|
||
/** The component encapsulating the dashboard. */ | ||
trait DashboardServiceComponent: | ||
|
||
/** The [[DashboardService]] instance. */ | ||
val dashboard: DashboardService | ||
|
||
/** The dashboard boundary. */ | ||
trait DashboardService: | ||
def temperatureUpdated(newTemperature: Temperature): Unit | ||
def onHeaterNotified(): Unit | ||
def offHeaterNotified(): Unit | ||
def alertNotified(msg: String): Unit |
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
11 changes: 11 additions & 0 deletions
11
smart-hub/src/main/scala/io/github/tassiLuca/hub/core/ports/LampsComponent.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 io.github.tassiLuca.hub.core.ports | ||
|
||
import gears.async.Async | ||
|
||
trait LampsComponent: | ||
|
||
val lamps: Lamps | ||
|
||
trait Lamps: | ||
def on()(using Async): Unit | ||
def off()(using Async): Unit |
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: 9 additions & 0 deletions
9
...-hub/src/main/scala/io/github/tassiLuca/hub/infrastructure/MockedLightingHubManager.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,9 @@ | ||
package io.github.tassiLuca.hub.infrastructure | ||
|
||
import gears.async.Async | ||
import io.github.tassiLuca.hub.application.LightingHubManager | ||
|
||
trait MockedLightingHubManager extends LightingHubManager: | ||
override val lamps: Lamps = new Lamps: | ||
override def on()(using Async): Unit = println("[Lamp] Turning On...") | ||
override def off()(using Async): Unit = println("[Lamp] Turning off...") |
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
Oops, something went wrong.