Skip to content

Commit 063f7d9

Browse files
committed
Did some refactoring...
1 parent 5e13e1f commit 063f7d9

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

src/controller/controller.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from src import sparql
99
from src.failuredetection import PingFailureDetector
1010
from src.netscan import HostListScanner
11-
from src.semantics import InputTypeBuilder, UnknownSemanticsException
11+
from src.semantics import TDInputBuilder, UnknownSemanticsException
1212
from src.td import ThingDescription
1313

1414
# Configuration. Location of the different things:
@@ -31,29 +31,6 @@ class AlarmSystem(object):
3131

3232
last_auth_time = datetime.datetime(1970, 1, 1, 0, 0, 0)
3333

34-
def __build_alarm_action_params(self, action):
35-
"""
36-
Tries to determine the semantics of the input type of a alarm action.
37-
@type action TDAction
38-
@param action The alarm action to construct input data for.
39-
@rtype dict
40-
@return Input data for the given alarm action.
41-
"""
42-
it = action.input_type() # Get input type description
43-
ns_repo = action.get_td().namespace_repository()
44-
45-
if it['type'] == 'number':
46-
# Determine semantics for this boolean value:
47-
for key, value in it.items():
48-
if key != 'type' and sparql.classes_equivalent(ns_repo.resolve(key),
49-
'http://www.matthias-fisch.de/ontologies/wot#Duration'):
50-
# So this is the duration of the alarm...
51-
# Determine its unit:
52-
if sparql.classes_equivalent(ns_repo.resolve(value), 'http://dbpedia.org/resource/Second'):
53-
return self.alarm_duration_secs
54-
elif sparql.classes_equivalent(ns_repo.resolve(value), 'http://dbpedia.org/resource/Millisecond'):
55-
return self.alarm_duration_secs * 1000
56-
5734
def on_door_opened(self, is_opened):
5835
if is_opened: # If the door is opened and not closed
5936
# Calculate seconds since last authentication:
@@ -62,7 +39,7 @@ def on_door_opened(self, is_opened):
6239
if secs <= self.auth_ttl_secs: # Permission case
6340
welcome_action = self.alarm_source.get_action_by_types(['http://www.matthias-fisch.de/ontologies/wot#PlaybackAction'])
6441
if welcome_action:
65-
pb = InputTypeBuilder()
42+
pb = TDInputBuilder()
6643
pb.add_option_rule('http://www.matthias-fisch.de/ontologies/wot#SoundFile', 'http://www.matthias-fisch.de/ontologies/wot#WelcomeSound')
6744

6845
try:
@@ -78,7 +55,7 @@ def on_door_opened(self, is_opened):
7855
alarm_action = self.alarm_source.get_action_by_types(
7956
['http://www.matthias-fisch.de/ontologies/wot#AlarmAction'])
8057

81-
pb = InputTypeBuilder()
58+
pb = TDInputBuilder()
8259
pb.add_value_rule('http://www.matthias-fisch.de/ontologies/wot#Duration',
8360
'http://dbpedia.org/resource/Second', self.alarm_duration_secs)
8461
pb.add_value_rule('http://www.matthias-fisch.de/ontologies/wot#Duration',
@@ -95,6 +72,7 @@ def on_door_opened(self, is_opened):
9572

9673
def on_authentication(self, data):
9774
self.last_auth_time = datetime.datetime.strptime(data['time'], "%d-%m-%Y %H:%M:%S")
75+
print("Entry authenticated at %s for %d seconds..." % (self.last_auth_time.strftime("%d-%m-%Y %H:%M:%S"), self.auth_ttl_secs))
9876

9977

10078
def get_td(url):

0 commit comments

Comments
 (0)