Merge remote-tracking branch 'origin/master' into next
Conflicts: source/_posts/2016-07-16-sqlalchemy-knx-join-simplisafe.markdown
This commit is contained in:
commit
fb2ea42c88
39 changed files with 736 additions and 49 deletions
|
@ -39,7 +39,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Initialize Awesome Light platform."""
|
||||
"""Setup the Awesome Light platform."""
|
||||
import awesomelights
|
||||
|
||||
# Validate passed in config
|
||||
|
@ -63,8 +63,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
# Add devices
|
||||
add_devices(AwesomeLight(light) for light in hub.lights())
|
||||
|
||||
|
||||
class AwesomeLight(Light):
|
||||
"""Represents an AwesomeLight in Home Assistant."""
|
||||
"""Representation of an Awesome Light."""
|
||||
|
||||
def __init__(self, light):
|
||||
"""Initialize an AwesomeLight."""
|
||||
|
@ -72,7 +73,7 @@ class AwesomeLight(Light):
|
|||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the display name of this light"""
|
||||
"""Return the display name of this light."""
|
||||
return self._light.name
|
||||
|
||||
@property
|
||||
|
@ -86,7 +87,7 @@ class AwesomeLight(Light):
|
|||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""If light is on."""
|
||||
"""Return true if light is on."""
|
||||
return self._light.is_on()
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
|
@ -105,7 +106,7 @@ class AwesomeLight(Light):
|
|||
def update(self):
|
||||
"""Fetch new state data for this light.
|
||||
|
||||
This is the only method that should fetch new data for Home Assitant.
|
||||
This is the only method that should fetch new data for Home Assistant.
|
||||
"""
|
||||
self._light.update()
|
||||
```
|
||||
|
|
|
@ -31,19 +31,25 @@ from homeassistant.helpers.entity import Entity
|
|||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the sensor platform."""
|
||||
add_devices([ExampleSensor()])
|
||||
|
||||
|
||||
class ExampleSensor(Entity):
|
||||
"""Representation of a Sensor."""
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return 'Example Temperature'
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor.""
|
||||
return 23
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return TEMP_CELSIUS
|
||||
```
|
||||
|
|
|
@ -52,19 +52,19 @@ Similar to the output in the "Developer Tools" of the frontend.
|
|||
```python
|
||||
import homeassistant.remote as remote
|
||||
|
||||
api = remote.API('127.1.0.1', 'password')
|
||||
api = remote.API('127.1.0.1', 'YOUR_PASSWORD')
|
||||
|
||||
print('-- Available services:')
|
||||
services = remote.get_services(api)
|
||||
for service in services:
|
||||
print(service['services'])
|
||||
|
||||
print('\n-- Available event')
|
||||
print('\n-- Available events:')
|
||||
events = remote.get_event_listeners(api)
|
||||
for event in events:
|
||||
print(event)
|
||||
|
||||
print('\n-- Available entities')
|
||||
print('\n-- Available entities:')
|
||||
entities = remote.get_states(api)
|
||||
for entity in entities:
|
||||
print(entity)
|
||||
|
@ -77,7 +77,7 @@ To get the details of a single entity the `get_state` method is used.
|
|||
```python
|
||||
import homeassistant.remote as remote
|
||||
|
||||
api = remote.API('127.1.0.1', 'password')
|
||||
api = remote.API('127.1.0.1', 'YOUR_PASSWORD')
|
||||
office_temperature = remote.get_state(api, 'sensor.office_temperature')
|
||||
print('{} is {} {}.'.format(office_temperature.attributes['friendly_name'],
|
||||
office_temperature.state,
|
||||
|
@ -97,7 +97,7 @@ The exact same thing is working for a switch. The difference is that both entiti
|
|||
```python
|
||||
import homeassistant.remote as remote
|
||||
|
||||
api = remote.API('127.1.0.1', 'password')
|
||||
api = remote.API('127.1.0.1', 'YOUR_PASSWORD')
|
||||
switch_livingroom = remote.get_state(api, 'switch.livingroom_pin_2')
|
||||
print('{} is {}.'.format(switch_livingroom.attributes['friendly_name'],
|
||||
switch_livingroom.state
|
||||
|
@ -113,7 +113,7 @@ Of course, it's possible to set the state.
|
|||
import homeassistant.remote as remote
|
||||
from homeassistant.const import STATE_ON
|
||||
|
||||
api = remote.API('127.1.0.1', 'password')
|
||||
api = remote.API('127.1.0.1', 'YOUR_PASSWORD')
|
||||
remote.set_state(api, 'sensor.office_temperature', new_state=123)
|
||||
remote.set_state(api, 'switch.livingroom_pin_2', new_state=STATE_ON)
|
||||
```
|
||||
|
@ -122,14 +122,14 @@ The state will be set to those value until the next update occurs.
|
|||
|
||||
### {% linkable_title Blinking all entites of a domain %}
|
||||
|
||||
If you want to turn on all entities of a domain, just a service which was retrieved by `get_services`.
|
||||
If you want to turn on all entities of a domain, just use a service which was retrieved by `get_services`.
|
||||
|
||||
|
||||
```python
|
||||
import time
|
||||
import homeassistant.remote as remote
|
||||
|
||||
api = remote.API('127.1.0.1', 'password')
|
||||
api = remote.API('127.1.0.1', 'YOUR_PASSWORD')
|
||||
domain = 'switch'
|
||||
|
||||
remote.call_service(api, domain, 'turn_on')
|
||||
|
@ -145,7 +145,7 @@ To turn on or off a single switch. The ID of the entity is needed as attribute.
|
|||
import time
|
||||
import homeassistant.remote as remote
|
||||
|
||||
api = remote.API('127.1.0.1', 'password')
|
||||
api = remote.API('127.1.0.1', 'YOUR_PASSWORD')
|
||||
domain = 'switch'
|
||||
switch_name = 'switch.livingroom_pin_2'
|
||||
|
||||
|
@ -185,7 +185,7 @@ The example uses the jabber notification platform to send a single message to th
|
|||
```python
|
||||
import homeassistant.remote as remote
|
||||
|
||||
api = remote.API('127.1.0.1', 'password')
|
||||
api = remote.API('127.1.0.1', 'YOUR_PASSWORD')
|
||||
domain = 'notify'
|
||||
data = {"title":"Test", "message":"A simple test message from HA."}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ print(response.text)
|
|||
```
|
||||
|
||||
<p class='note'>
|
||||
You can append <code>?api_password=YOUR_PASSWORD</code> to any url to log in automatically.
|
||||
You can append `?password=YOUR_PASSWORD` to any url to log in automatically.
|
||||
</p>
|
||||
|
||||
Successful calls will return status code 200 or 201. Other status codes that can return are:
|
||||
|
|
|
@ -18,7 +18,7 @@ A requirement on the client-side is existing support for the [EventSource](https
|
|||
There are various ways to access the stream. One is `curl`:
|
||||
|
||||
```bash
|
||||
$ curl -X GET -H "x-ha-access: 12345" \
|
||||
$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \
|
||||
-H "Content-Type: application/json" http://localhost:8123/api/stream
|
||||
```
|
||||
|
||||
|
@ -31,7 +31,7 @@ For more comfort put the HTML snippet below in a file `sse.html` in your `www` f
|
|||
<h1>Getting Home Assistant server events</h1>
|
||||
<div id="events"></div>
|
||||
<script type="text/javascript">
|
||||
var source = new EventSource("/api/stream");
|
||||
var source = new EventSource("/api/stream?password=YOUR_PASSWORD");
|
||||
source.onmessage = function(event) {
|
||||
document.getElementById("events").innerHTML += event.data + "<br>";
|
||||
};
|
||||
|
@ -44,10 +44,10 @@ Visit [http://localhost:8123/local/sse.html](http://localhost:8123/local/sse.htm
|
|||
|
||||
## {% linkable_title Examples %}
|
||||
|
||||
The simplest way to consume server-sent events is `curl`.
|
||||
A simplest way to consume server-sent events is `httpie`.
|
||||
|
||||
```bash
|
||||
$ curl http://localhost:8123/api/stream?api_password=MYPASS
|
||||
$ http --stream http://localhost:8123/api/stream x-ha-access:YOUR_PASSWORD content-type:application/json
|
||||
```
|
||||
|
||||
### {% linkable_title Website %}
|
||||
|
@ -67,7 +67,7 @@ The simplest script to consume the SSE looks like the following snipplet.
|
|||
```python
|
||||
from sseclient import SSEClient
|
||||
|
||||
messages = SSEClient('http://localhost:8123/api/stream?api_password=MYPASS')
|
||||
messages = SSEClient('http://localhost:8123/api/stream?api_password=YOUR_PASSWORD')
|
||||
for msg in messages:
|
||||
print(msg)
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue