Commit 971927f6 authored by Vassilis Panos's avatar Vassilis Panos
Browse files

[1.3.4] Some code cleanup

parent 77f4f2ec
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)

DOMAIN = 'smartir'
VERSION = '1.3.4'
VERSION = '1.3.5'
VERSION_URL = (
    "https://raw.githubusercontent.com/"
    "smartHomeHub/SmartIR/{}/version.json")
+14 −25
Original line number Diff line number Diff line
@@ -51,23 +51,16 @@ 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)
    temperature_sensor = config.get(CONF_TEMPERATURE_SENSOR)
    humidity_sensor = config.get(CONF_HUMIDITY_SENSOR)
    power_sensor = config.get(CONF_POWER_SENSOR)

    abspath = os.path.dirname(os.path.abspath(__file__))
    hass_config_absdir = os.path.dirname(os.path.abspath(__file__))
    device_files_subdir = os.path.join('codes', 'climate')
    device_files_path = os.path.join(abspath, device_files_subdir)
    device_files_absdir = os.path.join(hass_config_absdir, device_files_subdir)

    if not os.path.isdir(device_files_path):
        os.makedirs(device_files_path)
    if not os.path.isdir(device_files_absdir):
        os.makedirs(device_files_absdir)

    device_json_filename = str(device_code) + '.json'
    device_json_path = os.path.join(device_files_path, device_json_filename)
    device_json_path = os.path.join(device_files_absdir, device_json_filename)

    if not os.path.exists(device_json_path):
        _LOGGER.warning("Couldn't find the device Json file. The component will " \
@@ -94,23 +87,19 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
            return

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

class SmartIRClimate(ClimateDevice, RestoreEntity):
    def __init__(self, hass, unique_id, name, device_code, device_data, 
                 controller_send_service, temperature_sensor, 
                 humidity_sensor, power_sensor):
    def __init__(self, hass, config, device_data):
        self.hass = hass
        self._unique_id = unique_id
        self._name = name
        self._device_code = device_code
        self._controller_send_service = controller_send_service
        self._temperature_sensor = temperature_sensor
        self._humidity_sensor = humidity_sensor
        self._power_sensor = power_sensor
        self._unique_id = config.get(CONF_UNIQUE_ID)
        self._name = config.get(CONF_NAME)
        self._device_code = config.get(CONF_DEVICE_CODE)
        self._controller_send_service = config.get(CONF_CONTROLLER_SEND_SERVICE)
        self._temperature_sensor = config.get(CONF_TEMPERATURE_SENSOR)
        self._humidity_sensor = config.get(CONF_HUMIDITY_SENSOR)
        self._power_sensor = config.get(CONF_POWER_SENSOR)

        self._manufacturer = device_data['manufacturer']
        self._supported_models = device_data['supportedModels']
+13 −19
Original line number Diff line number Diff line
@@ -38,21 +38,17 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
})

async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
    unique_id = config.get(CONF_UNIQUE_ID)
    name = config.get(CONF_NAME)
    """Set up the IR Fan platform."""
    device_code = config.get(CONF_DEVICE_CODE)
    controller_send_service = config.get(CONF_CONTROLLER_SEND_SERVICE)
    power_sensor = config.get(CONF_POWER_SENSOR)

    abspath = os.path.dirname(os.path.abspath(__file__))
    hass_config_absdir = os.path.dirname(os.path.abspath(__file__))
    device_files_subdir = os.path.join('codes', 'fan')
    device_files_path = os.path.join(abspath, device_files_subdir)
    device_files_absdir = os.path.join(hass_config_absdir, device_files_subdir)

    if not os.path.isdir(device_files_path):
        os.makedirs(device_files_path)
    if not os.path.isdir(device_files_absdir):
        os.makedirs(device_files_absdir)

    device_json_filename = str(device_code) + '.json'
    device_json_path = os.path.join(device_files_path, device_json_filename)
    device_json_path = os.path.join(device_files_absdir, device_json_filename)

    if not os.path.exists(device_json_path):
        _LOGGER.warning("Couldn't find the device Json file. The component will " \
@@ -79,19 +75,17 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
            return

    async_add_entities([SmartIRFan(
        hass, unique_id, name, device_code, device_data, 
        controller_send_service, power_sensor
        hass, config, device_data
    )])

class SmartIRFan(FanEntity, RestoreEntity):
    def __init__(self, hass, unique_id, name, device_code, 
                 device_data, controller_send_service, power_sensor):
    def __init__(self, hass, config, device_data):
        self.hass = hass
        self._unique_id = unique_id
        self._name = name
        self._device_code = device_code
        self._controller_send_service = controller_send_service
        self._power_sensor = power_sensor
        self._unique_id = config.get(CONF_UNIQUE_ID)
        self._name = config.get(CONF_NAME)
        self._device_code = config.get(CONF_DEVICE_CODE)
        self._controller_send_service = config.get(CONF_CONTROLLER_SEND_SERVICE)
        self._power_sensor = config.get(CONF_POWER_SENSOR)

        self._manufacturer = device_data['manufacturer']
        self._supported_models = device_data['supportedModels']
+12 −19
Original line number Diff line number Diff line
@@ -39,21 +39,16 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({

async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
    """Set up the IR Media Player 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)
    power_sensor = config.get(CONF_POWER_SENSOR)

    abspath = os.path.dirname(os.path.abspath(__file__))
    hass_config_absdir = os.path.dirname(os.path.abspath(__file__))
    device_files_subdir = os.path.join('codes', 'media_player')
    device_files_path = os.path.join(abspath, device_files_subdir)
    device_files_absdir = os.path.join(hass_config_absdir, device_files_subdir)

    if not os.path.isdir(device_files_path):
        os.makedirs(device_files_path)
    if not os.path.isdir(device_files_absdir):
        os.makedirs(device_files_absdir)

    device_json_filename = str(device_code) + '.json'
    device_json_path = os.path.join(device_files_path, device_json_filename)
    device_json_path = os.path.join(device_files_absdir, device_json_filename)

    if not os.path.exists(device_json_path):
        _LOGGER.warning("Couldn't find the device Json file. The component will " \
@@ -80,19 +75,17 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
            return

    async_add_entities([SmartIRMediaPlayer(
        hass, unique_id, name, device_code, device_data, 
        controller_send_service, power_sensor
        hass, config, device_data
    )])

class SmartIRMediaPlayer(MediaPlayerDevice, RestoreEntity):
    def __init__(self, hass, unique_id, name, device_code, 
                 device_data, controller_send_service, power_sensor):
    def __init__(self, hass, config, device_data):
        self.hass = hass
        self._unique_id = unique_id
        self._name = name
        self._device_code = device_code
        self._controller_send_service = controller_send_service
        self._power_sensor = power_sensor
        self._unique_id = config.get(CONF_UNIQUE_ID)
        self._name = config.get(CONF_NAME)
        self._device_code = config.get(CONF_DEVICE_CODE)
        self._controller_send_service = config.get(CONF_CONTROLLER_SEND_SERVICE)
        self._power_sensor = config.get(CONF_POWER_SENSOR)

        self._manufacturer = device_data['manufacturer']
        self._supported_models = device_data['supportedModels']
+2 −2
Original line number Diff line number Diff line
{            
    "version": "1.3.4",
    "version": "1.3.5",
    "minHAVersion": "0.89",
    "releaseNotes": "A new version (1.3.4) is available that is compatible with your system. Call the ``smartir.update_component`` service to update the component.",
    "releaseNotes": "A new version (1.3.5) is available that is compatible with your system. Call the ``smartir.update_component`` service to update the component.",
    "files": [
        "__init__.py",
        "climate.py",