Unverified Commit e5c1a956 authored by Vassilis Panos's avatar Vassilis Panos Committed by GitHub
Browse files

Add support for unique_id

parent 831c7177
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ _LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = "SmartIR Climate"

CONF_UNIQUE_ID = 'unique_id'
CONF_DEVICE_CODE = 'device_code'
CONF_CONTROLLER_SEND_SERVICE = "controller_send_service"
CONF_TEMPERATURE_SENSOR = 'temperature_sensor'
@@ -39,6 +40,7 @@ SUPPORT_FLAGS = (
)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Optional(CONF_UNIQUE_ID): cv.string,
    vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
    vol.Required(CONF_DEVICE_CODE): cv.positive_int,
    vol.Required(CONF_CONTROLLER_SEND_SERVICE): cv.entity_id,
@@ -49,6 +51,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({

async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
    """Set up the IR Climate platform."""
    unique_id = config.get(CONF_UNIQUE_ID)
    name = config.get(CONF_NAME)
    device_code = config.get(CONF_DEVICE_CODE)
    controller_send_service = config.get(CONF_CONTROLLER_SEND_SERVICE)
@@ -91,15 +94,17 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
            return

    async_add_entities([SmartIRClimate(
        hass, name, device_code, device_data, controller_send_service, 
        temperature_sensor, humidity_sensor, power_sensor
        hass, name, unique_id, device_code, device_data, 
        controller_send_service, temperature_sensor, 
        humidity_sensor, power_sensor
    )])

class SmartIRClimate(ClimateDevice, RestoreEntity):
    def __init__(self, hass, name, device_code, device_data, 
    def __init__(self, hass, unique_id, name, device_code, device_data, 
                 controller_send_service, temperature_sensor, 
                 humidity_sensor, power_sensor):
        self.hass = hass
        self._unique_id = unique_id
        self._name = name
        self._device_code = device_code
        self._controller_send_service = controller_send_service
@@ -167,9 +172,9 @@ class SmartIRClimate(ClimateDevice, RestoreEntity):
                                     self._async_power_sensor_changed)

    @property
    def should_poll(self):
        """Return the polling state."""
        return False
    def unique_id(self):
        """Return a unique ID."""
        return self._unique_id

    @property
    def name(self):