update to HA 0.110.4 & smartir 1.12.0

This commit is contained in:
Erimus MBA 2020-06-04 00:32:43 +08:00
parent 0a5d2d0c88
commit 98414b7b47
8 changed files with 92 additions and 45 deletions

View File

@ -1 +1 @@
0.108.4
0.110.4

View File

@ -22,6 +22,7 @@ homeassistant:
allow_bypass_login: true
- type: homeassistant
zeroconf:
group: !include groups.yaml # 分组
automation: !include automations.yaml # 自动化
script: !include scripts.yaml # 脚本/批处理命令
@ -31,8 +32,8 @@ homekit: !include homekit.yaml # 管理homekit出现的项目
# iOS App 需要的部件
default_config:
mobile_app:
discovery: # Discover some devices automatically
# mobile_app:
# discovery: # Discover some devices automatically
ios: # advanced notifications like actionable notifications and categories
# cloud: # securely connecting to your Home Assistant via Nabu Casa

View File

@ -19,7 +19,7 @@ from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
DOMAIN = 'smartir'
VERSION = '1.7.5'
VERSION = '1.12.0'
MANIFEST_URL = (
"https://raw.githubusercontent.com/"
"smartHomeHub/SmartIR/{}/"
@ -108,7 +108,7 @@ async def _update(hass, branch, do_update=False, notify_if_latest=True):
dest = os.path.join(COMPONENT_ABS_DIR, file)
os.makedirs(os.path.dirname(dest), exist_ok=True)
await Helper.downloader(source, dest)
except:
except Exception:
has_errors = True
_LOGGER.error("Error updating %s. Please update the file manually.", file)
@ -120,7 +120,7 @@ async def _update(hass, branch, do_update=False, notify_if_latest=True):
hass.components.persistent_notification.async_create(
"Successfully updated to {}. Please restart Home Assistant."
.format(last_version), title='SmartIR')
except:
except Exception:
_LOGGER.error("An error occurred while checking for updates.")
class Helper():

View File

@ -5,7 +5,7 @@ import os.path
import voluptuous as vol
from homeassistant.components.climate import ClimateDevice, PLATFORM_SCHEMA
from homeassistant.components.climate import ClimateEntity, PLATFORM_SCHEMA
from homeassistant.components.climate.const import (
HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_COOL,
HVAC_MODE_DRY, HVAC_MODE_FAN_ONLY, HVAC_MODE_AUTO,
@ -69,7 +69,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
"codes/climate/{}.json")
await Helper.downloader(codes_source.format(device_code), device_json_path)
except:
except Exception:
_LOGGER.error("There was an error while downloading the device Json file. " \
"Please check your internet connection or if the device code " \
"exists on GitHub. If the problem still exists please " \
@ -79,7 +79,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
with open(device_json_path) as j:
try:
device_data = json.load(j)
except:
except Exception:
_LOGGER.error("The device Json file is invalid")
return
@ -87,7 +87,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
hass, config, device_data
)])
class SmartIRClimate(ClimateDevice, RestoreEntity):
class SmartIRClimate(ClimateEntity, RestoreEntity):
def __init__(self, hass, config, device_data):
self.hass = hass
self._unique_id = config.get(CONF_UNIQUE_ID)
@ -320,18 +320,23 @@ class SmartIRClimate(ClimateDevice, RestoreEntity):
async def send_command(self):
async with self._temp_lock:
self._on_by_remote = False
operation_mode = self._hvac_mode
fan_mode = self._current_fan_mode
target_temperature = '{0:g}'.format(self._target_temperature)
if operation_mode.lower() == HVAC_MODE_OFF:
command = self._commands['off']
else:
command = self._commands[operation_mode][fan_mode][target_temperature]
try:
await self._controller.send(command)
self._on_by_remote = False
operation_mode = self._hvac_mode
fan_mode = self._current_fan_mode
target_temperature = '{0:g}'.format(self._target_temperature)
if operation_mode.lower() == HVAC_MODE_OFF:
await self._controller.send(self._commands['off'])
return
if 'on' in self._commands:
await self._controller.send(self._commands['on'])
await asyncio.sleep(0.5)
await self._controller.send(
self._commands[operation_mode][fan_mode][target_temperature])
except Exception as e:
_LOGGER.exception(e)

View File

@ -1,10 +1,10 @@
import asyncio
from base64 import b64encode
import binascii
import requests
import logging
import json
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import split_entity_id
from . import Helper
_LOGGER = logging.getLogger(__name__)
@ -12,24 +12,25 @@ _LOGGER = logging.getLogger(__name__)
BROADLINK_CONTROLLER = 'Broadlink'
XIAOMI_CONTROLLER = 'Xiaomi'
MQTT_CONTROLLER = 'MQTT'
LOOKIN_CONTROLLER = 'LOOKin'
ESPHOME_CONTROLLER = 'ESPHome'
ENC_BASE64 = 'Base64'
ENC_HEX = 'Hex'
ENC_PRONTO = 'Pronto'
ENC_RAW = 'Raw'
BROADLINK_COMMANDS_ENCODING = [
ENC_BASE64, ENC_HEX, ENC_PRONTO]
XIAOMI_COMMANDS_ENCODING = [
ENC_PRONTO, ENC_RAW]
BROADLINK_COMMANDS_ENCODING = [ENC_BASE64, ENC_HEX, ENC_PRONTO]
XIAOMI_COMMANDS_ENCODING = [ENC_PRONTO, ENC_RAW]
MQTT_COMMANDS_ENCODING = [ENC_RAW]
LOOKIN_COMMANDS_ENCODING = [ENC_PRONTO, ENC_RAW]
ESPHOME_COMMANDS_ENCODING = [ENC_RAW]
class Controller():
def __init__(self, hass, controller, encoding, controller_data):
if controller not in [
BROADLINK_CONTROLLER, XIAOMI_CONTROLLER, MQTT_CONTROLLER]:
BROADLINK_CONTROLLER, XIAOMI_CONTROLLER,
MQTT_CONTROLLER, LOOKIN_CONTROLLER, ESPHOME_CONTROLLER]:
raise Exception("The controller is not supported.")
if controller == BROADLINK_CONTROLLER:
@ -47,6 +48,16 @@ class Controller():
raise Exception("The encoding is not supported "
"by the mqtt controller.")
if controller == LOOKIN_CONTROLLER:
if encoding not in LOOKIN_COMMANDS_ENCODING:
raise Exception("The encoding is not supported "
"by the LOOKin controller.")
if controller == ESPHOME_CONTROLLER:
if encoding not in ESPHOME_COMMANDS_ENCODING:
raise Exception("The encoding is not supported "
"by the ESPHome controller.")
self.hass = hass
self._controller = controller
self._encoding = encoding
@ -99,4 +110,20 @@ class Controller():
}
await self.hass.services.async_call(
'mqtt', 'publish', service_data)
'mqtt', 'publish', service_data)
if self._controller == LOOKIN_CONTROLLER:
encoding = self._encoding.lower().replace('pronto', 'prontohex')
url = f"http://{self._controller_data}/commands/ir/" \
f"{encoding}/{command}"
await self.hass.async_add_executor_job(
requests.get, url
)
if self._controller == ESPHOME_CONTROLLER:
service_data = {
'command': json.loads(command)
}
await self.hass.services.async_call(
'esphome', self._controller_data, service_data)

View File

@ -9,7 +9,7 @@ from homeassistant.components.fan import (
FanEntity, PLATFORM_SCHEMA, ATTR_SPEED,
SPEED_OFF, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH,
DIRECTION_REVERSE, DIRECTION_FORWARD,
SUPPORT_SET_SPEED, SUPPORT_DIRECTION)
SUPPORT_SET_SPEED, SUPPORT_DIRECTION, SUPPORT_OSCILLATE, ATTR_OSCILLATING )
from homeassistant.const import (
CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN)
from homeassistant.core import callback
@ -58,7 +58,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
"codes/fan/{}.json")
await Helper.downloader(codes_source.format(device_code), device_json_path)
except:
except Exception:
_LOGGER.error("There was an error while downloading the device Json file. " \
"Please check your internet connection or if the device code " \
"exists on GitHub. If the problem still exists please " \
@ -68,7 +68,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
with open(device_json_path) as j:
try:
device_data = json.load(j)
except:
except Exception:
_LOGGER.error("The device JSON file is invalid")
return
@ -95,7 +95,7 @@ class SmartIRFan(FanEntity, RestoreEntity):
self._speed = SPEED_OFF
self._direction = None
self._last_on_speed = None
self._oscillating = None
self._support_flags = SUPPORT_SET_SPEED
if (DIRECTION_REVERSE in self._commands and \
@ -103,6 +103,11 @@ class SmartIRFan(FanEntity, RestoreEntity):
self._direction = DIRECTION_REVERSE
self._support_flags = (
self._support_flags | SUPPORT_DIRECTION)
if ('oscillate' in self._commands):
self._oscillating = False
self._support_flags = (
self._support_flags | SUPPORT_OSCILLATE)
self._temp_lock = asyncio.Lock()
self._on_by_remote = False
@ -168,7 +173,7 @@ class SmartIRFan(FanEntity, RestoreEntity):
@property
def oscillating(self):
"""Return the oscillation state."""
return None
return self._oscillating
@property
def direction(self):
@ -207,6 +212,13 @@ class SmartIRFan(FanEntity, RestoreEntity):
await self.send_command()
await self.async_update_ha_state()
async def async_oscillate(self, oscillating: bool) -> None:
"""Set oscillation of the fan."""
self._oscillating = oscillating
await self.send_command()
await self.async_update_ha_state()
async def async_set_direction(self, direction: str):
"""Set the direction of the fan"""
self._direction = direction
@ -232,9 +244,12 @@ class SmartIRFan(FanEntity, RestoreEntity):
self._on_by_remote = False
speed = self._speed
direction = self._direction or 'default'
oscillating = self._oscillating
if speed.lower() == SPEED_OFF:
command = self._commands['off']
elif oscillating:
command = self._commands['oscillate']
else:
command = self._commands[direction][speed]
@ -257,4 +272,4 @@ class SmartIRFan(FanEntity, RestoreEntity):
self._on_by_remote = False
if self._speed != SPEED_OFF:
self._speed = SPEED_OFF
await self.async_update_ha_state()
await self.async_update_ha_state()

View File

@ -5,10 +5,10 @@
"dependencies": [],
"codeowners": ["@smartHomeHub"],
"requirements": ["aiofiles==0.5.0"],
"homeassistant": "0.96.0",
"homeassistant": "0.110.0b0",
"updater": {
"version": "1.7.5",
"releaseNotes": "-- Fix doing I/O",
"version": "1.12.0",
"releaseNotes": "-- Adds support for ESPHome",
"files": [
"__init__.py",
"climate.py",

View File

@ -6,14 +6,13 @@ import os.path
import voluptuous as vol
from homeassistant.components.media_player import (
MediaPlayerDevice, PLATFORM_SCHEMA)
MediaPlayerEntity, PLATFORM_SCHEMA)
from homeassistant.components.media_player.const import (
SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_PREVIOUS_TRACK,
SUPPORT_NEXT_TRACK, SUPPORT_VOLUME_STEP, SUPPORT_VOLUME_MUTE,
SUPPORT_SELECT_SOURCE, MEDIA_TYPE_CHANNEL)
from homeassistant.const import (
CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN)
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.restore_state import RestoreEntity
from . import COMPONENT_ABS_DIR, Helper
@ -63,7 +62,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
"codes/media_player/{}.json")
await Helper.downloader(codes_source.format(device_code), device_json_path)
except:
except Exception:
_LOGGER.error("There was an error while downloading the device Json file. " \
"Please check your internet connection or if the device code " \
"exists on GitHub. If the problem still exists please " \
@ -73,7 +72,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
with open(device_json_path) as j:
try:
device_data = json.load(j)
except:
except Exception:
_LOGGER.error("The device JSON file is invalid")
return
@ -81,7 +80,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
hass, config, device_data
)])
class SmartIRMediaPlayer(MediaPlayerDevice, RestoreEntity):
class SmartIRMediaPlayer(MediaPlayerEntity, RestoreEntity):
def __init__(self, hass, config, device_data):
self.hass = hass
self._unique_id = config.get(CONF_UNIQUE_ID)