Skip to content

Commit

Permalink
generate unique id automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Jan 7, 2022
1 parent 601806c commit 32af168
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ The climate will have 2 modes :

## Configuration

| Key | Type | Required | Description |
| :----------------- | :------ | :------- | :-------------------------------------------------------------------------------------------------------------------------- |
| `platform` | string | yes | Platform name |
| `heater` | string | yes | Light entity |
| `sensor` | string | no | Temperature sensor (for display) |
| `additional_modes` | boolean | no | 6-order support (add Comfort -1 and Comfort -2 preset) |
| `name` | string | no | Name to use in the frontend. |
| `unique_id` | string | no | An ID that uniquely identifies this cover group. If two climates have the same unique ID, Home Assistant will raise an error. |
| Key | Type | Required | Description |
| :----------------- | :------ | :------- | :------------------------------------------------------------------------------------------------------------------------ |
| `platform` | string | yes | Platform name |
| `heater` | string | yes | Light entity |
| `sensor` | string | no | Temperature sensor (for display) |
| `additional_modes` | boolean | no | 6-order support (add Comfort -1 and Comfort -2 preset) |
| `name` | string | no | Name to use in the frontend. |
| `unique_id` | string | no | An ID that uniquely identifies this climate. If two climates have the same unique ID, Home Assistant will raise an error. |

The unique id is recommended to allow icon, entity_id or name changes from the UI.
The unique id is recommended to allow icon, entity_id or name changes from the UI.

## Example

Expand Down Expand Up @@ -69,13 +69,20 @@ climate:
sensor: sensor.temperature_living_room
```
using unique_id (This allow you to edit entity_id, name, icon from the UI)
## Unique ID
The `unique_id` is used to edit the entity from the GUI. It's automatically generated from heater entity_id. As the `unique_id` must be unique, you can not create 2 entities with the same heater.

If you want to have 2 climate with the same heater, you must specify the `unique_id` in the config.

```yaml
climate:
- platform: qubino_wire_pilot
heater: light.heater_living_room_dimmer
unique_id: qubino_thermostat
unique_id: qubino_heater_living_room_1
- platform: qubino_wire_pilot
heater: light.heater_living_room_dimmer
unique_id: qubino_heater_living_room_2
```

## Lovelace
Expand Down
16 changes: 9 additions & 7 deletions custom_components/qubino_wire_pilot/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
additional_modes = config.get(CONF_ADDITIONAL_MODES)

async_add_entities(
[QubinoWirePilotClimate(unique_id, name, heater_entity_id, sensor_entity_id, additional_modes)]
[QubinoWirePilotClimate(
unique_id, name, heater_entity_id, sensor_entity_id, additional_modes)]
)


Expand All @@ -86,13 +87,13 @@ class QubinoWirePilotClimate(ClimateEntity, RestoreEntity):

def __init__(self, unique_id, name, heater_entity_id, sensor_entity_id, additional_modes):
"""Initialize the climate device."""

self.heater_entity_id = heater_entity_id
self.sensor_entity_id = sensor_entity_id
self.additional_modes = additional_modes
self._cur_temperature = None
self._attr_unique_id = unique_id

self._attr_unique_id = unique_id if unique_id else "qubino_wire_pilot_" + heater_entity_id
self._attr_name = name

async def async_added_to_hass(self):
Expand All @@ -118,7 +119,8 @@ def _async_startup(event):

self.async_schedule_update_ha_state()

self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _async_startup)
self.hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_START, _async_startup)

@property
def supported_features(self):
Expand Down Expand Up @@ -195,7 +197,7 @@ async def async_set_preset_mode(self, preset_mode):
value = VALUE_COMFORT_1
elif preset_mode == PRESET_COMFORT:
value = VALUE_COMFORT

await self._async_set_heater_value(value)

# Modes
Expand Down Expand Up @@ -252,4 +254,4 @@ async def _async_set_heater_value(self, value):
light.ATTR_BRIGHTNESS: value * 255 / 99,
}

await self.hass.services.async_call(light.DOMAIN, light.SERVICE_TURN_ON, data)
await self.hass.services.async_call(light.DOMAIN, light.SERVICE_TURN_ON, data)
2 changes: 1 addition & 1 deletion custom_components/qubino_wire_pilot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"issue_tracker": "https://github.com/piitaya/home-assitant-qubino_wire_pilot/issues",
"requirements": [],
"dependencies": [],
"version": "1.2.0",
"version": "2.0.0",
"codeowners": ["@piitaya"]
}

0 comments on commit 32af168

Please sign in to comment.