Skip to content

Commit

Permalink
Add support for Hisense AEH-W4A1 wifi module (AC remote control) (hom…
Browse files Browse the repository at this point in the history
…e-assistant#28641)

* First commit

* First working release, but there's a lot to do

* Added support for preset_modes

* Refined logic

* Added translations for config_flow

* Updated translations

* modified:   homeassistant/components/hisense_aehw4a1/climate.py

* modified:   climate.py

* Updated library to latest version

* Small changes

* Null states when AC off

* Minor fixes

* Latest updates for TOX

* First commit

* First working release, but there's a lot to do

* new file:   requirements_test_all.txt

* Added support for preset_modes

* Refined logic

* Added translations for config_flow

* Updated translations

* modified:   homeassistant/components/hisense_aehw4a1/climate.py

* modified:   climate.py

* Updated library to latest version

* Small changes

* Null states when AC off

* Minor fixes

* Latest updates for TOX

* new file:   requirements_test_all.txt

* Fighting with tox

* vs Tox round 2

* Isort and updated requirements_test_all.txt

* Fighting with lint

* Implemented available state

* Changed exception type after Travis-ci pylint fails

* Support entry in configuration.yaml

* Removed commented code

* Switched to async

* Minor changes

* Updated library and fixed pylint errors

* Code optimization

* Implemented static ip addresses in configuration.yaml

* Reverted to existing constant

* Corrected pylint wrong-import-order

* Recovery from nuke event (messing all while rebase)

* Resolved Ci error

* Changes for PR

* Corrected temp scale for frontend

* Added test for config entry from configuration.yaml

* Updated dependency

* Check on manual config

* Imported custom exceptions and modified import config

* Optimized

* Change based on PR revision

* Added logging for failure event on manual config

* Tests added but to be corrected

* Edited tests

* Tests updated to ensure no I/O

* Working on tests

* Cheanges based on revision for PR

* Setting librey exception as direct side_effect in test

* Final changes for PR

* Redundand on command solved

* Improved AC logic
  • Loading branch information
bannhead authored and MartinHjelmare committed Nov 15, 2019
1 parent 3500084 commit d796053
Show file tree
Hide file tree
Showing 13 changed files with 671 additions and 0 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ omit =
homeassistant/components/heatmiser/climate.py
homeassistant/components/hikvision/binary_sensor.py
homeassistant/components/hikvisioncam/switch.py
homeassistant/components/hisense_aehw4a1/*
homeassistant/components/hitron_coda/device_tracker.py
homeassistant/components/hive/*
homeassistant/components/hlk_sw16/*
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ homeassistant/components/heos/* @andrewsayre
homeassistant/components/here_travel_time/* @eifinger
homeassistant/components/hikvision/* @mezz64
homeassistant/components/hikvisioncam/* @fbradyirl
homeassistant/components/hisense_aehw4a1/* @bannhead
homeassistant/components/history/* @home-assistant/core
homeassistant/components/history_graph/* @andrey-git
homeassistant/components/hive/* @Rendili @KJonline
Expand Down
81 changes: 81 additions & 0 deletions homeassistant/components/hisense_aehw4a1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""The Hisense AEH-W4A1 integration."""
import ipaddress
import logging

from pyaehw4a1.aehw4a1 import AehW4a1
import pyaehw4a1.exceptions
import voluptuous as vol

from homeassistant import config_entries
from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN
from homeassistant.const import CONF_IP_ADDRESS
import homeassistant.helpers.config_validation as cv

from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)


def coerce_ip(value):
"""Validate that provided value is a valid IP address."""
if not value:
raise vol.Invalid("Must define an IP address")
try:
ipaddress.IPv4Network(value)
except ValueError:
raise vol.Invalid("Not a valid IP address")
return value


CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: {
CLIMATE_DOMAIN: vol.Schema(
{
vol.Optional(CONF_IP_ADDRESS, default=[]): vol.All(
cv.ensure_list, [vol.All(cv.string, coerce_ip)]
)
}
)
}
},
extra=vol.ALLOW_EXTRA,
)


async def async_setup(hass, config):
"""Set up the Hisense AEH-W4A1 integration."""
conf = config.get(DOMAIN)
hass.data[DOMAIN] = {}

if conf is not None:
devices = conf[CONF_IP_ADDRESS][:]
for device in devices:
try:
await AehW4a1(device).check()
except pyaehw4a1.exceptions.ConnectionError:
conf[CONF_IP_ADDRESS].remove(device)
_LOGGER.warning("Hisense AEH-W4A1 at %s not found", device)
if conf[CONF_IP_ADDRESS]:
hass.data[DOMAIN] = conf
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT},
)
)

return True


async def async_setup_entry(hass, entry):
"""Set up a config entry for Hisense AEH-W4A1."""
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, CLIMATE_DOMAIN)
)

return True


async def async_unload_entry(hass, entry):
"""Unload a config entry."""
return await hass.config_entries.async_forward_entry_unload(entry, CLIMATE_DOMAIN)
Loading

0 comments on commit d796053

Please sign in to comment.