Skip to content

Commit 54b5b97

Browse files
authored
Merge pull request #20 from Windham-High-School/123-complete-api
123 complete api
2 parents ece4c2a + 6ef366b commit 54b5b97

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

servercom/implementations/circuitpy.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ def basic_auth_str(user: str, pwd: str) -> str:
3030

3131
DataClass = enum(
3232
TEMPERATURE = "temperature",
33-
HUMIDITY = "humidity",
3433
PRESSURE = "pressure",
35-
LIGHT_INTENSITY = "light intensity",
3634
COMMENT = "comment",
37-
BATTERY = "remaining battery"
35+
BATTERY = "remaining battery",
36+
BEACON = "beacon challenge"
3837
)
3938

4039
class DataPoint():
@@ -69,30 +68,24 @@ class Temperature(DataPoint):
6968
def __init__(self, value):
7069
super().__init__(DataClass.TEMPERATURE, value)
7170

72-
class Humidity(DataPoint):
73-
"""A class for DataPoints that store humidity values"""
74-
UNIT = "%"
75-
def __init__(self, value):
76-
super().__init__(DataClass.HUMIDITY, value)
77-
7871
class Pressure(DataPoint):
7972
"""A class for DataPoints that store barometric pressure values"""
8073
UNIT="inHg"
8174
def __init__(self, value):
8275
super().__init__(DataClass.PRESSURE, value)
8376

84-
class Intensity(DataPoint):
85-
"""A class for DataPoints that store light intensity values"""
86-
UNIT="lux"
87-
def __init__(self, value):
88-
super().__init__(DataClass.LIGHT_INTENSITY, value)
89-
9077
class Text(DataPoint):
9178
"""A class reserved for DataPoints that are intended as a text comment"""
9279
UNIT="" # No unit for regular strings of text
9380
def __init__(self, value: str):
9481
super().__init__(DataClass.COMMENT, value)
9582

83+
class BeaconChallenge(DataPoint):
84+
"""A class reserved for DataPoints that are in response to a message from the beacon"""
85+
UNIT="" # No unit for regular strings of text
86+
def __init__(self, value: str):
87+
super().__init__(DataClass.BEACON, value)
88+
9689
class BatteryLevel(DataPoint):
9790
"""A class reserved for DataPoints that are intended as an indication of battery level"""
9891
UNIT="%" # No unit for regular strings of text
@@ -399,7 +392,7 @@ def get_status(self) -> GameStatus:
399392
resp_json = loads(resp[1])
400393
if self.v:
401394
print(f"It is {resp_json['unix_time']} seconds since the epoch.")
402-
return GameStatus(Time(resp_json['unix_time']), resp_json['status']['score'])
395+
return GameStatus(Time(resp_json['unix_time']), resp_json['status']['score'], resp_json['CubeServer_version'])
403396

404397
def sync_time(self) -> bool:
405398
"""Syncs the current clock against the server"""

servercom/implementations/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
GameStatus = namedtuple("GameStatus",
1717
['time',
18-
'score']
18+
'score',
19+
'CubeServer_version']
1920
)
2021

2122
HTTPResponse = namedtuple("HTTPResponse",

servercom/implementations/cpy.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
# Helpers:
1919
class DataClass(str, Enum):
2020
TEMPERATURE = "temperature"
21-
HUMIDITY = "humidity"
2221
PRESSURE = "pressure"
23-
LIGHT_INTENSITY = "light intensity"
2422
COMMENT = "comment"
2523
BATTERY = "remaining battery"
24+
BEACON = "beacon challenge"
2625

2726
class DataPoint():
2827
"""A class for storing and handling datapoints"""
@@ -56,30 +55,24 @@ class Temperature(DataPoint):
5655
def __init__(self, value):
5756
super().__init__(DataClass.TEMPERATURE, value)
5857

59-
class Humidity(DataPoint):
60-
"""A class for DataPoints that store humidity values"""
61-
UNIT = "%"
62-
def __init__(self, value):
63-
super().__init__(DataClass.HUMIDITY, value)
64-
6558
class Pressure(DataPoint):
6659
"""A class for DataPoints that store barometric pressure values"""
6760
UNIT="inHg"
6861
def __init__(self, value):
6962
super().__init__(DataClass.PRESSURE, value)
7063

71-
class Intensity(DataPoint):
72-
"""A class for DataPoints that store light intensity values"""
73-
UNIT="lux"
74-
def __init__(self, value):
75-
super().__init__(DataClass.LIGHT_INTENSITY, value)
76-
7764
class Text(DataPoint):
7865
"""A class reserved for DataPoints that are intended as a text comment"""
7966
UNIT="" # No unit for regular strings of text
8067
def __init__(self, value: str):
8168
super().__init__(DataClass.COMMENT, value)
8269

70+
class BeaconChallenge(DataPoint):
71+
"""A class reserved for DataPoints that are in response to a message from the beacon"""
72+
UNIT="" # No unit for regular strings of text
73+
def __init__(self, value: str):
74+
super().__init__(DataClass.BEACON, value)
75+
8376
class BatteryLevel(DataPoint):
8477
"""A class reserved for DataPoints that are intended as an indication of battery level"""
8578
UNIT="%" # No unit for regular strings of text
@@ -344,7 +337,7 @@ def get_status(self) -> GameStatus:
344337
"""
345338
resp = self.request('GET', '/status')
346339
resp_json = loads(resp[1])
347-
return GameStatus(Time(resp_json['unix_time']), resp_json['status']['score'])
340+
return GameStatus(Time(resp_json['unix_time']), resp_json['status']['score'], resp_json['CubeServer_version'])
348341

349342
def sync_time(self) -> bool:
350343
"""Syncs the current clock against the server"""

0 commit comments

Comments
 (0)