Skip to content

Commit

Permalink
Introduced a PotAppDevice class to encapsulate process logic for devices
Browse files Browse the repository at this point in the history
Merge pull request #43 from pharo-iot/dev
Introduced a PotAppDevice class to encapsulate process logic for devices
  • Loading branch information
oliveiraallex committed Apr 28, 2020
2 parents 391adf7 + a958dd5 commit 40b4596
Show file tree
Hide file tree
Showing 42 changed files with 147 additions and 24 deletions.
5 changes: 5 additions & 0 deletions src/PharoThings-Apps-Tests.package/.filetree
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"separateMethodMetaAndSource" : false,
"noMethodMetaData" : true,
"useCypressPropertiesFile" : true
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
log
^ log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
loopBody
log := 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
process
^process
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"commentStamp" : "",
"super" : "PotAppDevice",
"category" : "PharoThings-Apps-Tests",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"log"
],
"name" : "PotAppDeviceMock",
"type" : "normal"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
running
setUp
"Hooks that subclasses may override to define the fixture of test."
super setUp.
appDevice := PotAppDeviceMock new.
appDevice deviceName: 'testAppDevice'.
appDevice delay: 500 milliSeconds
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
running
tearDown
appDevice disconnect.
super tearDown
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tests
testBody
appDevice connect.
appDevice delay wait.
self assert: appDevice log notNil
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tests
testConnection
appDevice connect.
self assert: appDevice process name equals: (appDevice printString, ': ', appDevice deviceName).
self assert: appDevice process priority equals: Processor userBackgroundPriority.
self assert: appDevice isConnected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tests
testDelay
self assert: appDevice delay equals: 500 milliSeconds
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tests
testDeviceName
self assert: appDevice deviceName equals: 'testAppDevice'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tests
testDisconnection
appDevice connect.
self assert: appDevice isConnected.
appDevice disconnect.
self deny: appDevice isConnected
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"commentStamp" : "",
"super" : "TestCase",
"category" : "PharoThings-Apps-Tests",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"appDevice"
],
"name" : "PotAppDeviceTests",
"type" : "normal"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SystemOrganization addCategory: #'PharoThings-Apps-Tests'!
Empty file.
1 change: 1 addition & 0 deletions src/PharoThings-Apps-Tests.package/monticello.meta/package
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(name 'PharoThings-Apps-Tests')
1 change: 1 addition & 0 deletions src/PharoThings-Apps-Tests.package/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ }
5 changes: 5 additions & 0 deletions src/PharoThings-Apps.package/.filetree
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"separateMethodMetaAndSource" : false,
"noMethodMetaData" : true,
"useCypressPropertiesFile" : true
}
4 changes: 4 additions & 0 deletions src/PharoThings-Apps.package/PotAppDevice.class/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
I am a specialized device with a process and connect/disconnect logic for writing devices that need to regularly update.
I am an abstract class.
You have to subclass me and implement:
- loopBody: the method that is called by my process
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
controlling
connect
process := [ [ true ]
whileTrue: [ self loopBody.
delay wait ] ]
forkAt: Processor userBackgroundPriority
named: self printString , ': ' , self deviceName
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
delay: anObject
delay := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
delay
^ delay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
deviceName: aString
deviceName := aString
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
accessing
deviceName
^ deviceName
ifNil: [ deviceName := 'anonymous device('
, Time now asNanoSeconds printString , ')' ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
controlling
disconnect
self isConnected
ifFalse: [ ^ self ].
process terminate
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
controlling
isConnected
^ process notNil and: [ process isTerminated not ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
controlling
loopBody
self subclassResponsibility
15 changes: 15 additions & 0 deletions src/PharoThings-Apps.package/PotAppDevice.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"commentStamp" : "StevenCostiou 12/3/2019 15:26",
"super" : "PotDevice",
"category" : "PharoThings-Apps",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"process",
"delay",
"deviceName"
],
"name" : "PotAppDevice",
"type" : "normal"
}
1 change: 1 addition & 0 deletions src/PharoThings-Apps.package/monticello.meta/categories.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SystemOrganization addCategory: #'PharoThings-Apps'!
Empty file.
1 change: 1 addition & 0 deletions src/PharoThings-Apps.package/monticello.meta/package
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(name 'PharoThings-Apps')
1 change: 1 addition & 0 deletions src/PharoThings-Apps.package/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ }
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ Internal Representation and Key Implementation Points.

Instance Variables
alarmPin: <PotBoardPin>
waterSensor: <PotDevice>
trackingProcess: <Process>
waterSensor: <PotDevice>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
controlling
initialize
super initialize.
deviceName := 'water tracking'

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
controlling
loopBody
self checkWater

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"commentStamp" : "DenisKudryashov 2/16/2018 18:53",
"super" : "PotDevice",
"commentStamp" : "StevenCostiou 12/3/2019 16:09",
"super" : "PotAppDevice",
"category" : "PharoThings-Devices-WaterAlarm",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"waterSensor",
"alarmPin",
"trackingProcess"
"alarmPin"
],
"name" : "PotWaterAlarm",
"type" : "normal"
Expand Down

0 comments on commit 40b4596

Please sign in to comment.