mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-12 11:56:29 +00:00
Update mobile app (#1325)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
76d4c8aacf
commit
ab9f007804
@ -24,7 +24,8 @@ To register a sensor, make a request to the webhook like this:
|
||||
"unique_id": "battery_state",
|
||||
"unit_of_measurement": "%",
|
||||
"state_class": "measurement",
|
||||
"entity_category": "diagnostic"
|
||||
"entity_category": "diagnostic",
|
||||
"disabled": true
|
||||
},
|
||||
"type": "register_sensor"
|
||||
}
|
||||
@ -44,6 +45,7 @@ The valid keys are:
|
||||
| unit_of_measurement | string | No | The unit of measurement for the sensor |
|
||||
| state_class | string | No | The [state class](../../core/entity/sensor.md#available-state-classes) of the entity (sensors only)
|
||||
| entity_category | string | No | The entity category of the entity
|
||||
| disabled | boolean | No | If the entity should be enabled or disabled.
|
||||
|
||||
Sensors will appear as soon as they are registered.
|
||||
|
||||
@ -79,3 +81,70 @@ Only some of the keys are allowed during updates:
|
||||
| state | bool, float, int, string | Yes | The state of the sensor |
|
||||
| type | string | Yes | The type of the sensor. Must be one of `binary_sensor` or `sensor` |
|
||||
| unique_id | string | Yes | An identifier unique to this installation of your app. You'll need this later. Usually best when its a safe version of the sensor name |
|
||||
|
||||
The response to updating a sensor is a dictionary with unique_id => update result.
|
||||
|
||||
The key `is_disabled` will be added to successful updates if the entity is disabled inside Home Assistant. This means the app can disable sending updates to the sensor.
|
||||
|
||||
If an update was unsuccessful, an error is returned.
|
||||
|
||||
```json
|
||||
{
|
||||
"battery_state": {
|
||||
"success": true
|
||||
},
|
||||
"battery_level": {
|
||||
"success": true,
|
||||
"is_disabled": true
|
||||
},
|
||||
"battery_charging": {
|
||||
"success": false,
|
||||
"error": {
|
||||
"code": "not_registered",
|
||||
"message": "Entity is not registered",
|
||||
}
|
||||
},
|
||||
"battery_charging_state": {
|
||||
"success": false,
|
||||
"error": {
|
||||
"code": "invalid_format",
|
||||
"message": "Unexpected value for type",
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Keeping sensors in sync with Home Assistant
|
||||
|
||||
Users can enable and disable entities in Home Assistant. A disabled entity will not be added to Home Assistant, even if offered by the integration. This means that it won't make sense for phones to keep sending data to entities that are not enabled in Home Assistant.
|
||||
|
||||
**When a sensor is enabled/disabled in the app**, the app should send a `register_sensor` webhook for this sensor and set `disabled` to `true` or `false`.
|
||||
|
||||
**When the mobile app sends an `update_sensor_states` webhook to update the data for an entity that is disabled**, the update result will contain an `is_disabled` key with a value of `true`. This is an indicator that the mobile app needs to synchronize the enabled states from Home Assistant to the mobile app.
|
||||
|
||||
```json
|
||||
{
|
||||
"battery_level": {
|
||||
"success": true,
|
||||
},
|
||||
"battery_charging": {
|
||||
"success": true,
|
||||
"is_disabled": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**When the user enables/disables an entity in Home Assistant, it needs to be synchronized to the mobile app.** The `get_config` webhook response contains an `entities` key. This is a dictionary mapping `unique_id` to `{"disabled": boolean}`. The mobile app should adopt these enabled settings.
|
||||
|
||||
```json5
|
||||
{
|
||||
// ...
|
||||
"entities": {
|
||||
"battery_level": {
|
||||
"disabled": false
|
||||
},
|
||||
"battery_charging": {
|
||||
"disabled": true
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user