mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Even more simplified API
This commit is contained in:
parent
7c17987585
commit
58c90402c5
30
README.md
30
README.md
@ -241,25 +241,37 @@ Returns message if API is up and running.
|
|||||||
Returns a dict with as keys the events and as value the number of listeners.
|
Returns a dict with as keys the events and as value the number of listeners.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
[
|
||||||
"state_changed": 5,
|
{
|
||||||
"time_changed": 2
|
"event": "state_changed",
|
||||||
}
|
"listener_count": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"event": "time_changed",
|
||||||
|
"listener_count": 2
|
||||||
|
}
|
||||||
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
**/api/services - GET**<br>
|
**/api/services - GET**<br>
|
||||||
Returns a dict with as keys the domain and as value a list of published services.
|
Returns a dict with as keys the domain and as value a list of published services.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
[
|
||||||
"browser": [
|
{
|
||||||
|
"domain": "browser",
|
||||||
|
"services": [
|
||||||
"browse_url"
|
"browse_url"
|
||||||
],
|
]
|
||||||
"keyboard": [
|
},
|
||||||
|
{
|
||||||
|
"domain": "keyboard",
|
||||||
|
"services": [
|
||||||
"volume_up",
|
"volume_up",
|
||||||
"volume_down"
|
"volume_down"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
**/api/states - GET**<br>
|
**/api/states - GET**<br>
|
||||||
|
@ -402,7 +402,10 @@ def is_state(api, entity_id, state, logger=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_services(api, logger=None):
|
def get_services(api, logger=None):
|
||||||
""" Returns a dict with per domain the available services at API. """
|
"""
|
||||||
|
Returns a list of dicts. Each dict has a string "domain" and
|
||||||
|
a list of strings "services".
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
req = api(METHOD_GET, URL_API_SERVICES)
|
req = api(METHOD_GET, URL_API_SERVICES)
|
||||||
|
|
||||||
|
@ -245,14 +245,25 @@ class TestHTTP(unittest.TestCase):
|
|||||||
req = requests.get(_url(remote.URL_API_EVENTS),
|
req = requests.get(_url(remote.URL_API_EVENTS),
|
||||||
headers=HA_HEADERS)
|
headers=HA_HEADERS)
|
||||||
|
|
||||||
self.assertEqual(req.json(), self.hass.bus.listeners)
|
local = self.hass.bus.listeners
|
||||||
|
|
||||||
|
for event in req.json():
|
||||||
|
self.assertEqual(event["listener_count"],
|
||||||
|
local.pop(event["event"]))
|
||||||
|
|
||||||
|
self.assertEqual(len(local), 0)
|
||||||
|
|
||||||
def test_api_get_services(self):
|
def test_api_get_services(self):
|
||||||
""" Test if we can get a dict describing current services. """
|
""" Test if we can get a dict describing current services. """
|
||||||
req = requests.get(_url(remote.URL_API_SERVICES),
|
req = requests.get(_url(remote.URL_API_SERVICES),
|
||||||
headers=HA_HEADERS)
|
headers=HA_HEADERS)
|
||||||
|
|
||||||
self.assertEqual(req.json(), self.hass.services.services)
|
local_services = self.hass.services.services
|
||||||
|
|
||||||
|
for serv_domain in req.json():
|
||||||
|
local = local_services.pop(serv_domain["domain"])
|
||||||
|
|
||||||
|
self.assertEqual(serv_domain["services"], local)
|
||||||
|
|
||||||
def test_api_call_service_no_data(self):
|
def test_api_call_service_no_data(self):
|
||||||
""" Test if the API allows us to call a service. """
|
""" Test if the API allows us to call a service. """
|
||||||
@ -310,9 +321,13 @@ class TestRemoteMethods(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_event_listeners(self):
|
def test_get_event_listeners(self):
|
||||||
""" Test Python API get_event_listeners. """
|
""" Test Python API get_event_listeners. """
|
||||||
|
local = self.hass.bus.listeners
|
||||||
|
|
||||||
self.assertEqual(
|
for event in remote.get_event_listeners(self.api):
|
||||||
remote.get_event_listeners(self.api), self.hass.bus.listeners)
|
self.assertEqual(event["listener_count"],
|
||||||
|
local.pop(event["event"]))
|
||||||
|
|
||||||
|
self.assertEqual(len(local), 0)
|
||||||
|
|
||||||
def test_fire_event(self):
|
def test_fire_event(self):
|
||||||
""" Test Python API fire_event. """
|
""" Test Python API fire_event. """
|
||||||
@ -360,8 +375,12 @@ class TestRemoteMethods(unittest.TestCase):
|
|||||||
def test_get_services(self):
|
def test_get_services(self):
|
||||||
""" Test Python API get_services. """
|
""" Test Python API get_services. """
|
||||||
|
|
||||||
self.assertEqual(
|
local_services = self.hass.services.services
|
||||||
remote.get_services(self.api), self.hass.services.services)
|
|
||||||
|
for serv_domain in remote.get_services(self.api):
|
||||||
|
local = local_services.pop(serv_domain["domain"])
|
||||||
|
|
||||||
|
self.assertEqual(serv_domain["services"], local)
|
||||||
|
|
||||||
def test_call_service(self):
|
def test_call_service(self):
|
||||||
""" Test Python API call_service. """
|
""" Test Python API call_service. """
|
||||||
@ -392,7 +411,9 @@ class TestRemoteClasses(unittest.TestCase):
|
|||||||
|
|
||||||
def test_statemachine_init(self):
|
def test_statemachine_init(self):
|
||||||
""" Tests if remote.StateMachine copies all states on init. """
|
""" Tests if remote.StateMachine copies all states on init. """
|
||||||
self.assertEqual(self.hass.states.all(), self.slave.states.all())
|
for state in self.hass.states.all():
|
||||||
|
self.assertEqual(
|
||||||
|
self.slave.states.get(state.entity_id), state)
|
||||||
|
|
||||||
def test_statemachine_set(self):
|
def test_statemachine_set(self):
|
||||||
""" Tests if setting the state on a slave is recorded. """
|
""" Tests if setting the state on a slave is recorded. """
|
||||||
|
Loading…
x
Reference in New Issue
Block a user