mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-11-09 02:58:52 +00:00
Merge branch 'current' into next
This commit is contained in:
@@ -41,7 +41,7 @@ and not mention sign-off.
|
||||
|
||||
## Signing
|
||||
|
||||
To sign this CLA you must first submit a pull request to a repository under the Home Assistant organization.
|
||||
If you have not signed the CLA and you submit a pull request to a repository under the Home Assistant organization, a link will be automatically generated. Just follow the link and the instructions in the link.
|
||||
|
||||
## Adoption
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ footer: true
|
||||
---
|
||||
|
||||
New controller or hub components often need to add platforms in sub-components (i.e. Lights & Switches) without additional configuration.
|
||||
This can be achieved using the `homeassistant.components.discovery.load_platform` method:
|
||||
This can be achieved using the `load_platform` or `async_load_platform` methods from `homeassistant.helpers.discovery`:
|
||||
|
||||
```python
|
||||
def load_platform(hass, component, platform, info=None, hass_config=None)
|
||||
def load_platform(hass, component, platform, discovered=None, hass_config=None)
|
||||
```
|
||||
|
||||
From more info on how this works, refer to the [load_platform](https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/discovery.py#L78) method.
|
||||
From more info on how this works, refer to the [load_platform](https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/helpers/discovery.py#L136) method.
|
||||
|
||||
### {% linkable_title Example %}
|
||||
|
||||
@@ -40,7 +40,7 @@ The source for your component can be located in your configuration directory for
|
||||
In the hub component `myflashyhub.py` you can call your light and switch components. To pass any non-serializable information to the platforms in the sub-component, you can use a global variable.
|
||||
|
||||
```python
|
||||
from homeassistant.components.discovery import load_platform
|
||||
from homeassistant.helpers.discovery import load_platform
|
||||
DOMAIN = 'myflashyhub'
|
||||
|
||||
MFH_GLOBAL = None
|
||||
@@ -77,7 +77,3 @@ The `load_platform` method allows the platforms to be loaded with the need for a
|
||||
#switch:
|
||||
# platform: myflashyhub
|
||||
```
|
||||
|
||||
<p class='note '>
|
||||
In the past, this was achieved by adding your component to the `DISCOVERY_PLATFORMS` in the target sub-component. Generic discovery through `load_platform()` allows you to load any sub-component, including custom components, without changing the sub-component.
|
||||
</p>
|
||||
|
||||
@@ -76,11 +76,14 @@ class AwesomeLight(Light):
|
||||
def __init__(self, light):
|
||||
"""Initialize an AwesomeLight."""
|
||||
self._light = light
|
||||
self._name = light.name
|
||||
self._state = None
|
||||
self._brightness = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the display name of this light."""
|
||||
return self._light.name
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
@@ -89,12 +92,12 @@ class AwesomeLight(Light):
|
||||
This method is optional. Removing it indicates to Home Assistant
|
||||
that brightness is not supported for this light.
|
||||
"""
|
||||
return self._light.brightness
|
||||
return self._brightness
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if light is on."""
|
||||
return self._light.is_on()
|
||||
return self._state
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Instruct the light to turn on.
|
||||
@@ -115,4 +118,6 @@ class AwesomeLight(Light):
|
||||
This is the only method that should fetch new data for Home Assistant.
|
||||
"""
|
||||
self._light.update()
|
||||
self._state = self._light.is_on()
|
||||
self._brightness = self._light.brightness
|
||||
```
|
||||
|
||||
@@ -38,6 +38,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
class ExampleSensor(Entity):
|
||||
"""Representation of a Sensor."""
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize the sensor."""
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
@@ -46,10 +50,17 @@ class ExampleSensor(Entity):
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
return 23
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return TEMP_CELSIUS
|
||||
|
||||
def update(self):
|
||||
"""Fetch new state data for the sensor.
|
||||
|
||||
This is the only method that should fetch new data for Home Assistant.
|
||||
"""
|
||||
self._state = 23
|
||||
```
|
||||
|
||||
@@ -418,7 +418,7 @@ Sample `curl` command:
|
||||
```bash
|
||||
$ curl -X POST -H "x-ha-access: YOUR_PASSWORD" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"entity_id": "switch.christmas_lights", "state": "on"}' \
|
||||
-d '{"entity_id": "switch.christmas_lights"}' \
|
||||
http://localhost:8123/api/services/switch/turn_on
|
||||
```
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
layout: page
|
||||
title: "Websocket API"
|
||||
description: "Home Assistant Websocket API documentation"
|
||||
title: "WebSocket API"
|
||||
description: "Home Assistant WebSocket API documentation"
|
||||
date: 2016-11-26 13:27
|
||||
sidebar: true
|
||||
comments: false
|
||||
@@ -9,9 +9,11 @@ sharing: true
|
||||
footer: true
|
||||
---
|
||||
|
||||
Home Assistant contains a websocket API. This API can be used to stream information from a Home Assistant instance to any client that implements websockets. Implementations in different languages:
|
||||
Home Assistant contains a WebSocket API. This API can be used to stream information from a Home Assistant instance to any client that implements WebSocket. Implementations in different languages:
|
||||
|
||||
- [JavaScript](https://github.com/home-assistant/home-assistant-js-websocket) - powers the frontend
|
||||
- [Python](https://raw.githubusercontent.com/home-assistant/home-assistant-dev-helper/master/ha-websocket-client.py) - CLI client using [`asyncws`](https://async-websockets.readthedocs.io/en/latest/)
|
||||
- [JavaScript/HTML](https://raw.githubusercontent.com/home-assistant/home-assistant-dev-helper/master/ha-websocket.html) - WebSocket connection in your browser
|
||||
|
||||
Connect your websocket implementation to `ws://localhost:8123/api/websocket`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user