1212
1313spaceapi = APIRouter ()
1414
15- # Homeassistant Sensors to export to the Space API
15+ # Home Assistant Sensors to export to the Space API
1616# entity_id, override_name
1717HOMEASSISTANT_SENSORS = (
1818 ("sensor.gw_dhcp_leases_online" , "WiFi Clients" ),
3232
3333
3434def get_state () -> dict :
35+ """
36+ Return the current open state of the Hackspace.
37+ """
3538 data = get_entity_state (settings .hackspace_open_entity )
3639 if data :
3740 return {
3841 "open" : data ["state" ] == "on" ,
3942 "lastchange" : int (arrow .get (data ["last_changed" ]).timestamp ()),
4043 }
4144
42- # We didn't get a valid response from Homeassistant , assume we're closed
45+ # We didn't get a valid response from Home Assistant , assume we're closed
4346 return {
4447 "open" : False ,
4548 }
4649
4750
4851@ttl_cache (ttl = 60 )
4952def get_sensors () -> dict :
53+ """
54+ Query Home Assistant and Prometheus to build the 'sensors' section of the
55+ SpaceAPI response.
56+ """
5057 results = {}
5158 for sensor , override_name in HOMEASSISTANT_SENSORS :
5259 data = get_entity_state (sensor )
@@ -202,6 +209,9 @@ def get_sensors() -> dict:
202209
203210
204211def get_links () -> list :
212+ """
213+ Return a list of links to add to the 'links' value of the SpaceAPI response.
214+ """
205215 return [
206216 {"name" : "Github" , "url" : "https://github.com/leigh-hackspace" },
207217 {
@@ -214,6 +224,9 @@ def get_links() -> list:
214224
215225
216226def get_membership_plans () -> list :
227+ """
228+ Format the website membership plan data into a SpaceAPI compatible format.
229+ """
217230 data = get_membership_data ()
218231 if not data :
219232 return []
0 commit comments