From f71517856df381039fb145b798be160c5553f927 Mon Sep 17 00:00:00 2001 From: Artem Date: Wed, 5 Feb 2020 19:13:35 +0300 Subject: [PATCH] 2020-02-05 Version 1.1.0: Added Debug Monitor implementation for tests and run the app without Arduino --- app/build.gradle | 2 +- .../remotetemperaturecontrol/MainActivity.kt | 6 +- .../components/fragments/BaseFragment.kt | 8 +- .../deviceselector/BtDevicesBottomSheet.kt | 4 +- .../deviceselector/recycler/BtDeviceHolder.kt | 2 +- .../recycler/BtDevicesAdapter.kt | 2 +- ...orHandleFragment.kt => MonitorFragment.kt} | 59 +++++++++----- .../logic/monitor/api/BtConnection.kt | 21 +++++ .../monitor/{Monitor.kt => api/BtMonitor.kt} | 6 +- .../BtMonitorSignalType.kt} | 10 +-- .../BtMonitorTarget.kt} | 4 +- .../connection => api}/entities/BtDevice.kt | 2 +- .../entities}/targets/BtConnectTarget.kt | 2 +- .../entities}/targets/BtDisconnectTarget.kt | 2 +- .../entities}/targets/BtPauseTarget.kt | 2 +- .../monitor/impl/debugbt/DebugBtConnection.kt | 80 +++++++++++++++++++ .../monitor/impl/debugbt/DebugBtMonitor.kt | 53 ++++++++++++ .../devicebt/DeviceBtConnection.kt} | 35 ++++---- .../devicebt/DeviceBtDataExtractor.kt} | 12 +-- .../devicebt/DeviceBtMonitor.kt} | 46 +++++------ .../logic/settings/SettingsBottomSheet.kt | 2 +- .../main/res/layout-v23/item_bt_device.xml | 18 ----- .../remotetemperaturecontrol/TestSuite.kt | 8 +- .../MonitorDataExtractorTest.kt} | 32 ++++---- .../MonitorDataSendTest.kt} | 28 +++---- .../api/fakemonitor/FakeMonitor.kt | 39 +++++++++ .../fakemonitor/FakeMonitorHandleTarget.kt | 7 +- .../handle/fakemonitor/FakeMonitor.kt | 39 --------- 28 files changed, 342 insertions(+), 189 deletions(-) rename app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/{ui/MonitorHandleFragment.kt => MonitorFragment.kt} (77%) create mode 100644 app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/BtConnection.kt rename app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/{Monitor.kt => api/BtMonitor.kt} (61%) rename app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/{MonitorSignalType.kt => api/BtMonitorSignalType.kt} (80%) rename app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/{MonitorHandleTarget.kt => api/BtMonitorTarget.kt} (90%) rename app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/{btmonitor/connection => api}/entities/BtDevice.kt (83%) rename app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/{btmonitor/connection => api/entities}/targets/BtConnectTarget.kt (82%) rename app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/{btmonitor/connection => api/entities}/targets/BtDisconnectTarget.kt (78%) rename app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/{btmonitor/connection => api/entities}/targets/BtPauseTarget.kt (78%) create mode 100644 app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/debugbt/DebugBtConnection.kt create mode 100644 app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/debugbt/DebugBtMonitor.kt rename app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/{btmonitor/connection/MonitorBtConnection.kt => impl/devicebt/DeviceBtConnection.kt} (69%) rename app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/{btmonitor/connection/MonitorDataExtractor.kt => impl/devicebt/DeviceBtDataExtractor.kt} (58%) rename app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/{btmonitor/BtMonitor.kt => impl/devicebt/DeviceBtMonitor.kt} (55%) delete mode 100644 app/src/main/res/layout-v23/item_bt_device.xml rename app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/{handle/FakeMonitorDataExtractorTest.kt => api/MonitorDataExtractorTest.kt} (51%) rename app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/{handle/FakeMonitorDataSendTest.kt => api/MonitorDataSendTest.kt} (62%) create mode 100644 app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/api/fakemonitor/FakeMonitor.kt rename app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/{handle => api}/fakemonitor/FakeMonitorHandleTarget.kt (82%) delete mode 100644 app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/handle/fakemonitor/FakeMonitor.kt diff --git a/app/build.gradle b/app/build.gradle index 8c1d788..80d1253 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,7 +12,7 @@ android { minSdkVersion 21 targetSdkVersion 29 versionCode 1 - versionName "1.0.1" + versionName "1.1.0" } } diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/MainActivity.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/MainActivity.kt index d652f34..d2a6e20 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/MainActivity.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/MainActivity.kt @@ -3,14 +3,14 @@ package com.smlnskgmail.jaman.remotetemperaturecontrol import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.targets.BtPauseTarget -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.ui.MonitorHandleFragment +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.MonitorFragment +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.entities.targets.BtPauseTarget class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - showFragment(MonitorHandleFragment()) + showFragment(MonitorFragment()) } private fun showFragment(fragment: Fragment) { diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/components/fragments/BaseFragment.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/components/fragments/BaseFragment.kt index e4cc164..8491b43 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/components/fragments/BaseFragment.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/components/fragments/BaseFragment.kt @@ -6,16 +6,10 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import com.smlnskgmail.jaman.remotetemperaturecontrol.components.bottomsheets.BaseBottomSheet -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.targets.BtPauseTarget +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.entities.targets.BtPauseTarget abstract class BaseFragment : Fragment(), BtPauseTarget { - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - initializeFragment(view) - } - - abstract fun initializeFragment(view: View) - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/deviceselector/BtDevicesBottomSheet.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/deviceselector/BtDevicesBottomSheet.kt index 41dbfa2..4ae4bc8 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/deviceselector/BtDevicesBottomSheet.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/deviceselector/BtDevicesBottomSheet.kt @@ -3,8 +3,8 @@ package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.deviceselector import com.smlnskgmail.jaman.remotetemperaturecontrol.R import com.smlnskgmail.jaman.remotetemperaturecontrol.components.bottomsheets.BaseBottomSheet import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.deviceselector.recycler.BtDevicesAdapter -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.entities.BtDevice -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.targets.BtConnectTarget +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.entities.BtDevice +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.entities.targets.BtConnectTarget import kotlinx.android.synthetic.main.bottom_sheet_bt_devices.* class BtDevicesBottomSheet : BaseBottomSheet() { diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/deviceselector/recycler/BtDeviceHolder.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/deviceselector/recycler/BtDeviceHolder.kt index 03ca337..8a05e98 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/deviceselector/recycler/BtDeviceHolder.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/deviceselector/recycler/BtDeviceHolder.kt @@ -2,7 +2,7 @@ package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.deviceselector.recy import android.view.View import androidx.recyclerview.widget.RecyclerView -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.entities.BtDevice +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.entities.BtDevice import kotlinx.android.synthetic.main.item_bt_device.view.* class BtDeviceHolder( diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/deviceselector/recycler/BtDevicesAdapter.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/deviceselector/recycler/BtDevicesAdapter.kt index cbdccd3..2078023 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/deviceselector/recycler/BtDevicesAdapter.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/deviceselector/recycler/BtDevicesAdapter.kt @@ -4,7 +4,7 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.smlnskgmail.jaman.remotetemperaturecontrol.R -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.entities.BtDevice +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.entities.BtDevice class BtDevicesAdapter( private val btDevices: List diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/ui/MonitorHandleFragment.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/MonitorFragment.kt similarity index 77% rename from app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/ui/MonitorHandleFragment.kt rename to app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/MonitorFragment.kt index e276909..9aed384 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/ui/MonitorHandleFragment.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/MonitorFragment.kt @@ -1,41 +1,43 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.ui +package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor +import android.annotation.SuppressLint import android.bluetooth.BluetoothAdapter import android.content.DialogInterface +import android.os.Bundle import android.view.View import android.widget.TextView import com.smlnskgmail.jaman.remotetemperaturecontrol.R import com.smlnskgmail.jaman.remotetemperaturecontrol.components.dialogs.AppDialog import com.smlnskgmail.jaman.remotetemperaturecontrol.components.fragments.BaseFragment import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.deviceselector.BtDevicesBottomSheet -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.MonitorHandleTarget -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.MonitorSignalType -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.BtMonitor -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.MonitorBtConnection -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.entities.BtDevice -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.targets.BtConnectTarget -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.targets.BtDisconnectTarget +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtConnection +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitor +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitorSignalType +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitorTarget +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.entities.BtDevice +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.entities.targets.BtConnectTarget +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.entities.targets.BtDisconnectTarget +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.impl.debugbt.DebugBtConnection +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.impl.debugbt.DebugBtMonitor +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.impl.devicebt.DeviceBtConnection +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.impl.devicebt.DeviceBtMonitor import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.settings.SettingsBottomSheet import kotlinx.android.synthetic.main.fragment_monitor.* @SuppressWarnings("TooManyFunctions") -class MonitorHandleFragment : BaseFragment(), MonitorHandleTarget { +class MonitorFragment : BaseFragment(), BtMonitorTarget { - private var monitorBtConnection: MonitorBtConnection? = null + private var monitorBtConnection: BtConnection? = null private var btAdapter: BluetoothAdapter? = null private var btMonitor: BtMonitor? = null - override fun initializeFragment(view: View) { - enableMonitor() - } - - private fun enableMonitor() { + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { if (btIsEnabled()) { btAdapter = BluetoothAdapter.getDefaultAdapter() val btDevices = getBtDevices() if (btDevices.isNotEmpty()) { - btMonitor = BtMonitor(this) + btMonitor = DeviceBtMonitor(this) showDevicesList(btDevices) } else { showBtDevicesNotFoundWarning() @@ -45,6 +47,18 @@ class MonitorHandleFragment : BaseFragment(), MonitorHandleTarget { } } + @SuppressLint("SetTextI18n") + @Suppress("unused") + private fun startInDebugMode() { + btMonitor = DebugBtMonitor(this) + monitorBtConnection = DebugBtConnection(btMonitor!!) + monitorBtConnection!!.start() + + tv_connected_device_info.text = "DEBUG" + btn_main_options.isEnabled = false + btn_reset_monitor.isEnabled = false + } + private fun btIsEnabled() = true private fun showDevicesList(btDevices: List) { @@ -52,7 +66,7 @@ class MonitorHandleFragment : BaseFragment(), MonitorHandleTarget { devicesBottomSheet.setBtDevices(btDevices) devicesBottomSheet.setBtDeviceSelectCallback(object : BtConnectTarget { override fun onBtDeviceSelected(name: String, address: String) { - monitorBtConnection = MonitorBtConnection( + monitorBtConnection = DeviceBtConnection( btAdapter!!, address, btMonitor!! @@ -70,7 +84,10 @@ class MonitorHandleFragment : BaseFragment(), MonitorHandleTarget { private fun getBtDevices(): List { val bondedDevices= btAdapter!!.bondedDevices return bondedDevices.mapTo(ArrayList(bondedDevices.size)) { - BtDevice(it.name, it.address) + BtDevice( + it.name, + it.address + ) } } @@ -151,7 +168,7 @@ class MonitorHandleFragment : BaseFragment(), MonitorHandleTarget { private fun initializeButtons() { btn_reset_monitor.setOnClickListener { - monitorBtConnection!!.send(MonitorSignalType.Reset) + monitorBtConnection!!.send(BtMonitorSignalType.Reset) } btn_main_options.setOnClickListener { showSettings() @@ -159,13 +176,11 @@ class MonitorHandleFragment : BaseFragment(), MonitorHandleTarget { } private fun showSettings() { - val settingsBottomSheet = - SettingsBottomSheet() + val settingsBottomSheet = SettingsBottomSheet() settingsBottomSheet.setBtDisconnectListener(object : BtDisconnectTarget { override fun btDisconnect() { monitorBtConnection!!.disconnect() resetRequired() - enableMonitor() } }) showBottomSheet(settingsBottomSheet) diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/BtConnection.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/BtConnection.kt new file mode 100644 index 0000000..c14bd49 --- /dev/null +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/BtConnection.kt @@ -0,0 +1,21 @@ +package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api + +abstract class BtConnection : Thread() { + + open fun connect() { + + } + + open fun disconnect() { + + } + + open fun handleOnResume() { + + } + + open fun send(btMonitorSignalType: BtMonitorSignalType) { + + } + +} diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/Monitor.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/BtMonitor.kt similarity index 61% rename from app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/Monitor.kt rename to app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/BtMonitor.kt index bbf4ab6..1f2fc5a 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/Monitor.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/BtMonitor.kt @@ -1,9 +1,9 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor +package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api -interface Monitor { +interface BtMonitor { fun onNewDataAvailable( - monitorSignalType: MonitorSignalType, + btMonitorSignalType: BtMonitorSignalType, rawData: String ) diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/MonitorSignalType.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/BtMonitorSignalType.kt similarity index 80% rename from app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/MonitorSignalType.kt rename to app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/BtMonitorSignalType.kt index 0879c4b..f924715 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/MonitorSignalType.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/BtMonitorSignalType.kt @@ -1,6 +1,6 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor +package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api -enum class MonitorSignalType { +enum class BtMonitorSignalType { Temperature, TemperatureMinimum, @@ -13,7 +13,7 @@ enum class MonitorSignalType { companion object { - fun fromRawData(rawData: String): MonitorSignalType { + fun fromRawData(rawData: String): BtMonitorSignalType { return when (rawData[0].toString()) { "t" -> Temperature "i" -> TemperatureMinimum @@ -26,8 +26,8 @@ enum class MonitorSignalType { } } - fun signalOf(monitorSignalType: MonitorSignalType): String { - return when (monitorSignalType) { + fun signalOf(btMonitorSignalType: BtMonitorSignalType): String { + return when (btMonitorSignalType) { Temperature -> "t" TemperatureMinimum -> "i" TemperatureMaximum -> "m" diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/MonitorHandleTarget.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/BtMonitorTarget.kt similarity index 90% rename from app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/MonitorHandleTarget.kt rename to app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/BtMonitorTarget.kt index 566a3ca..ba0ef1d 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/MonitorHandleTarget.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/BtMonitorTarget.kt @@ -1,6 +1,6 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor +package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api -interface MonitorHandleTarget { +interface BtMonitorTarget { fun temperatureAvailable(data: String) fun temperatureMaximumAvailable(data: String) diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/entities/BtDevice.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/entities/BtDevice.kt similarity index 83% rename from app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/entities/BtDevice.kt rename to app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/entities/BtDevice.kt index 1397450..095c607 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/entities/BtDevice.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/entities/BtDevice.kt @@ -1,4 +1,4 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.entities +package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.entities data class BtDevice( val name: String, diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/targets/BtConnectTarget.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/entities/targets/BtConnectTarget.kt similarity index 82% rename from app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/targets/BtConnectTarget.kt rename to app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/entities/targets/BtConnectTarget.kt index 66e843d..dcf9b41 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/targets/BtConnectTarget.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/entities/targets/BtConnectTarget.kt @@ -1,4 +1,4 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.targets +package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.entities.targets interface BtConnectTarget { diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/targets/BtDisconnectTarget.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/entities/targets/BtDisconnectTarget.kt similarity index 78% rename from app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/targets/BtDisconnectTarget.kt rename to app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/entities/targets/BtDisconnectTarget.kt index 17d940f..992d0b4 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/targets/BtDisconnectTarget.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/entities/targets/BtDisconnectTarget.kt @@ -1,4 +1,4 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.targets +package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.entities.targets interface BtDisconnectTarget { diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/targets/BtPauseTarget.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/entities/targets/BtPauseTarget.kt similarity index 78% rename from app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/targets/BtPauseTarget.kt rename to app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/entities/targets/BtPauseTarget.kt index c0da2e7..437f7dd 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/targets/BtPauseTarget.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/api/entities/targets/BtPauseTarget.kt @@ -1,4 +1,4 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.targets +package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.entities.targets interface BtPauseTarget { diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/debugbt/DebugBtConnection.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/debugbt/DebugBtConnection.kt new file mode 100644 index 0000000..931a90d --- /dev/null +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/debugbt/DebugBtConnection.kt @@ -0,0 +1,80 @@ +package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.impl.debugbt + +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtConnection +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitor +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitorSignalType + +class DebugBtConnection( + private val btMonitor: BtMonitor +) : BtConnection() { + + companion object { + + private val temperature = arrayListOf( + "25.3 C", + "24.6 C", + "23.5 C", + "21.2 C", + "22.4 C", + "23.3 C", + "24.7 C", + "25.1 C", + "25.6 C", + "25.7 C" + ) + + private val humidity = arrayListOf( + "78.1 %", + "79.4 %", + "77.3 %", + "77.7 %", + "77.8 %", + "78.4 %", + "79.5 %", + "81.6 %", + "79.4 %", + "77.5 %" + ) + + } + + private var loopCounter = 0 + + override fun run() { + super.run() + while (true) { + @Suppress("MagicNumber") + sleep(5_000) + btMonitor.onNewDataAvailable( + BtMonitorSignalType.Temperature, + temperature[loopCounter] + ) + btMonitor.onNewDataAvailable( + BtMonitorSignalType.TemperatureMaximum, + "25.7 C" + ) + btMonitor.onNewDataAvailable( + BtMonitorSignalType.TemperatureMinimum, + "21.2 C" + ) + btMonitor.onNewDataAvailable( + BtMonitorSignalType.Humidity, + humidity[loopCounter] + ) + btMonitor.onNewDataAvailable( + BtMonitorSignalType.HumidityMaximum, + "81.6 %" + ) + btMonitor.onNewDataAvailable( + BtMonitorSignalType.HumidityMinimum, + "77.3 %" + ) + if (loopCounter < temperature.size - 1) { + loopCounter++ + } else { + loopCounter = 0 + } + } + } + +} diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/debugbt/DebugBtMonitor.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/debugbt/DebugBtMonitor.kt new file mode 100644 index 0000000..1b42c80 --- /dev/null +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/debugbt/DebugBtMonitor.kt @@ -0,0 +1,53 @@ +package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.impl.debugbt + +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitor +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitorSignalType +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitorTarget + +class DebugBtMonitor( + private val btMonitorTarget: BtMonitorTarget +) : BtMonitor { + + override fun onNewDataAvailable( + btMonitorSignalType: BtMonitorSignalType, + rawData: String + ) { + @Suppress("UseCheckOrError") + when (btMonitorSignalType) { + BtMonitorSignalType.Temperature -> { + btMonitorTarget.temperatureAvailable( + rawData + ) + } + BtMonitorSignalType.TemperatureMaximum -> { + btMonitorTarget.temperatureMaximumAvailable( + rawData + ) + } + BtMonitorSignalType.TemperatureMinimum -> { + btMonitorTarget.temperatureMinimumAvailable( + rawData + ) + } + BtMonitorSignalType.Humidity -> { + btMonitorTarget.humidityAvailable( + rawData + ) + } + BtMonitorSignalType.HumidityMaximum -> { + btMonitorTarget.humidityMaximumAvailable( + rawData + ) + } + BtMonitorSignalType.HumidityMinimum -> { + btMonitorTarget.humidityMinimumAvailable( + rawData + ) + } + else -> throw IllegalStateException( + "DebugMonitor cannot support $btMonitorSignalType!" + ) + } + } + +} diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/MonitorBtConnection.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/devicebt/DeviceBtConnection.kt similarity index 69% rename from app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/MonitorBtConnection.kt rename to app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/devicebt/DeviceBtConnection.kt index 7ccfc20..35648e0 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/MonitorBtConnection.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/devicebt/DeviceBtConnection.kt @@ -1,18 +1,19 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection +package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.impl.devicebt import android.bluetooth.BluetoothAdapter import android.bluetooth.BluetoothSocket -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.Monitor -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.MonitorSignalType +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtConnection +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitor +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitorSignalType import java.io.InputStream import java.io.OutputStream import java.util.* -class MonitorBtConnection( +class DeviceBtConnection( btAdapter: BluetoothAdapter, deviceMacAddress: String, - private val monitor: Monitor -) : Thread() { + private val btMonitor: BtMonitor +) : BtConnection() { private val btUuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB") @@ -38,19 +39,25 @@ class MonitorBtConnection( private fun read() { if (inputStreamIsOpen()) { val rawData = inputStream!!.bufferedReader().readLine() - val signalType = MonitorDataExtractor.signalType(rawData) - val data = MonitorDataExtractor.data(rawData) - monitor.onNewDataAvailable(signalType, data) + val signalType = + DeviceBtDataExtractor.signalType( + rawData + ) + val data = + DeviceBtDataExtractor.data( + rawData + ) + btMonitor.onNewDataAvailable(signalType, data) } } private fun inputStreamIsOpen() = inputStream!!.bufferedReader().ready() - fun send(monitorSignalType: MonitorSignalType) { - outputStream!!.write(MonitorSignalType.signalOf(monitorSignalType).toByteArray()) + override fun send(btMonitorSignalType: BtMonitorSignalType) { + outputStream!!.write(BtMonitorSignalType.signalOf(btMonitorSignalType).toByteArray()) } - fun connect() { + override fun connect() { if (!btSocket!!.isConnected) { btSocket!!.connect() inputStream = btSocket!!.inputStream @@ -58,7 +65,7 @@ class MonitorBtConnection( } } - fun disconnect() { + override fun disconnect() { if (btSocket!!.isConnected) { isRunning = false btSocket!!.close() @@ -71,7 +78,7 @@ class MonitorBtConnection( } } - fun handleOnResume() { + override fun handleOnResume() { if (outputStream != null) { outputStream!!.flush() } diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/MonitorDataExtractor.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/devicebt/DeviceBtDataExtractor.kt similarity index 58% rename from app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/MonitorDataExtractor.kt rename to app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/devicebt/DeviceBtDataExtractor.kt index abe287f..21912f6 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/connection/MonitorDataExtractor.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/devicebt/DeviceBtDataExtractor.kt @@ -1,14 +1,14 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection +package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.impl.devicebt -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.MonitorSignalType +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitorSignalType -object MonitorDataExtractor { +object DeviceBtDataExtractor { - fun signalType(rawData: String): MonitorSignalType { + fun signalType(rawData: String): BtMonitorSignalType { if (rawData.isNotEmpty()) { - return MonitorSignalType.fromRawData(rawData) + return BtMonitorSignalType.fromRawData(rawData) } - return MonitorSignalType.Other + return BtMonitorSignalType.Other } fun data(rawData: String): String { diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/BtMonitor.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/devicebt/DeviceBtMonitor.kt similarity index 55% rename from app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/BtMonitor.kt rename to app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/devicebt/DeviceBtMonitor.kt index cb23f18..3fc921e 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/btmonitor/BtMonitor.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/impl/devicebt/DeviceBtMonitor.kt @@ -1,52 +1,52 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor +package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.impl.devicebt import android.annotation.SuppressLint -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.Monitor -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.MonitorHandleTarget -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.MonitorSignalType +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitor +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitorSignalType +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitorTarget -class BtMonitor( - private val monitorHandleTarget: MonitorHandleTarget -) : Monitor { +class DeviceBtMonitor( + private val btMonitorTarget: BtMonitorTarget +) : BtMonitor { @Suppress("NON_EXHAUSTIVE_WHEN") override fun onNewDataAvailable( - monitorSignalType: MonitorSignalType, + btMonitorSignalType: BtMonitorSignalType, rawData: String ) { - when(monitorSignalType) { - MonitorSignalType.Temperature -> { - monitorHandleTarget.temperatureAvailable( + when(btMonitorSignalType) { + BtMonitorSignalType.Temperature -> { + btMonitorTarget.temperatureAvailable( temperatureResult(rawData) ) } - MonitorSignalType.TemperatureMaximum -> { - monitorHandleTarget.temperatureMaximumAvailable( + BtMonitorSignalType.TemperatureMaximum -> { + btMonitorTarget.temperatureMaximumAvailable( temperatureResult(rawData) ) } - MonitorSignalType.TemperatureMinimum -> { - monitorHandleTarget.temperatureMinimumAvailable( + BtMonitorSignalType.TemperatureMinimum -> { + btMonitorTarget.temperatureMinimumAvailable( temperatureResult(rawData) ) } - MonitorSignalType.Humidity -> { - monitorHandleTarget.humidityAvailable( + BtMonitorSignalType.Humidity -> { + btMonitorTarget.humidityAvailable( humidityResult(rawData) ) } - MonitorSignalType.HumidityMaximum -> { - monitorHandleTarget.humidityMaximumAvailable( + BtMonitorSignalType.HumidityMaximum -> { + btMonitorTarget.humidityMaximumAvailable( humidityResult(rawData) ) } - MonitorSignalType.HumidityMinimum -> { - monitorHandleTarget.humidityMinimumAvailable( + BtMonitorSignalType.HumidityMinimum -> { + btMonitorTarget.humidityMinimumAvailable( humidityResult(rawData) ) } - MonitorSignalType.Reset -> { - monitorHandleTarget.resetRequired() + BtMonitorSignalType.Reset -> { + btMonitorTarget.resetRequired() } } } diff --git a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/settings/SettingsBottomSheet.kt b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/settings/SettingsBottomSheet.kt index ac42189..3678430 100644 --- a/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/settings/SettingsBottomSheet.kt +++ b/app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/settings/SettingsBottomSheet.kt @@ -2,7 +2,7 @@ package com.smlnskgmail.jaman.remotetemperaturecontrol.logic.settings import com.smlnskgmail.jaman.remotetemperaturecontrol.R import com.smlnskgmail.jaman.remotetemperaturecontrol.components.bottomsheets.BaseBottomSheet -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.targets.BtDisconnectTarget +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.entities.targets.BtDisconnectTarget import kotlinx.android.synthetic.main.bottom_sheet_settings.* class SettingsBottomSheet : BaseBottomSheet() { diff --git a/app/src/main/res/layout-v23/item_bt_device.xml b/app/src/main/res/layout-v23/item_bt_device.xml deleted file mode 100644 index ff8a171..0000000 --- a/app/src/main/res/layout-v23/item_bt_device.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - diff --git a/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/TestSuite.kt b/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/TestSuite.kt index c6ad396..d0862b8 100644 --- a/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/TestSuite.kt +++ b/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/TestSuite.kt @@ -1,13 +1,13 @@ package com.smlnskgmail.jaman.remotetemperaturecontrol -import com.smlnskgmail.jaman.remotetemperaturecontrol.handle.FakeMonitorDataExtractorTest -import com.smlnskgmail.jaman.remotetemperaturecontrol.handle.FakeMonitorDataSendTest +import com.smlnskgmail.jaman.remotetemperaturecontrol.api.MonitorDataExtractorTest +import com.smlnskgmail.jaman.remotetemperaturecontrol.api.MonitorDataSendTest import org.junit.runner.RunWith import org.junit.runners.Suite @RunWith(Suite::class) @Suite.SuiteClasses( - FakeMonitorDataExtractorTest::class, - FakeMonitorDataSendTest::class + MonitorDataExtractorTest::class, + MonitorDataSendTest::class ) class TestSuite diff --git a/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/handle/FakeMonitorDataExtractorTest.kt b/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/api/MonitorDataExtractorTest.kt similarity index 51% rename from app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/handle/FakeMonitorDataExtractorTest.kt rename to app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/api/MonitorDataExtractorTest.kt index eac7ce0..0384604 100644 --- a/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/handle/FakeMonitorDataExtractorTest.kt +++ b/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/api/MonitorDataExtractorTest.kt @@ -1,57 +1,57 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.handle +package com.smlnskgmail.jaman.remotetemperaturecontrol.api -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.MonitorSignalType -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.btmonitor.connection.MonitorDataExtractor +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitorSignalType +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.impl.devicebt.DeviceBtDataExtractor import org.junit.Assert.assertEquals import org.junit.Test -class FakeMonitorDataExtractorTest { +class MonitorDataExtractorTest { @Test fun validateTemperatureParse() { - checkValidation(MonitorSignalType.Temperature) + checkValidation(BtMonitorSignalType.Temperature) } @Test fun validateTemperatureMinimumParse() { - checkValidation(MonitorSignalType.TemperatureMinimum) + checkValidation(BtMonitorSignalType.TemperatureMinimum) } @Test fun validateTemperatureMaximumParse() { - checkValidation(MonitorSignalType.TemperatureMaximum) + checkValidation(BtMonitorSignalType.TemperatureMaximum) } @Test fun validateHumidityParse() { - checkValidation(MonitorSignalType.Humidity) + checkValidation(BtMonitorSignalType.Humidity) } @Test fun validateHumidityMinimumParse() { - checkValidation(MonitorSignalType.HumidityMinimum) + checkValidation(BtMonitorSignalType.HumidityMinimum) } @Test fun validateHumidityMaximumParse() { - checkValidation(MonitorSignalType.HumidityMaximum) + checkValidation(BtMonitorSignalType.HumidityMaximum) } @Test fun validateResetRequired() { - checkValidation(MonitorSignalType.Reset, "") + checkValidation(BtMonitorSignalType.Reset, "") } private fun checkValidation( - monitorSignalType: MonitorSignalType, + btMonitorSignalType: BtMonitorSignalType, cleanResult: String = DEFAULT_CLEAN_RESULT ) { - val rawData = rawData(MonitorSignalType.signalOf(monitorSignalType), cleanResult) + val rawData = rawData(BtMonitorSignalType.signalOf(btMonitorSignalType), cleanResult) - val parsedSignalType = MonitorDataExtractor.signalType(rawData) - assertEquals(parsedSignalType, monitorSignalType) + val parsedSignalType = DeviceBtDataExtractor.signalType(rawData) + assertEquals(parsedSignalType, btMonitorSignalType) - val parsedData = MonitorDataExtractor.data(rawData) + val parsedData = DeviceBtDataExtractor.data(rawData) assertEquals(parsedData, cleanResult) } diff --git a/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/handle/FakeMonitorDataSendTest.kt b/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/api/MonitorDataSendTest.kt similarity index 62% rename from app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/handle/FakeMonitorDataSendTest.kt rename to app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/api/MonitorDataSendTest.kt index b452a6b..ea80590 100644 --- a/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/handle/FakeMonitorDataSendTest.kt +++ b/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/api/MonitorDataSendTest.kt @@ -1,15 +1,15 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.handle +package com.smlnskgmail.jaman.remotetemperaturecontrol.api -import com.smlnskgmail.jaman.remotetemperaturecontrol.handle.fakemonitor.FakeMonitor -import com.smlnskgmail.jaman.remotetemperaturecontrol.handle.fakemonitor.FakeMonitorHandleTarget -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.MonitorSignalType +import com.smlnskgmail.jaman.remotetemperaturecontrol.api.fakemonitor.FakeMonitor +import com.smlnskgmail.jaman.remotetemperaturecontrol.api.fakemonitor.FakeMonitorHandleTarget +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitorSignalType import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Test import java.io.ByteArrayOutputStream import java.io.PrintStream -class FakeMonitorDataSendTest { +class MonitorDataSendTest { private val monitorTarget = FakeMonitorHandleTarget() @@ -29,7 +29,7 @@ class FakeMonitorDataSendTest { fun validateTemperatureSend() { val validResult = "34.5" - sendNewData(MonitorSignalType.Temperature, validResult) + sendNewData(BtMonitorSignalType.Temperature, validResult) checkOutput(validResult) } @@ -37,7 +37,7 @@ class FakeMonitorDataSendTest { fun validateTemperatureMinimumSend() { val validResult = "29.1" - sendNewData(MonitorSignalType.TemperatureMinimum, validResult) + sendNewData(BtMonitorSignalType.TemperatureMinimum, validResult) checkOutput(validResult) } @@ -45,7 +45,7 @@ class FakeMonitorDataSendTest { fun validateTemperatureMaximumSend() { val validResult = "35.9" - sendNewData(MonitorSignalType.TemperatureMaximum, validResult) + sendNewData(BtMonitorSignalType.TemperatureMaximum, validResult) checkOutput(validResult) } @@ -53,7 +53,7 @@ class FakeMonitorDataSendTest { fun validateHumiditySend() { val validResult = "74.2" - sendNewData(MonitorSignalType.Humidity, validResult) + sendNewData(BtMonitorSignalType.Humidity, validResult) checkOutput(validResult) } @@ -61,7 +61,7 @@ class FakeMonitorDataSendTest { fun validateHumidityMinimumSend() { val validResult = "54.6" - sendNewData(MonitorSignalType.HumidityMinimum, validResult) + sendNewData(BtMonitorSignalType.HumidityMinimum, validResult) checkOutput(validResult) } @@ -69,7 +69,7 @@ class FakeMonitorDataSendTest { fun validateHumidityMaximumSend() { val validResult = "89.3" - sendNewData(MonitorSignalType.HumidityMaximum, validResult) + sendNewData(BtMonitorSignalType.HumidityMaximum, validResult) checkOutput(validResult) } @@ -77,12 +77,12 @@ class FakeMonitorDataSendTest { fun validateResetRequiredSend() { val validResult = "" - sendNewData(MonitorSignalType.Reset, validResult) + sendNewData(BtMonitorSignalType.Reset, validResult) checkOutput(validResult) } - private fun sendNewData(monitorSignalType: MonitorSignalType, data: String) { - signalTarget.onNewDataAvailable(monitorSignalType, data) + private fun sendNewData(btMonitorSignalType: BtMonitorSignalType, data: String) { + signalTarget.onNewDataAvailable(btMonitorSignalType, data) } private fun checkOutput(validOutput: String) { diff --git a/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/api/fakemonitor/FakeMonitor.kt b/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/api/fakemonitor/FakeMonitor.kt new file mode 100644 index 0000000..ae05778 --- /dev/null +++ b/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/api/fakemonitor/FakeMonitor.kt @@ -0,0 +1,39 @@ +package com.smlnskgmail.jaman.remotetemperaturecontrol.api.fakemonitor + +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitor +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitorSignalType +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitorTarget + +class FakeMonitor(private val btMonitorTarget: BtMonitorTarget) : + BtMonitor { + + override fun onNewDataAvailable( + btMonitorSignalType: BtMonitorSignalType, + rawData: String + ) { + when (btMonitorSignalType) { + BtMonitorSignalType.Temperature -> { + btMonitorTarget.temperatureAvailable(rawData) + } + BtMonitorSignalType.TemperatureMinimum -> { + btMonitorTarget.temperatureMinimumAvailable(rawData) + } + BtMonitorSignalType.TemperatureMaximum -> { + btMonitorTarget.temperatureMaximumAvailable(rawData) + } + BtMonitorSignalType.Humidity -> { + btMonitorTarget.humidityAvailable(rawData) + } + BtMonitorSignalType.HumidityMinimum -> { + btMonitorTarget.humidityMinimumAvailable(rawData) + } + BtMonitorSignalType.HumidityMaximum -> { + btMonitorTarget.humidityMaximumAvailable(rawData) + } + BtMonitorSignalType.Reset -> { + btMonitorTarget.resetRequired() + } + } + } + +} diff --git a/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/handle/fakemonitor/FakeMonitorHandleTarget.kt b/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/api/fakemonitor/FakeMonitorHandleTarget.kt similarity index 82% rename from app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/handle/fakemonitor/FakeMonitorHandleTarget.kt rename to app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/api/fakemonitor/FakeMonitorHandleTarget.kt index 412d3da..eb45840 100644 --- a/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/handle/fakemonitor/FakeMonitorHandleTarget.kt +++ b/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/api/fakemonitor/FakeMonitorHandleTarget.kt @@ -1,8 +1,9 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.handle.fakemonitor +package com.smlnskgmail.jaman.remotetemperaturecontrol.api.fakemonitor -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.MonitorHandleTarget +import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.api.BtMonitorTarget -class FakeMonitorHandleTarget : MonitorHandleTarget { +class FakeMonitorHandleTarget : + BtMonitorTarget { override fun temperatureAvailable(data: String) { printText(data) diff --git a/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/handle/fakemonitor/FakeMonitor.kt b/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/handle/fakemonitor/FakeMonitor.kt deleted file mode 100644 index 53067e0..0000000 --- a/app/src/test/java/com/smlnskgmail/jaman/remotetemperaturecontrol/handle/fakemonitor/FakeMonitor.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.smlnskgmail.jaman.remotetemperaturecontrol.handle.fakemonitor - -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.Monitor -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.MonitorHandleTarget -import com.smlnskgmail.jaman.remotetemperaturecontrol.logic.monitor.MonitorSignalType - -class FakeMonitor(private val monitorHandleTarget: MonitorHandleTarget) : - Monitor { - - override fun onNewDataAvailable( - monitorSignalType: MonitorSignalType, - rawData: String - ) { - when (monitorSignalType) { - MonitorSignalType.Temperature -> { - monitorHandleTarget.temperatureAvailable(rawData) - } - MonitorSignalType.TemperatureMinimum -> { - monitorHandleTarget.temperatureMinimumAvailable(rawData) - } - MonitorSignalType.TemperatureMaximum -> { - monitorHandleTarget.temperatureMaximumAvailable(rawData) - } - MonitorSignalType.Humidity -> { - monitorHandleTarget.humidityAvailable(rawData) - } - MonitorSignalType.HumidityMinimum -> { - monitorHandleTarget.humidityMinimumAvailable(rawData) - } - MonitorSignalType.HumidityMaximum -> { - monitorHandleTarget.humidityMaximumAvailable(rawData) - } - MonitorSignalType.Reset -> { - monitorHandleTarget.resetRequired() - } - } - } - -}