Skip to content

Commit

Permalink
add unique id support
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Sep 1, 2021
1 parent bfaf4c4 commit 9d666a7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,22 @@ The climate will have 2 modes :

## Configuration

| Key | Type | Required | Description |
| :----------------- | :------ | :------- | :----------------------------------------------------- |
| `platform` | string | yes | Platform name |
| `name` | string | yes | Name of the entity |
| `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) |
| 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. |

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

## Example

```yaml
climate:
- platform: qubino_wire_pilot
name: thermostat_living_room
heater: light.heater_living_room_dimmer
```
Expand All @@ -54,7 +56,6 @@ with 6 order
```yaml
climate:
- platform: qubino_wire_pilot
name: thermostat_living_room
heater: light.heater_living_room_dimmer
additional_modes: true
```
Expand All @@ -64,11 +65,17 @@ with optional sensor
```yaml
climate:
- platform: qubino_wire_pilot
name: thermostat_living_room
heater: light.heater_living_room_dimmer
sensor: sensor.temperature_living_room
```
```yaml
climate:
- platform: qubino_wire_pilot
heater: light.heater_living_room_dimmer
unique_id: sensor.temperature_living_room
```
## Lovelace
You can use the [climate-mode-entity-row](https://github.com/piitaya/lovelace-climate-mode-entity-row) card in your lovelace dashboard to easily switch between modes.
24 changes: 11 additions & 13 deletions custom_components/qubino_wire_pilot/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
PRESET_NONE,
)
from homeassistant.const import (
CONF_HOST,
TEMP_CELSIUS,
ATTR_TEMPERATURE,
CONF_NAME,
CONF_UNIQUE_ID,
EVENT_HOMEASSISTANT_START,
ATTR_ENTITY_ID,
STATE_UNKNOWN,
Expand All @@ -45,7 +44,6 @@
CONF_HEATER = "heater"
CONF_SENSOR = "sensor"
CONF_ADDITIONAL_MODES = "additional_modes"
CONF_NAME = "name"

PRESET_COMFORT_1 = "comfort-1"
PRESET_COMFORT_2 = "comfort-2"
Expand All @@ -61,8 +59,9 @@
{
vol.Required(CONF_HEATER): cv.entity_id,
vol.Optional(CONF_SENSOR): cv.entity_id,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_ADDITIONAL_MODES, default=False): cv.boolean,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_UNIQUE_ID): cv.string,
}
)

Expand All @@ -71,26 +70,30 @@

async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the wire pilot climate platform."""
unique_id = config.get(CONF_UNIQUE_ID)
name = config.get(CONF_NAME)
heater_entity_id = config.get(CONF_HEATER)
sensor_entity_id = config.get(CONF_SENSOR)
additional_modes = config.get(CONF_ADDITIONAL_MODES)

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


class QubinoWirePilotClimate(ClimateEntity, RestoreEntity):
"""Representation of a Qubino Wire Pilot device."""

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

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_name = name

async def async_added_to_hass(self):
"""Run when entity about to be added."""
Expand Down Expand Up @@ -125,11 +128,6 @@ def supported_features(self):
def update(self):
"""Update unit attributes."""

@property
def name(self):
"""Return the name of the climate device."""
return self._name

# Temperature
@property
def temperature_unit(self):
Expand Down
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.0.4",
"version": "1.2.0",
"codeowners": ["@piitaya"]
}

0 comments on commit 9d666a7

Please sign in to comment.