Restructure and add HTTP API

- Move check_action and run_action into actions.py
- Add HTTP API
- Minor formatting changes
This commit is contained in:
Dessa Simpson 2022-05-28 06:08:22 +00:00
parent e58b1b21ed
commit 96a25cf79b
3 changed files with 75 additions and 58 deletions

15
http_api.py Normal file
View file

@ -0,0 +1,15 @@
#!/usr/bin/python3
import hassapi as hass
from actions import run_action
class HttpApi(hass.Hass):
def initialize(self):
self.register_endpoint(self.api_request, '4button')
def api_request(self, data, kwargs):
if 'sequence' not in data: return 'Missing sequence', 400
# Let AppDaemon handle API response on error
if (run_action(self,data['sequence'])):
return 'Success', 200
else:
return 'No match', 400