├── hassio ├── CHANGELOG.md ├── icon.png ├── logo.png ├── README.md ├── config.json └── DOCS.md ├── aircon ├── __init__.py ├── error.py ├── config.py ├── app_mappings.py ├── control_value.py ├── mqtt_client.py ├── notifier.py ├── query_handlers.py ├── discovery.py ├── __main__.py ├── aircon.py └── properties.py ├── .style.yapf ├── repository.json ├── options.json ├── Dockerfile ├── docker-compose.yaml ├── new_version.sh ├── setup.py ├── run.sh ├── .gitignore ├── devicetypes └── deiger │ └── hisense-air-conditioner.src │ └── hisense-air-conditioner.groovy ├── README.md ├── CHANGELOG.md └── LICENSE /hassio/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ../CHANGELOG.md -------------------------------------------------------------------------------- /aircon/__init__.py: -------------------------------------------------------------------------------- 1 | from . import * 2 | __version__ = '0.3.17' 3 | -------------------------------------------------------------------------------- /hassio/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deiger/AirCon/HEAD/hassio/icon.png -------------------------------------------------------------------------------- /hassio/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deiger/AirCon/HEAD/hassio/logo.png -------------------------------------------------------------------------------- /.style.yapf: -------------------------------------------------------------------------------- 1 | [style] 2 | based_on_style=google 3 | column_limit=100 4 | indent_width=2 5 | -------------------------------------------------------------------------------- /repository.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Home Assistant Add-on: HiSense Air Conditioners", 3 | "url": "https://github.com/deiger/AirCon", 4 | "maintainer": "Dror Eiger " 5 | } 6 | -------------------------------------------------------------------------------- /aircon/error.py: -------------------------------------------------------------------------------- 1 | class Error(Exception): 2 | """Error class for AC handling.""" 3 | pass 4 | 5 | 6 | class KeyIdReplaced(Exception): 7 | """Error class for key id replacement""" 8 | 9 | def __init__(self, title, message): 10 | self.title = title 11 | self.message = message 12 | -------------------------------------------------------------------------------- /options.json: -------------------------------------------------------------------------------- 1 | { 2 | "app": [ 3 | { 4 | "username": "", 5 | "password": "", 6 | "code": "" 7 | } 8 | ], 9 | "log_level": "INFO", 10 | "mqtt_host": "core-mosquitto", 11 | "mqtt_port": 1883, 12 | "mqtt_user": "", 13 | "mqtt_pass": "", 14 | "port": 8888, 15 | "local_ip": "" 16 | } 17 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.10 2 | 3 | ARG BUILD_VERSION=latest 4 | LABEL io.hass.version="$BUILD_VERSION" io.hass.type="addon" io.hass.arch="armhf|armv7|aarch64|amd64|i386" 5 | 6 | COPY . /app 7 | WORKDIR /app 8 | 9 | RUN dpkg --add-architecture i386 && apt-get update && apt-get install -y --no-install-recommends jq 10 | RUN python setup.py install 11 | 12 | ENV PLATFORM=docker 13 | 14 | ENV CONFIG_DIR=/opt/hisense 15 | ENV OPTIONS_FILE=/data/options.json 16 | 17 | COPY run.sh / 18 | RUN chmod a+x /run.sh 19 | 20 | CMD [ "/run.sh" ] 21 | -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | copy_config: 4 | build: 5 | context: . 6 | command: > 7 | sh -c "cp -n ./options.json /config/" 8 | volumes: 9 | - /opt/hisense:/config 10 | hisense_ac: 11 | depends_on: 12 | - copy_config 13 | image: deiger/aircon:0.3.17 14 | container_name: hisense_ac 15 | healthcheck: 16 | disable: true 17 | environment: 18 | - CONFIG_DIR=/config 19 | - OPTIONS_FILE=/config/options.json 20 | network_mode: host 21 | volumes: 22 | - /opt/hisense:/config 23 | -------------------------------------------------------------------------------- /hassio/README.md: -------------------------------------------------------------------------------- 1 | # Home Assistant Add-on: Hisense Air Conditioner 2 | 3 | ![Supports aarch64 Architecture][aarch64-shield] ![Supports amd64 Architecture][amd64-shield] ![Supports armhf Architecture][armhf-shield] ![Supports armv7 Architecture][armv7-shield] ![Supports i386 Architecture][i386-shield] 4 | 5 | ## About 6 | 7 | Use this add-on to add support for Hisense Air Conditioners. See [here](https://github.com/deiger/AirCon) for more details. 8 | 9 | [aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg 10 | [amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg 11 | [armhf-shield]: https://img.shields.io/badge/armhf-yes-green.svg 12 | [armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg 13 | [i386-shield]: https://img.shields.io/badge/i386-yes-green.svg 14 | -------------------------------------------------------------------------------- /new_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | git pull 5 | 6 | OLD_VERSION=`git describe --abbrev=0` 7 | NEW_VERSION=$1 8 | if [ -z "$2" ]; then 9 | NEW_VERSION_MSG=v$1 10 | else 11 | NEW_VERSION_MSG=$2 12 | fi 13 | 14 | git tag -a $NEW_VERSION -m "$NEW_VERSION_MSG" 15 | auto-changelog 16 | 17 | for f in aircon/__init__.py hassio/config.json docker-compose.yaml; do 18 | sed -i "" -e "s/$OLD_VERSION/$NEW_VERSION/" $f 19 | done 20 | 21 | git commit -a -m $NEW_VERSION 22 | git tag -d $NEW_VERSION 23 | git tag -a $NEW_VERSION -m "$NEW_VERSION_MSG" 24 | docker buildx rm --all-inactive --force 25 | docker buildx create --name multiarch --driver docker-container --use || true 26 | docker buildx build --platform linux/arm/v7,linux/arm64,linux/amd64,linux/386 -t deiger/aircon:$NEW_VERSION --push . 27 | git push 28 | git push --tags 29 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import aircon 2 | import setuptools 3 | from os import path 4 | 5 | this_directory = path.abspath(path.dirname(__file__)) 6 | 7 | with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f: 8 | long_description = f.read() 9 | 10 | setuptools.setup( 11 | name='aircon', 12 | version=aircon.__version__, 13 | description='Interface for controlling Air Conditioners, e.g. with HiSense modules.', 14 | long_description=long_description, 15 | long_description_content_type='text/markdown', 16 | url='https://github.com/deiger/AirCon', 17 | author='Dror Eiger', 18 | author_email='droreiger@gmail.com', 19 | license='GPL 3.0', 20 | packages=setuptools.find_packages(), 21 | install_requires=[ 22 | 'aiohttp==3.10.11', 'dataclasses_json', 'pycryptodome', 'paho-mqtt==1.6.1', 'tenacity', 23 | 'get-mac', 'retry' 24 | ], 25 | classifiers=[ 26 | 'Programming Language :: Python :: 3', 27 | 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', 28 | 'Operating System :: OS Independent', 29 | 'Topic :: Home Automation', 30 | ], 31 | ) 32 | -------------------------------------------------------------------------------- /hassio/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "HiSense Air Conditioners", 3 | "version": "0.3.17", 4 | "slug": "hisense_ac", 5 | "description": "Interface for controlling Air Conditioners, e.g. with HiSense modules.", 6 | "url": "https://github.com/deiger/AirCon", 7 | "image": "deiger/aircon", 8 | "arch": ["armhf", "armv7", "aarch64", "amd64", "i386"], 9 | "startup": "application", 10 | "boot": "auto", 11 | "host_network": true, 12 | "map": ["config:rw"], 13 | "discovery": ["mqtt"], 14 | "services": ["mqtt:want"], 15 | "environment": { 16 | "CONFIG_DIR": "/config/hisense", 17 | "OPTIONS_FILE": "/data/options.json" 18 | }, 19 | "options": { 20 | "log_level": "INFO", 21 | "mqtt_host": "core-mosquitto", 22 | "mqtt_port": 1883, 23 | "mqtt_user": null, 24 | "mqtt_pass": null, 25 | "port": null 26 | }, 27 | "schema": { 28 | "app": [ 29 | { 30 | "username": "str", 31 | "password": "str", 32 | "code": "str" 33 | } 34 | ], 35 | "log_level": "list(CRITICAL|ERROR|WARNING|INFO|DEBUG)?", 36 | "mqtt_host": "str?", 37 | "mqtt_port": "port?", 38 | "mqtt_user": "str?", 39 | "mqtt_pass": "str?", 40 | "port": "port", 41 | "local_ip": "str?" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hassio/DOCS.md: -------------------------------------------------------------------------------- 1 | # Home Assistant Add-on: HiSense Air Conditioners 2 | 3 | ## Prerequisites 4 | 5 | 1. Air Conditioner with HiSense AEH-W4B1 or AEH-W4E1 WiFi module installed, or 6 | Fujitsu FGLair. 7 | These include A/Cs by multiple brands, including Beko, Westinghouse, Winia, 8 | Tornado, York and more. 9 | 1. An [MQTT broker](https://www.home-assistant.io/docs/mqtt/broker/) installed, 10 | whether it is Mosquitto or the default Home Assistant MQTT broker. Please 11 | make sure to install and set up that add-on before continuing. 12 | 13 | # Configuration 14 | 15 | 1. Find your application code from the list 16 | [here](https://github.com/deiger/AirCon#prerequisites). 17 | 1. Set the configuration as follows: 18 | ```yaml 19 | app: 20 | - username: App user name 21 | password: App password 22 | code: App code 23 | log_level: One of DEBUG, INFO, WARNING, ERROR, CRITICAL. Default is INFO. 24 | mqtt_host: IP address (or localhost). 25 | mqtt_user: User name for MQTT server. Remove if no authentication is used. 26 | mqtt_pass: Password for MQTT server. Remove if no authentication is used. 27 | port: Port number for the web server. 28 | ``` 29 | * Note: _If multiple apps are used, add them as separate values under `app`_ 30 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | PORT=$(jq -r '.port // 8888' $OPTIONS_FILE) 5 | TYPE=$(jq -r '.type // "ac"' $OPTIONS_FILE) 6 | LOG_LEVEL=$(jq -r '.log_level | ascii_upcase // "WARNING"' $OPTIONS_FILE) 7 | MQTT_HOST=$(jq -r '.mqtt_host // ""' $OPTIONS_FILE) 8 | MQTT_PORT=$(jq -r '.mqtt_port // 1883' $OPTIONS_FILE) 9 | MQTT_USER=$(jq -r 'if (.mqtt_user and .mqtt_pass) then (.mqtt_user + ":" + .mqtt_pass) else "" end' $OPTIONS_FILE) 10 | APPS=$(jq -r '.app | length // 0' $OPTIONS_FILE) 11 | LOCAL_IP=$(jq -r 'if (.local_ip) then (.local_ip) else "" end' $OPTIONS_FILE) 12 | 13 | mkdir -p $CONFIG_DIR 14 | if [ -z "$(find $CONFIG_DIR -maxdepth 1 -type f -name "config_*.json")" ]; then 15 | rm -f config_*.json 16 | for i in $(seq 0 $(($APPS-1))); do 17 | CODE=$(jq -r '.app['$i'].code' $OPTIONS_FILE) 18 | USERNAME=$(jq -r '.app['$i'].username' $OPTIONS_FILE) 19 | PASSWORD=$(jq -r '.app['$i'].password' $OPTIONS_FILE) 20 | python -m aircon discovery $CODE $USERNAME $PASSWORD 21 | done 22 | mv config_*.json $CONFIG_DIR/ 23 | fi 24 | configs= 25 | for i in $(find $CONFIG_DIR -maxdepth 1 -type f -name "config_*.json" -exec basename {} \;) 26 | do configs="$configs --config $CONFIG_DIR/$i --type $TYPE" 27 | done 28 | python -m aircon --log_level $LOG_LEVEL run --port $PORT --mqtt_host "$MQTT_HOST" --mqtt_port $MQTT_PORT --mqtt_user "$MQTT_USER" --local_ip "$LOCAL_IP" $configs 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | .vscode/* 10 | 11 | # Distribution / packaging 12 | .Python 13 | env/ 14 | build/ 15 | develop-eggs/ 16 | dist/ 17 | downloads/ 18 | eggs/ 19 | .eggs/ 20 | lib/ 21 | lib64/ 22 | parts/ 23 | sdist/ 24 | var/ 25 | wheels/ 26 | *.egg-info/ 27 | .installed.cfg 28 | *.egg 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | .hypothesis/ 50 | 51 | # Translations 52 | *.mo 53 | *.pot 54 | 55 | # Django stuff: 56 | *.log 57 | local_settings.py 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # dotenv 85 | .env 86 | 87 | # virtualenv 88 | .venv 89 | venv/ 90 | ENV/ 91 | 92 | # Spyder project settings 93 | .spyderproject 94 | .spyproject 95 | 96 | # Rope project settings 97 | .ropeproject 98 | 99 | # mkdocs documentation 100 | /site 101 | 102 | # mypy 103 | .mypy_cache/ 104 | -------------------------------------------------------------------------------- /aircon/config.py: -------------------------------------------------------------------------------- 1 | from Crypto.Cipher import AES 2 | from dataclasses import dataclass 3 | import hmac 4 | import random 5 | import string 6 | import time 7 | 8 | from .error import KeyIdReplaced 9 | 10 | 11 | @dataclass 12 | class LanConfig: 13 | lanip_key: str 14 | lanip_key_id: int 15 | random_1: str 16 | time_1: int 17 | random_2: str 18 | time_2: int 19 | 20 | 21 | @dataclass 22 | class Encryption: 23 | sign_key: bytes 24 | crypto_key: bytes 25 | iv_seed: bytes 26 | cipher: AES 27 | 28 | def __init__(self, lanip_key: bytes, msg: bytes): 29 | self.sign_key = self._build_key(lanip_key, msg + b'0') 30 | self.crypto_key = self._build_key(lanip_key, msg + b'1') 31 | self.iv_seed = self._build_key(lanip_key, msg + b'2')[:AES.block_size] 32 | self.cipher = AES.new(self.crypto_key, AES.MODE_CBC, self.iv_seed) 33 | 34 | @classmethod 35 | def _build_key(cls, lanip_key: bytes, msg: bytes) -> bytes: 36 | return cls.hmac_digest(lanip_key, cls.hmac_digest(lanip_key, msg) + msg) 37 | 38 | @staticmethod 39 | def hmac_digest(key: bytes, msg: bytes) -> bytes: 40 | return hmac.digest(key, msg, 'sha256') 41 | 42 | 43 | @dataclass 44 | class Config: 45 | _lan_config: LanConfig 46 | app: Encryption 47 | dev: Encryption 48 | 49 | def __init__(self, lanip_key: str, lanip_key_id: int): 50 | self._lan_config = LanConfig(lanip_key, lanip_key_id, '', 0, '', 0) 51 | self._update_encryption() 52 | 53 | def update(self, key: dict): 54 | """Updates the stored lan config, and encryption data.""" 55 | self._lan_config.random_1 = key['random_1'] 56 | self._lan_config.time_1 = key['time_1'] 57 | if key['key_id'] != self._lan_config.lanip_key_id: 58 | raise KeyIdReplaced( 59 | 'The key_id has been replaced!!', 60 | 'Old ID was {}; new ID is {}.'.format(self._lan_config.lanip_key_id, key['key_id'])) 61 | self._lan_config.random_2 = ''.join(random.choices(string.ascii_letters + string.digits, k=16)) 62 | self._lan_config.time_2 = time.monotonic_ns() % 2**40 63 | self._update_encryption() 64 | return {'random_2': self._lan_config.random_2, 'time_2': self._lan_config.time_2} 65 | 66 | def _update_encryption(self): 67 | lanip_key = self._lan_config.lanip_key.encode('utf-8') 68 | random_1 = self._lan_config.random_1.encode('utf-8') 69 | random_2 = self._lan_config.random_2.encode('utf-8') 70 | time_1 = str(self._lan_config.time_1).encode('utf-8') 71 | time_2 = str(self._lan_config.time_2).encode('utf-8') 72 | self.app = Encryption(lanip_key, random_1 + random_2 + time_1 + time_2) 73 | self.dev = Encryption(lanip_key, random_2 + random_1 + time_2 + time_1) 74 | -------------------------------------------------------------------------------- /aircon/app_mappings.py: -------------------------------------------------------------------------------- 1 | AYLA_USER_SERVERS = { 2 | 'us': 'user-field.aylanetworks.com', 3 | 'eu': 'user-field-eu.aylanetworks.com', 4 | 'cn': 'user-field.ayla.com.cn', 5 | } 6 | AYLA_DEVICES_SERVERS = { 7 | 'us': 'ads-field.aylanetworks.com', 8 | 'eu': 'ads-eu.aylanetworks.com', 9 | 'cn': 'ads-field.ayla.com.cn', 10 | } 11 | SECRET_MAP = { 12 | 'oem-us': 13 | b'\x1dgAPT\xd1\xa9\xec\xe2\xa2\x01\x19\xc0\x03X\x13j\xfc\xb5\x91', 14 | 'mid-us': 15 | b'\xdeCx\xbe\x0cq8\x0b\x99\xb4Z\x93>\xfc\xcc\x9ag\x98\xf8\x14', 16 | 'tornado-us': 17 | b'\x87O\xf2.&;X\xfb\xf6L\xfdRq\'\x0f\t6\x0c\xfd)', 18 | 'wwh-us': 19 | b'(\xcb9w\xc5\xc9\xb7\xab{*k8T!Yb\xaa\xcf\xd0\x85', 20 | 'winia-us': 21 | b'\xeb_\xce\xb2\xc6\xff`\xa9\xfa\xa8r\x1c\x0bH\xf8\xe27\xa7U\xec', 22 | 'york-us': 23 | b'\xc6A\x7fHyV<\xb2\xa2\xde<\x1f{c\xa9\rt\x9fy\xef', 24 | 'beko-eu': 25 | b'\xa9C\n\xdb\xf7+\x01\xe2X\ne\x85\x06\x89\xaa\x88ZP+\x07>~s{\xd3\x1f\x05\x91&\x8c\x81\x84&\xe11\xef=s"*\xa4', 26 | 'oem-eu': 27 | b'a\x1ez\xf5\xc4\x0f\x18~\xe5\xeb\xb1\x9f\xe4\xf5&B\xfe#\x88\xcb>\x06O,y\xc1\x06c\x9d\x99J\xc2x\xac\xeb\x82\x93\xe5\r\x89d', 28 | 'mid-eu': 29 | b'\x05$\xe6\xecW\xa3\xd1B\xa0\x84\xab*\xf0\x04\x80\xce\xae\xe5`\xc4>w\xf8\xc4\xf3X\xf6<\xd2\xd2I\x14!\xd0\x98\xed\xf2\xab\xae\xc6\x03', 30 | 'haxxair': 31 | b'\xd8\xaf\x89--\x00\xabI\x93\x83j\xab\x9acX\xac^\x90f;', 32 | 'fglair-cn': 33 | b'\xcd\xec\xe0\xed\x8e\xb4b\x90/\xcbq\xcf\xc3\x1b\xd6.wx:\x1e', 34 | 'fglair-eu': 35 | b'\x82\x91[T\x14h\x88\x9f\x04\xdd\x05\x89\xf9\x04T,\xb2\xf7\x8fu', 36 | 'fglair-us': 37 | b'U\xbf\x0c@\xbf\xe5\x16&\x10\xec2\xa37G\x82\x15|\xe7)\x91', 38 | 'field-us': 39 | b'\xc8b\x08\xfa\xce8\xf8\xf1\x81\xa5\x81\x8fX\xb4\x80\xc0\xdc\xf5\ny', 40 | 'huihe-us': 41 | b'\xa2\xbcZ3\xbch\xfa7.`\xbc\xef0\xa3p\xa1\xf0\xaf\xf4\xd4', 42 | 'denali-us': 43 | b'\xf1\'\xb0K \xdbZ\xd84;\xeb\x02\xa2\xee\x008\xda\x95\xfd\x93', 44 | 'hisense-eu': 45 | b'\xc0\xedK,\xff+X\xfa\xf6p\x87\xaa\xbcV\x88\xfbI\xb4\xcf\xad', 46 | 'hisense-us': 47 | b'x\x04\xdf\xef6\x08\x8e\x06\n\x97\xfc\xed4m\xd8\xc7\xa3=\xce\x9f', 48 | 'hismart-eu': 49 | b'0\x07\xe9\x04a\xa6e\xc4\x1c\x08+"\r\x84w\x91\x8f\xa8)\x98', 50 | 'hismart-us': 51 | b'\xd6+\x1f\xb0b\t\x19G\x87\x8c\xaak\xd0\xf8y\xf5\x933\xafp', 52 | } 53 | SECRET_ID_MAP = { 54 | 'haxxair': 'HAXXAIR', 55 | 'field-us': 'pactera-field-f624d97f-us', 56 | 'fglair-cn': 'FGLairField-cn', 57 | 'fglair-eu': 'FGLair-eu', 58 | 'fglair-us': 'CJIOSP', 59 | 'huihe-us': 'huihe-d70b5148-field-us', 60 | 'denali-us': 'DenaliAire', 61 | 'hisense-eu': 'Hisense', 62 | 'hisense-us': 'APP1', 63 | 'hismart-eu': 'Hismart', 64 | 'hismart-us': 'App1', 65 | } 66 | SECRET_ID_EXTRA_MAP = { 67 | 'denali-us': 'iA', 68 | 'hisense-eu': 'mw', 69 | 'hisense-us': 'pg', 70 | 'hismart-eu': 'fA', 71 | 'hismart-us': 'Lg', 72 | } 73 | # Most ACs are using Fahrenheit in their API. These do not: 74 | CELSIUS_BASED_APPS = {'fglair-eu', 'hisense-eu', 'hismart-eu', 'hismart-us'} 75 | -------------------------------------------------------------------------------- /aircon/control_value.py: -------------------------------------------------------------------------------- 1 | from .properties import (AcWorkMode, AirFlow, Economy, FanSpeed, FastColdHeat, Quiet, Power, 2 | TemperatureUnit) 3 | 4 | 5 | def clear_up_change_flags(control: int) -> int: 6 | return control & 2868817502 7 | 8 | 9 | def get_fan_speed(control: int) -> FanSpeed: 10 | int_val = (control >> 1) & 15 11 | return FanSpeed(int_val) 12 | 13 | 14 | def set_fan_speed(control: int, value: FanSpeed) -> None: 15 | int_val = value.value 16 | return (control & ~31) | ((int_val << 1) | 1) 17 | 18 | 19 | def get_power(control: int) -> Power: 20 | int_val = (control >> 6) & 1 21 | return Power(int_val) 22 | 23 | 24 | def set_power(control: int, value: Power) -> None: 25 | int_val = value.value 26 | return (control & ~(3 << 5)) | (((int_val << 1) | 1) << 5) 27 | 28 | 29 | def get_work_mode(control: int) -> AcWorkMode: 30 | int_val = (control >> 9) & 7 31 | return AcWorkMode(int_val) 32 | 33 | 34 | def set_work_mode(control: int, value: AcWorkMode) -> None: 35 | int_val = value.value 36 | return (control & ~(15 << 8)) | (((int_val << 1) | 1) << 8) 37 | 38 | 39 | def get_heat_cold(control: int) -> FastColdHeat: 40 | int_val = (control >> 13) & 1 41 | return FastColdHeat(int_val) 42 | 43 | 44 | def set_heat_cold(control: int, value: FastColdHeat) -> None: 45 | int_val = value.value 46 | return (control & ~(3 << 12)) | (((int_val << 1) | 1) << 12) 47 | 48 | 49 | def get_eco(control: int) -> Economy: 50 | int_val = (control >> 15) & 1 51 | return Economy(int_val) 52 | 53 | 54 | def set_eco(control: int, value: Economy) -> None: 55 | int_val = value.value 56 | return (control & ~(3 << 14)) | (((int_val << 1) | 1) << 14) 57 | 58 | 59 | def get_temp(control: int) -> int: 60 | return (control >> 17) & 63 61 | 62 | 63 | def set_temp(control: int, value: int) -> None: 64 | return (control & ~(127 << 16)) | (((value << 1) | 1) << 16) 65 | 66 | 67 | def get_fan_power(control: int) -> AirFlow: 68 | int_val = (control >> 25) & 1 69 | return AirFlow(int_val) 70 | 71 | 72 | def set_fan_power(control: int, value: AirFlow) -> None: 73 | int_val = value.value 74 | return (control & ~(3 << 24)) | (((int_val << 1) | 1) << 24) 75 | 76 | 77 | def get_fan_lr(control: int) -> AirFlow: 78 | int_val = (control >> 27) & 1 79 | return AirFlow(int_val) 80 | 81 | 82 | def set_fan_lr(control: int, value: AirFlow) -> None: 83 | int_val = value.value 84 | return (control & ~(3 << 26)) | (((int_val << 1) | 1) << 26) 85 | 86 | 87 | def get_fan_mute(control: int) -> Quiet: 88 | int_val = (control >> 29) & 1 89 | return Quiet(int_val) 90 | 91 | 92 | def set_fan_mute(control: int, value: Quiet) -> None: 93 | int_val = value.value 94 | return (control & ~(3 << 28)) | (((int_val << 1) | 1) << 28) 95 | 96 | 97 | def get_temptype(control: int) -> TemperatureUnit: 98 | int_val = (control >> 31) & 1 99 | return TemperatureUnit(int_val) 100 | 101 | 102 | def set_temptype(control: int, value: TemperatureUnit) -> None: 103 | int_val = value.value 104 | return (control & ~(3 << 30)) | (((int_val << 1) | 1) << 30) 105 | -------------------------------------------------------------------------------- /aircon/mqtt_client.py: -------------------------------------------------------------------------------- 1 | from dataclasses import fields 2 | import enum 3 | import logging 4 | import paho.mqtt.client as mqtt 5 | 6 | from .aircon import Device 7 | from .properties import AcWorkMode, FglOperationMode 8 | 9 | 10 | class MqttClient(mqtt.Client): 11 | 12 | def __init__(self, client_id: str, mqtt_topics: dict, devices: [Device]): 13 | super().__init__(client_id=client_id, clean_session=True) 14 | self._mqtt_topics = mqtt_topics 15 | self._devices = devices 16 | 17 | self.on_connect = self.mqtt_on_connect 18 | self.on_message = self.mqtt_on_message 19 | 20 | def mqtt_on_connect(self, client: mqtt.Client, userdata, flags, rc): 21 | for device in self._devices: 22 | client.subscribe([(self._mqtt_topics['sub'].format(device.mac_address, data_field.name), 0) 23 | for data_field in fields(device.get_all_properties())]) 24 | # Subscribe to subscription updates. 25 | client.subscribe('$SYS/broker/log/M/subscribe/#') 26 | 27 | # Publish current status of all properties for available devices. 28 | for device in self._devices: 29 | if device.available: 30 | for prop_name in fields(device.get_all_properties()): 31 | self.mqtt_publish_update(device.mac_address, 32 | prop_name, 33 | device.get_property(prop_name), 34 | retain=False) 35 | 36 | def mqtt_on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): 37 | logging.info('MQTT message Topic: {}, Payload {}'.format(message.topic, message.payload)) 38 | if message.topic.startswith('$SYS/broker/log/M/subscribe'): 39 | return self.mqtt_on_subscribe(message.payload) 40 | mac_address = message.topic.rsplit('/', 3)[1] 41 | prop_name = message.topic.rsplit('/', 3)[2] 42 | payload = message.payload.decode('utf-8') 43 | if prop_name == 't_work_mode': 44 | if payload == 'fan_only': 45 | payload = 'FAN' 46 | 47 | for device in self._devices: 48 | if device.mac_address != mac_address: 49 | continue 50 | chosen_device = device 51 | 52 | try: 53 | chosen_device.queue_command(prop_name, payload.upper()) 54 | except Exception: 55 | logging.exception('Failed to parse value {} for property {}'.format( 56 | payload.upper(), prop_name)) 57 | 58 | def mqtt_on_subscribe(self, payload: bytes): 59 | # The last segment in the space delimited string is the topic. 60 | topic = payload.decode('utf-8').rsplit(' ', 1)[-1] 61 | if topic not in self._mqtt_topics['pub']: 62 | return 63 | mac_address = topic.rsplit('/', 3)[1] 64 | prop_name = topic.rsplit('/', 3)[2] 65 | 66 | for device in self._devices: 67 | if device.mac_address != mac_address: 68 | continue 69 | chosen_device = device 70 | 71 | self.mqtt_publish_update(chosen_device.mac_address, 72 | prop_name, 73 | chosen_device.get_property(prop_name), 74 | retain=False) 75 | 76 | def mqtt_publish_update(self, 77 | mac_address: str, 78 | property_name: str, 79 | value, 80 | retain: bool = False) -> None: 81 | if isinstance(value, enum.Enum): 82 | payload = 'fan_only' if (value is AcWorkMode.FAN or 83 | value is FglOperationMode.FAN) else value.name.lower() 84 | else: 85 | payload = str(value) 86 | self.publish(self._mqtt_topics['pub'].format(mac_address, property_name), 87 | payload=payload.encode('utf-8'), 88 | retain=retain) 89 | -------------------------------------------------------------------------------- /aircon/notifier.py: -------------------------------------------------------------------------------- 1 | import aiohttp 2 | import asyncio 3 | import concurrent 4 | from dataclasses import dataclass 5 | from http import HTTPStatus 6 | import json 7 | import logging 8 | import socket 9 | import sys 10 | from tenacity import retry, retry_if_exception_type, wait_exponential, stop_after_attempt 11 | import time 12 | import threading 13 | 14 | from .aircon import Device 15 | 16 | if sys.version_info < (3, 8): 17 | TimeoutError = concurrent.futures.TimeoutError 18 | else: 19 | TimeoutError = asyncio.exceptions.TimeoutError 20 | 21 | 22 | @dataclass 23 | class _NotifyConfiguration: 24 | device: Device 25 | headers: dict 26 | last_timestamp: int 27 | 28 | 29 | def _run_after_failure(retry_state): 30 | config = retry_state.kwargs['config'] 31 | config.device.available = False 32 | return 0 33 | 34 | 35 | class Notifier: 36 | _KEEP_ALIVE_INTERVAL = 10.0 37 | _TIME_TO_HANDLE_REQUESTS = 100e-3 38 | 39 | def __init__(self, port: int, local_ip: str): 40 | self._configurations = [] 41 | self._condition = asyncio.Condition() 42 | 43 | self._running = False 44 | 45 | local_ip = local_ip or self._get_local_ip() 46 | self._json = {'local_reg': {'ip': local_ip, 'notify': 0, 'port': port, 'uri': '/local_lan'}} 47 | 48 | def _get_local_ip(self): 49 | sock = None 50 | try: 51 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 52 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) 53 | sock.connect(('10.255.255.255', 1)) 54 | return sock.getsockname()[0] 55 | finally: 56 | if sock: 57 | sock.close() 58 | 59 | def register_device(self, device: Device): 60 | if device not in (conf.device for conf in self._configurations): 61 | headers = { 62 | 'Accept': 'application/json', 63 | 'Connection': 'keep-alive', 64 | 'Content-Type': 'application/json', 65 | 'Host': device.ip_address, 66 | 'Accept-Encoding': 'gzip' 67 | } 68 | self._configurations.append(_NotifyConfiguration(device, headers, 0)) 69 | 70 | async def _notify(self): 71 | async with self._condition: 72 | self._condition.notify_all() 73 | 74 | def notify(self): 75 | loop = asyncio.get_event_loop() 76 | asyncio.run_coroutine_threadsafe(self._notify(), loop) 77 | 78 | async def start(self, session: aiohttp.ClientSession): 79 | self._running = True 80 | async with self._condition: 81 | while self._running: 82 | queue_sizes = await asyncio.gather(*(self._perform_request(session=session, config=config) 83 | for config in self._configurations)) 84 | if max(queue_sizes) <= 1: 85 | logging.debug('[KeepAlive] Waiting for notification or timeout') 86 | try: 87 | await asyncio.wait_for(self._condition.wait(), timeout=self._KEEP_ALIVE_INTERVAL) 88 | except TimeoutError: 89 | pass 90 | else: 91 | # give some time to clean up the queues 92 | await asyncio.sleep(self._TIME_TO_HANDLE_REQUESTS) 93 | 94 | async def stop(self): 95 | self._running = False 96 | await self._notify() 97 | 98 | @retry(retry=retry_if_exception_type(ConnectionError), 99 | retry_error_callback=_run_after_failure, 100 | wait=wait_exponential(exp_base=1.6, max=10), 101 | stop=stop_after_attempt(6)) 102 | async def _perform_request(self, session: aiohttp.ClientSession, 103 | config: _NotifyConfiguration) -> int: 104 | now = time.time() 105 | queue_size = config.device.commands_queue.qsize() 106 | if (queue_size == 0 or 107 | not config.device.available) and now - config.last_timestamp < self._KEEP_ALIVE_INTERVAL: 108 | return 0 109 | method = 'PUT' if config.device.available else 'POST' 110 | self._json['local_reg']['notify'] = int(config.device.commands_queue.qsize() > 0) 111 | url = f'http://{config.device.ip_address}/local_reg.json' 112 | logging.debug(f'[KeepAlive] Sending {method} {url} {json.dumps(self._json)}') 113 | try: 114 | async with session.request(method, url, json=self._json, headers=config.headers) as resp: 115 | if resp.status != HTTPStatus.ACCEPTED.value: 116 | resp_data = await resp.text() 117 | logging.error(f'[KeepAlive] Sending local_reg failed: {resp.status}, {resp_data}') 118 | raise ConnectionError(f'Sending local_reg failed: {resp.status}, {resp_data}') 119 | except (aiohttp.client_exceptions.ClientConnectorError, 120 | aiohttp.client_exceptions.ClientConnectionError) as e: 121 | logging.error(f'Failed to connect to {config.device.ip_address}, maybe it is offline?') 122 | raise ConnectionError( 123 | f'Failed to connect to {config.device.ip_address}, maybe it is offline?') 124 | config.last_timestamp = now 125 | config.device.available = True 126 | return queue_size 127 | -------------------------------------------------------------------------------- /aircon/query_handlers.py: -------------------------------------------------------------------------------- 1 | from aiohttp import web 2 | import base64 3 | from Crypto.Cipher import AES 4 | from http import HTTPStatus 5 | import json 6 | import math 7 | import logging 8 | import queue 9 | import random 10 | import string 11 | import time 12 | from typing import Callable 13 | 14 | from .config import Config, Encryption 15 | from .aircon import Device 16 | from .error import Error, KeyIdReplaced 17 | 18 | 19 | class QueryHandlers: 20 | 21 | def __init__(self, devices: [Device]): 22 | self._devices_map = {} 23 | for device in devices: 24 | self._devices_map[device.ip_address] = device 25 | 26 | async def key_exchange_handler(self, request: web.Request) -> web.Response: 27 | """Handles a key exchange. 28 | Accepts the AC's random and time and pass its own. 29 | Note that a key encryption component is the lanip_key, mapped to the 30 | lanip_key_id provided by the AC. This secret part is provided by HiSense 31 | server. Fortunately the lanip_key_id (and lanip_key) are static for a given 32 | AC. 33 | """ 34 | updated_keys = {} 35 | post_data = await request.text() 36 | data = json.loads(post_data) 37 | try: 38 | key = data['key_exchange'] 39 | if key['ver'] != 1 or key['proto'] != 1 or key.get('sec'): 40 | logging.error(f'Invalid key exchange: {data}') 41 | raise web.HTTPBadRequest(reason=f'Invalid key exchange: {data}') 42 | updated_keys = self._devices_map[request.remote].update_key(key) 43 | except KeyIdReplaced as e: 44 | logging.error(f'{e.title}\n{e.message}') 45 | return web.Response(status=HTTPStatus.NOT_FOUND.value, reason=f'{e.title}\n{e.message}') 46 | return web.json_response(updated_keys) 47 | 48 | async def command_handler(self, request: web.Request) -> web.Response: 49 | """Handles a command request. 50 | Request arrives from the AC. takes a command from the queue, 51 | builds the JSON, encrypts and signs it, and sends it to the AC. 52 | """ 53 | command = {} 54 | device = self._devices_map[request.remote] 55 | command['seq_no'] = device.get_command_seq_no() 56 | try: 57 | command_entry = device.commands_queue.get_nowait() 58 | command['data'], property_updater = command_entry.command, command_entry.updater 59 | except queue.Empty: 60 | command['data'], property_updater = {}, None 61 | if property_updater: 62 | property_updater() #TODO: should be async as well? 63 | return web.json_response(self._encrypt_and_sign(device, command)) 64 | 65 | async def property_update_handler(self, request: web.Request) -> web.Response: 66 | """Handles a property update request. 67 | Decrypts, validates, and pushes the value into the local properties store. 68 | """ 69 | device = self._devices_map[request.remote] 70 | post_data = await request.text() 71 | data = json.loads(post_data) 72 | try: 73 | update = self._decrypt_and_validate(device, data) 74 | except Error: 75 | logging.exception('Failed to parse property.') 76 | return web.Response(status=HTTPStatus.BAD_REQUEST.value, reason='Failed to parse property.') 77 | response = web.Response() 78 | if not device.is_update_valid(update['seq_no']): 79 | return response 80 | try: 81 | if not update['data']: 82 | logging.info('Unsupported update message = {}'.format(update['seq_no'])) 83 | return response 84 | name = update['data']['name'] 85 | # Fix A/C typos. 86 | if name == 'f_votage': 87 | name = 'f_voltage' 88 | data_type = device.get_property_type(name) 89 | value = data_type(update['data']['value']) 90 | device.update_property(name, value) 91 | except Exception as ex: 92 | logging.error('Failed to handle {}. Exception = {}'.format(update, ex)) 93 | #TODO: Should return internal error? 94 | return response 95 | 96 | async def get_status_handler(self, request: web.Request) -> web.Response: 97 | """Handles get status request (by a smart home hub). 98 | Returns the current internally stored state of the AC. 99 | """ 100 | devices = [] 101 | for device in self._devices_map.values(): 102 | if 'device_ip' in request.query.keys() and device.ip_address != request.query['device_ip']: 103 | continue 104 | devices.append({'ip': device.ip_address, 'props': device.get_all_properties().to_dict()}) 105 | return web.json_response({'devices': devices}) 106 | 107 | async def queue_command_handler(self, request: web.Request) -> web.Response: 108 | """Handles queue command request (by a smart home hub). 109 | """ 110 | device = self._devices_map.get(request.query.get('device_ip')) 111 | if not device: 112 | if len(self._devices_map) == 1: 113 | device = list(self._devices_map.values())[0] 114 | else: 115 | raise web.HTTPBadRequest(reason=f'Device "{request.query.get("device_ip")}" not found.') 116 | try: 117 | device.queue_command(request.query['property'], request.query['value']) 118 | except Exception as ex: 119 | logging.exception('Failed to queue command.') 120 | raise web.HTTPBadRequest(f'Failed to queue command:\n{ex!r}') 121 | return web.json_response({'queued_commands': device.commands_queue.qsize()}) 122 | 123 | def _encrypt_and_sign(self, device: Device, data: dict) -> dict: 124 | text = json.dumps(data) 125 | logging.debug('Encrypting: {}'.format(text)) 126 | text = text.encode('utf-8') 127 | encryption = device.get_app_encryption() 128 | return { 129 | "enc": base64.b64encode(encryption.cipher.encrypt(self.pad(text))).decode('utf-8'), 130 | "sign": base64.b64encode(Encryption.hmac_digest(encryption.sign_key, text)).decode('utf-8') 131 | } 132 | 133 | def _decrypt_and_validate(self, device: Device, data: dict) -> dict: 134 | encryption = device.get_dev_encryption() 135 | text = self.unpad(encryption.cipher.decrypt(base64.b64decode(data['enc']))) 136 | sign = base64.b64encode(Encryption.hmac_digest(encryption.sign_key, text)).decode('utf-8') 137 | if sign != data['sign']: 138 | raise Error(f'Invalid signature for:\n{text.decode("utf-8")}!') 139 | logging.info('Decrypted: %s', text.decode('utf-8')) 140 | try: 141 | return json.loads(text.decode('utf-8')) 142 | except Exception as ex: 143 | raise Error(f'Failed to decode message, {ex!r}:\n{text.decode("utf-8")}') 144 | 145 | @staticmethod 146 | def pad(data: bytes): 147 | """Zero padding for AES data encryption (non standard).""" 148 | new_size = math.ceil(len(data) / AES.block_size) * AES.block_size 149 | return data.ljust(new_size, bytes([0])) 150 | 151 | @staticmethod 152 | def unpad(data: bytes): 153 | """Remove Zero padding for AES data encryption (non standard).""" 154 | return data.rstrip(bytes([0])) 155 | -------------------------------------------------------------------------------- /aircon/discovery.py: -------------------------------------------------------------------------------- 1 | import aiohttp 2 | import base64 3 | from getmac import get_mac_address 4 | from http import HTTPStatus 5 | import json 6 | import logging 7 | import ssl 8 | import sys 9 | 10 | from .app_mappings import * 11 | 12 | _USER_AGENT = 'Dalvik/2.1.0 (Linux; U; Android 9.0; SM-G850F Build/LRX22G)' 13 | 14 | 15 | async def _sign_in(user: str, passwd: str, user_server: str, app_id: str, app_secret: str, 16 | session: aiohttp.ClientSession, ssl_context: ssl.SSLContext): 17 | query = { 18 | 'user': { 19 | 'email': user, 20 | 'password': passwd, 21 | 'application': { 22 | 'app_id': app_id, 23 | 'app_secret': app_secret 24 | } 25 | } 26 | } 27 | headers = { 28 | 'Accept': 'application/json', 29 | 'Connection': 'Keep-Alive', 30 | 'Authorization': 'none', 31 | 'Content-Type': 'application/json', 32 | 'User-Agent': _USER_AGENT, 33 | 'Host': user_server, 34 | 'Accept-Encoding': 'gzip' 35 | } 36 | logging.debug('POST /users/sign_in.json, body=%r, headers=%r', json.dumps(query), headers) 37 | async with session.request('POST', 38 | f'https://{user_server}/users/sign_in.json', 39 | json=query, 40 | headers=headers, 41 | ssl=ssl_context) as resp: 42 | if resp.status != HTTPStatus.OK.value: 43 | logging.error('Failed to login to Hisense server:\nStatus %d: %r', resp.status, resp.reason) 44 | sys.exit(1) 45 | resp_data = await resp.text() 46 | try: 47 | tokens = json.loads(resp_data) 48 | except UnicodeDecodeError: 49 | logging.exception('Failed to parse login tokens to Hisense server:\nData: %r', resp_data) 50 | sys.exit(1) 51 | return tokens['access_token'] 52 | 53 | 54 | async def _get_devices(devices_server: str, access_token: str, headers: dict, 55 | session: aiohttp.ClientSession, ssl_context: ssl.SSLContext): 56 | logging.debug('GET /apiv1/devices.json, headers=%r', headers) 57 | async with session.get(f'https://{devices_server}/apiv1/devices.json', 58 | headers=headers, 59 | ssl=ssl_context) as resp: 60 | if resp.status != HTTPStatus.OK.value: 61 | logging.error('Failed to get devices data from Hisense server:\nStatus %d: %r', resp.status, 62 | resp.reason) 63 | sys.exit(1) 64 | resp_data = await resp.text() 65 | try: 66 | devices = json.loads(resp_data) 67 | except UnicodeDecodeError: 68 | logging.exception('Failed to parse devices data from Hisense server:\nData: %r', resp_data) 69 | sys.exit(1) 70 | if not devices: 71 | logging.error('No device is configured! Please configure a device first.') 72 | sys.exit(1) 73 | return devices 74 | 75 | 76 | async def _get_lanip(devices_server: str, dsn: str, headers: dict, session: aiohttp.ClientSession, 77 | ssl_context: ssl.SSLContext): 78 | logging.debug(f'GET /apiv1/dsns/{dsn}/lan.json, headers=%r', headers) 79 | async with session.get(f'https://{devices_server}/apiv1/dsns/{dsn}/lan.json', 80 | headers=headers, 81 | ssl=ssl_context) as resp: 82 | if resp.status != HTTPStatus.OK.value: 83 | logging.error('Failed to get device data from Hisense server: %r', resp) 84 | sys.exit(1) 85 | resp_data = await resp.text() 86 | return json.loads(resp_data)['lanip'] 87 | 88 | 89 | async def _get_device_properties(devices_server: str, dsn: str, headers: dict, 90 | session: aiohttp.ClientSession, ssl_context: ssl.SSLContext): 91 | logging.debug(f'GET /apiv1/dsns/{dsn}/properties.json, headers=%r', headers) 92 | async with session.get(f'https://{devices_server}/apiv1/dsns/{dsn}/properties.json', 93 | headers=headers, 94 | ssl=ssl_context) as resp: 95 | if resp.status != HTTPStatus.OK.value: 96 | logging.error('Failed to get properties data from Hisense server: %r', resp) 97 | sys.exit(1) 98 | resp_data = await resp.text() 99 | return json.loads(resp_data) 100 | 101 | 102 | async def perform_discovery(session: aiohttp.ClientSession, 103 | app: str, 104 | user: str, 105 | passwd: str, 106 | device_filter: str = None, 107 | properties_filter: bool = False) -> dict: 108 | if app in SECRET_ID_MAP: 109 | app_prefix = SECRET_ID_MAP[app] 110 | else: 111 | app_prefix = 'a-Hisense-{}-field'.format(app) 112 | 113 | if app in SECRET_ID_EXTRA_MAP: 114 | app_id = '-'.join((app_prefix, SECRET_ID_EXTRA_MAP[app], 'id')) 115 | else: 116 | app_id = '-'.join((app_prefix, 'id')) 117 | 118 | secret = base64.b64encode(SECRET_MAP[app]).decode('utf-8').rstrip('=').replace('+', '-').replace( 119 | '/', '_') 120 | app_secret = '-'.join((app_prefix, secret)) 121 | 122 | # Extract the region from the app ID (and fallback to US) 123 | region = app[-2:] 124 | if region not in AYLA_USER_SERVERS: 125 | region = 'us' 126 | user_server = AYLA_USER_SERVERS[region] 127 | devices_server = AYLA_DEVICES_SERVERS[region] 128 | 129 | ssl_context = ssl.SSLContext() 130 | ssl_context.verify_mode = ssl.CERT_NONE 131 | ssl_context.check_hostname = False 132 | ssl_context.load_default_certs() 133 | 134 | access_token = await _sign_in(user, passwd, user_server, app_id, app_secret, session, ssl_context) 135 | 136 | result = [] 137 | headers = { 138 | 'Accept': 'application/json', 139 | 'Connection': 'Keep-Alive', 140 | 'Authorization': 'auth_token ' + access_token, 141 | 'User-Agent': _USER_AGENT, 142 | 'Host': devices_server, 143 | 'Accept-Encoding': 'gzip' 144 | } 145 | devices = await _get_devices(devices_server, access_token, headers, session, ssl_context) 146 | logging.debug('Found devices: %r', devices) 147 | for device in devices: 148 | device_data = device['device'] 149 | if device_filter and device_filter != device_data['product_name']: 150 | continue 151 | dsn = device_data['dsn'] 152 | lanip = await _get_lanip(devices_server, dsn, headers, session, ssl_context) 153 | properties_text = '' 154 | if properties_filter: 155 | props = await _get_device_properties(devices_server, dsn, headers, session, ssl_context) 156 | device_data['properties'] = props 157 | 158 | device_data['lanip_key'] = lanip['lanip_key'] 159 | device_data['lanip_key_id'] = lanip['lanip_key_id'] 160 | device_data['temp_type'] = 'C' if app in CELSIUS_BASED_APPS else 'F' 161 | # If the server doesn't know the MAC address, fetch it from the local network. 162 | if not device_data.get('mac'): 163 | mac = get_mac_address(ip=device_data['lan_ip']) 164 | if not mac or mac == '00:00:00:00:00:00': 165 | logging.error(f'Failed to fetch MAC address for AC on IP address {device_data["lan_ip"]}.' + 166 | '\nAre you sure it is connected? Skipping...') 167 | continue 168 | device_data['mac'] = mac.replace(':', '') 169 | result.append(device_data) 170 | return result 171 | -------------------------------------------------------------------------------- /devicetypes/deiger/hisense-air-conditioner.src/hisense-air-conditioner.groovy: -------------------------------------------------------------------------------- 1 | /** 2 | * Hisense Air Conditioner 3 | * 4 | * Copyright 2019 Dror Eiger 5 | * 6 | * Licensed under the GNU General Public License, Version 3.0 (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at: 8 | * 9 | * https://www.gnu.org/licenses/gpl-3.0.en.html 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed 12 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing permissions and limitations under the License. 14 | * 15 | */ 16 | 17 | preferences { 18 | input("host", "text", title: "IP Address", description: "The IP address and port for the Hisense server.") 19 | } 20 | 21 | metadata { 22 | definition(name: "Hisense Air Conditioner", namespace: "deiger", author: "Dror Eiger", mnmn: "SmartThings", ocfDeviceType: "oic.d.airconditioner", vid: "SmartThings-smartthings-Hisense_Air_Conditioner") { 23 | capability "Air Conditioner Mode" 24 | capability "Fan Speed" 25 | capability "Filter Status" 26 | capability "Health Check" 27 | capability "Power Meter" 28 | capability "Rapid Cooling" 29 | capability "Relative Humidity Measurement" 30 | capability "Switch" 31 | capability "Temperature Measurement" 32 | capability "Thermostat Setpoint" 33 | capability "Voltage Measurement" 34 | 35 | command "setAirConditionerMode" 36 | command "setFanSpeed" 37 | command "setRapidCooling" 38 | command "off" 39 | command "on" 40 | command "nextFanSpeed" 41 | command "nextAirConditionerMode" 42 | command "temperatureUp" 43 | command "temperatureDown" 44 | command "displayOff" 45 | command "displayOn" 46 | 47 | attribute "airConditionerMode", "ENUM" 48 | attribute "fanSpeed", "NUMBER" 49 | attribute "filterStatus", "ENUM" 50 | attribute "power", "NUMBER" 51 | attribute "rapidCooling", "ENUM" 52 | attribute "humidity", "NUMBER" 53 | attribute "switch", "ENUM" 54 | attribute "temperature", "NUMBER" 55 | attribute "thermostatSetpoint", "NUMBER" 56 | attribute "voltage", "NUMBER" 57 | attribute "display", "ENUM" 58 | attribute "temperatureUnit", "string" 59 | } 60 | 61 | simulator { 62 | } 63 | 64 | tiles(scale: 2) { 65 | multiAttributeTile(name:"temperature", type:"thermostat", width: 6, height: 4) { 66 | tileAttribute("device.switch", key: "PRIMARY_CONTROL") { 67 | attributeState("off", label: '${name}', action: "on", backgroundColor: "#ffffff", nextState:"on", icon:"st.thermostat.ac.air-conditioning") 68 | attributeState("on", label: '${name}', action: "off", backgroundColor: "#79b821", nextState:"off", icon:"st.thermostat.ac.air-conditioning") 69 | attributeState("offline", label:'${name}', backgroundColor:"#bc2323", defaultState: true, icon:"st.thermostat.ac.air-conditioning") 70 | } 71 | tileAttribute("device.thermostatSetpoint", key: "VALUE_CONTROL") { 72 | attributeState("VALUE_UP", action: "temperatureUp") 73 | attributeState("VALUE_DOWN", action: "temperatureDown") 74 | } 75 | tileAttribute("device.temperature", key: "SECONDARY_CONTROL") { 76 | attributeState("temp", label:'${currentValue}', unit:"dC", icon: "st.alarm.temperature.normal") 77 | } 78 | } 79 | standardTile("airConditionerMode", "device.airConditionerMode", width: 2, height: 2, decoration: "flat") { 80 | state("fanOnly", label:'Fan', action: "nextAirConditionerMode", backgroundColor:"#145D78", nextState:"heat", icon: "st.thermostat.fan-on") 81 | state("heat", label:'Heat', action: "nextAirConditionerMode", backgroundColor:"#e86d13", nextState:"cool", icon: "st.thermostat.heat") 82 | state("cool", label:'Cool', action: "nextAirConditionerMode", backgroundColor:"#00a0dc", nextState:"dry", icon: "st.thermostat.cool") 83 | state("dry", label:'Dry', action: "nextAirConditionerMode", backgroundColor:"#44B621", nextState:"auto", icon: "st.vents.wet") 84 | state("auto", label:'Auto', action: "nextAirConditionerMode", backgroundColor: "#ffffff", nextState:"fanOnly", icon: "st.thermostat.auto") 85 | } 86 | standardTile("fanSpeed", "device.fanSpeed", width: 2, height: 2, decoration: "flat") { 87 | state("0", label: 'Auto', action: "nextFanSpeed", nextState:"5", icon:"st.thermostat.fan-auto") 88 | state("5", label: 'Lower', action: "nextFanSpeed", nextState:"6", icon:"st.thermostat.fan-on") 89 | state("6", label: 'Low', action: "nextFanSpeed", nextState:"7", icon:"st.thermostat.fan-on") 90 | state("7", label: 'Medium', action: "nextFanSpeed", nextState:"8", icon:"st.thermostat.fan-on") 91 | state("8", label: 'High', action: "nextFanSpeed", nextState:"9", icon:"st.thermostat.fan-on") 92 | state("9", label: 'Higher', action: "nextFanSpeed", nextState:"0", icon:"st.thermostat.fan-on") 93 | state("-1", label:'Not Supported') 94 | } 95 | standardTile("display", "device.display", width: 2, height: 2, decoration: "flat") { 96 | state("on", label: 'Disaply On', action: "displayOff", backgroundColor: "#79b821", nextState:"off", icon: "st.switches.light.on") 97 | state("off", label: 'Display Off', action: "displayOn", backgroundColor: "#ffffff", nextState:"on", icon: "st.switches.light.off") 98 | } 99 | standardTile("rapidCooling", "device.rapidCooling", width: 2, height: 2, decoration: "flat") { 100 | state("on", label: 'Rapid On', action: "setRapidCooling 'off'", backgroundColor: "#79b821", nextState:"off", icon: "st.vents.vent-open") 101 | state("off", label: 'Rapid Off', action: "setRapidCooling 'on'", backgroundColor: "#ffffff", nextState:"on", icon: "st.vents.vent-closed") 102 | } 103 | valueTile("humidity", "device.humidity", width: 2, height: 2, decoration: "flat") { 104 | state("humidity", label: '${currentValue}%', backgroundColor: "#ffffff") 105 | } 106 | main("temperature") 107 | details([ 108 | "temperature", "airConditionerMode", "fanSpeed", "display", "rapidCooling", "humidity" 109 | ]) 110 | } 111 | } 112 | 113 | def installed() { 114 | initialize() 115 | } 116 | 117 | def updated() { 118 | initialize() 119 | } 120 | 121 | def initialize() { 122 | unschedule(updateStatus) 123 | runEvery1Minute(updateStatus) 124 | } 125 | 126 | void temperatureUp() { 127 | updateTemperature(state.thermostatSetpoint + 1) 128 | } 129 | 130 | void temperatureDown() { 131 | updateTemperature(state.thermostatSetpoint - 1) 132 | } 133 | 134 | void updateTemperature(float new_temp) { 135 | // Since the AC actually works only in F, convert and round in F and then convert back. 136 | def tempF = convertTempToF(new_temp).round().toInteger() 137 | sendCommand("t_temp", tempF) 138 | state.thermostatSetpoint = convertTempFromF(tempF) 139 | updateField("thermostatSetpoint", state.thermostatSetpoint.round().toInteger(), state.temperatureUnit) 140 | } 141 | 142 | void nextAirConditionerMode() { 143 | switch (state.airConditionerMode) { 144 | case "fanOnly": 145 | setAirConditionerMode("HEAT") 146 | break 147 | case "heat": 148 | setAirConditionerMode("COOL") 149 | break 150 | case "cool": 151 | setAirConditionerMode("DRY") 152 | break 153 | case "dry": 154 | setAirConditionerMode("AUTO") 155 | break 156 | case "auto": 157 | setAirConditionerMode("FAN") 158 | break 159 | default: 160 | log.debug "Invalid state.airConditionerMode ${state.airConditionerMode}" 161 | } 162 | } 163 | 164 | void setAirConditionerMode(String mode) { 165 | sendCommand("t_work_mode", mode) 166 | updateStateAirConditionerMode(mode) 167 | updateField("airConditionerMode", state.airConditionerMode) 168 | } 169 | 170 | void updateStateAirConditionerMode(String mode) { 171 | switch (mode) { 172 | case "FAN": 173 | state.airConditionerMode = "fanOnly" 174 | break 175 | case "HEAT": 176 | state.airConditionerMode = "heat" 177 | break 178 | case "COOL": 179 | state.airConditionerMode = "cool" 180 | break 181 | case "DRY": 182 | state.airConditionerMode = "dry" 183 | break 184 | case "AUTO": 185 | state.airConditionerMode = "auto" 186 | break 187 | default: 188 | state.airConditionerMode = "notSupported" 189 | break 190 | } 191 | } 192 | 193 | void nextFanSpeed() { 194 | switch (state.fanSpeed) { 195 | case 0: 196 | setFanSpeed("LOWER") 197 | break 198 | case 5: 199 | setFanSpeed("LOW") 200 | break 201 | case 6: 202 | setFanSpeed("MEDIUM") 203 | break 204 | case 7: 205 | setFanSpeed("HIGH") 206 | break 207 | case 8: 208 | setFanSpeed("HIGHER") 209 | break 210 | case 9: 211 | setFanSpeed("AUTO") 212 | break 213 | default: 214 | log.debug "Invalid state.fanSpeed ${state.fanSpeed}" 215 | } 216 | } 217 | 218 | void setFanSpeed(String speed) { 219 | sendCommand("t_fan_speed", speed) 220 | updateStateFanSpeed(speed) 221 | updateField("fanSpeed", state.fanSpeed) 222 | } 223 | 224 | void updateStateFanSpeed(String speed) { 225 | switch (speed) { 226 | case "AUTO": 227 | state.fanSpeed = 0 228 | break 229 | case "LOWER": 230 | state.fanSpeed = 5 231 | break 232 | case "LOW": 233 | state.fanSpeed = 6 234 | break 235 | case "MEDIUM": 236 | state.fanSpeed = 7 237 | break 238 | case "HIGH": 239 | state.fanSpeed = 8 240 | break 241 | case "HIGHER": 242 | state.fanSpeed = 9 243 | break 244 | default: 245 | state.fanSpeed = -1 246 | break 247 | } 248 | } 249 | 250 | void setRapidCooling(String status) { 251 | sendCommand("t_temp_heatcold", status == "on" ? "ON" : "OFF") 252 | state.rapidCooling = status 253 | updateField("rapidCooling", state.rapidCooling) 254 | } 255 | 256 | void off() { 257 | sendCommand("t_power", "OFF") 258 | state.switch = "off" 259 | updateField("switch", state.switch) 260 | } 261 | 262 | void on() { 263 | sendCommand("t_power", "ON") 264 | state.switch = "on" 265 | updateField("switch", state.switch) 266 | } 267 | 268 | void displayOff() { 269 | sendCommand("t_backlight", "ON") 270 | state.display = "off" 271 | updateField("display", state.display) 272 | } 273 | 274 | void displayOn() { 275 | sendCommand("t_backlight", "OFF") 276 | state.display = "on" 277 | updateField("display", state.display) 278 | } 279 | 280 | def sendCommand(String property, value) { 281 | String valueStr = value.toString() 282 | sendQuery("/hisense/command?property=" + property + "&value=" + valueStr, null) 283 | } 284 | 285 | def updateStatus() { 286 | sendQuery("/hisense/status", updateStatusHandler) 287 | } 288 | 289 | void updateField(String field, value, String unit="") { 290 | String valueStr = value.toString() 291 | def oldValue = device.currentState(field)?.stringValue 292 | if (valueStr != oldValue) { 293 | sendEvent(name: field, value: valueStr, unit: unit, descriptionText: "${field} is ${value}${unit}", displayed: true) 294 | } 295 | } 296 | 297 | void updateStatusHandler(physicalgraph.device.HubResponse hubResponse) { 298 | log.debug "updateStatusHandler(${hubResponse.body})" 299 | def status = hubResponse?.json 300 | if (status) { 301 | state.switch = status.t_power == "ON" ? "on" : "off" 302 | state.display = status.t_backlight == "ON" ? "off" : "on" 303 | state.rapidCooling = status.t_temp_heatcold == "ON" ? "on" : "off" 304 | updateStateAirConditionerMode(status.t_work_mode) 305 | updateStateFanSpeed(status.t_fan_speed) 306 | state.temperatureUnit = status.t_temptype == "CELSIUS" ? "C" : "F" 307 | state.thermostatSetpoint = convertTempFromF(status.t_temp) 308 | state.temperature = convertTempFromF(status.f_temp_in) 309 | if (status.f_humidity > 0) { 310 | state.humidity = status.f_humidity 311 | } 312 | log.debug "Current state: ${state}" 313 | updateField("switch", state.switch) 314 | updateField("display", state.display) 315 | updateField("rapidCooling", state.rapidCooling) 316 | updateField("airConditionerMode", state.airConditionerMode) 317 | updateField("fanSpeed", state.fanSpeed) 318 | updateField("thermostatSetpoint", state.thermostatSetpoint.round().toInteger(), state.temperatureUnit) 319 | updateField("temperature", state.temperature.round().toInteger(), state.temperatureUnit) 320 | } 321 | } 322 | 323 | float convertTempFromF(float temp) { 324 | if (state.temperatureUnit == "F") { 325 | return temp 326 | } 327 | return ((temp - 32) / 1.8).toFloat() 328 | } 329 | 330 | float convertTempToF(float temp) { 331 | if (state.temperatureUnit == "F") { 332 | return temp 333 | } 334 | return (temp * 1.8 + 32).toFloat() 335 | } 336 | 337 | def sendQuery(path, _callback) { 338 | def options = [ 339 | "method": "GET", 340 | "path": path, 341 | "headers": [ 342 | "HOST": settings.host, 343 | "Content-Type": "application/json", 344 | ] 345 | ] 346 | log.debug options 347 | def hubAction = new physicalgraph.device.HubAction(options, null, [callback: _callback]) 348 | sendHubCommand(hubAction) 349 | } 350 | -------------------------------------------------------------------------------- /aircon/__main__.py: -------------------------------------------------------------------------------- 1 | import aiohttp 2 | from aiohttp import web 3 | import argparse 4 | import asyncio 5 | import base64 6 | from http import HTTPStatus 7 | from http.client import HTTPConnection, InvalidURL 8 | from http.server import HTTPServer, BaseHTTPRequestHandler 9 | import json 10 | import logging 11 | import logging.handlers 12 | import os 13 | import paho.mqtt.client as mqtt 14 | from retry import retry 15 | import signal 16 | import socket 17 | import sys 18 | try: 19 | from systemd.journal import JournalHandler 20 | except: 21 | JournalHandler = None 22 | import textwrap 23 | import threading 24 | import time 25 | import _thread 26 | from urllib.parse import parse_qs, urlparse, ParseResult 27 | 28 | from .app_mappings import SECRET_MAP 29 | from .config import Config 30 | from .error import Error 31 | from .aircon import Device 32 | from .discovery import perform_discovery 33 | from .mqtt_client import MqttClient 34 | from .notifier import Notifier 35 | from .query_handlers import QueryHandlers 36 | 37 | 38 | async def query_status_device(device: Device): 39 | _STATUS_UPDATE_INTERVAL = 600.0 40 | _WAIT_FOR_EMPTY_QUEUE = 10.0 41 | while True: 42 | # In case the AC is stuck, and not fetching commands, avoid flooding 43 | # the queue with status updates. 44 | while device.commands_queue.qsize() > 10: 45 | await asyncio.sleep(_WAIT_FOR_EMPTY_QUEUE) 46 | device.queue_status() 47 | await asyncio.sleep(_STATUS_UPDATE_INTERVAL) 48 | 49 | 50 | async def query_status_worker(devices: [Device]): 51 | await asyncio.wait([asyncio.create_task(query_status_device(device)) for device in devices]) 52 | 53 | 54 | def ParseArguments() -> argparse.Namespace: 55 | """Parse command line arguments.""" 56 | arg_parser = argparse.ArgumentParser(description='JSON server for HiSense air conditioners.', 57 | allow_abbrev=False) 58 | arg_parser.add_argument('--log_level', 59 | default='WARNING', 60 | choices={'CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'}, 61 | help='Minimal log level.') 62 | subparsers = arg_parser.add_subparsers(dest='cmd', help='Determines what server should do') 63 | subparsers.required = True 64 | 65 | parser_run = subparsers.add_parser('run', help='Runs the server to control the device') 66 | parser_run.add_argument('-p', '--port', required=True, type=int, help='Port for the server.') 67 | parser_run.add_argument('--local_ip', 68 | required=False, 69 | default=None, 70 | help='The local IP address to report to the AC unit(s) as target server. Useful in case the server running this application has multiple IP addresses (e.g. in multiple VLANs), since some/most(?) AC units will refuse to report to an IP address outside of their subnet.') 71 | group_device = parser_run.add_argument_group('Device', 'Arguments that are related to the device') 72 | group_device.add_argument('--config', required=True, action='append', help='LAN Config file.') 73 | group_device.add_argument('--type', 74 | required=False, 75 | action='append', 76 | choices={'ac', 'fgl', 'fgl_b', 'humidifier'}, 77 | help='Device type. Deprecated, now decided based on OEM model.') 78 | 79 | group_mqtt = parser_run.add_argument_group('MQTT', 'Settings related to the MQTT') 80 | group_mqtt.add_argument('--mqtt_host', default=None, help='MQTT broker hostname or IP address.') 81 | group_mqtt.add_argument('--mqtt_port', type=int, default=1883, help='MQTT broker port.') 82 | group_mqtt.add_argument('--mqtt_client_id', default=None, help='MQTT client ID.') 83 | group_mqtt.add_argument('--mqtt_user', default=None, help=' for the MQTT channel.') 84 | group_mqtt.add_argument('--mqtt_topic', default='hisense_ac', help='MQTT topic.') 85 | group_mqtt.add_argument('--mqtt_discovery_prefix', 86 | default='homeassistant', 87 | help='MQTT discovery prefix for HomeAssistant.') 88 | 89 | parser_discovery = subparsers.add_parser('discovery', help='Runs the device discovery') 90 | parser_discovery.add_argument('app', choices=set(SECRET_MAP), help='The app used for the login.') 91 | parser_discovery.add_argument('user', help='Username for the app login.') 92 | parser_discovery.add_argument('passwd', help='Password for the app login.') 93 | parser_discovery.add_argument('-d', 94 | '--device', 95 | default=None, 96 | help='Device name to fetch data for. If not set, takes all.') 97 | parser_discovery.add_argument('--prefix', 98 | required=False, 99 | default='config_', 100 | help='Config file prefix.') 101 | parser_discovery.add_argument('--properties', 102 | action='store_true', 103 | help='Fetch the properties for the device.') 104 | return arg_parser.parse_args() 105 | 106 | 107 | def setup_logger(log_level, use_stderr=False): 108 | if use_stderr or os.environ.get('PLATFORM') == 'docker': 109 | logging_handler = logging.StreamHandler(sys.stderr) 110 | elif JournalHandler: 111 | logging_handler = JournalHandler() 112 | # Fallbacks when JournalHandler isn't available. 113 | elif sys.platform == 'linux': 114 | logging_handler = logging.handlers.SysLogHandler(address='/dev/log') 115 | elif sys.platform == 'darwin': 116 | logging_handler = logging.handlers.SysLogHandler(address='/var/run/syslog') 117 | elif sys.platform.lower() in ['windows', 'win32']: 118 | logging_handler = logging.handlers.SysLogHandler() 119 | else: # Unknown platform, revert to stderr 120 | logging_handler = logging.StreamHandler(sys.stderr) 121 | logging_handler.setFormatter( 122 | logging.Formatter(fmt='{levelname[0]}{asctime}.{msecs:03.0f} ' 123 | '{filename}:{lineno}] {message}', 124 | datefmt='%m%d %H:%M:%S', 125 | style='{')) 126 | logger = logging.getLogger() 127 | logger.setLevel(log_level) 128 | logger.addHandler(logging_handler) 129 | 130 | 131 | async def setup_and_run_http_server(parsed_args, devices: [Device]): 132 | query_handlers = QueryHandlers(devices) 133 | app = web.Application() 134 | app.add_routes([ 135 | web.get('/hisense/status', query_handlers.get_status_handler), 136 | web.get('/hisense/command', query_handlers.queue_command_handler), 137 | web.post('/local_lan/key_exchange.json', query_handlers.key_exchange_handler), 138 | web.get('/local_lan/commands.json', query_handlers.command_handler), 139 | web.post('/local_lan/property/datapoint.json', query_handlers.property_update_handler), 140 | web.post('/local_lan/property/datapoint/ack.json', query_handlers.property_update_handler), 141 | web.post('/local_lan/node/property/datapoint.json', query_handlers.property_update_handler), 142 | web.post('/local_lan/node/property/datapoint/ack.json', 143 | query_handlers.property_update_handler), 144 | # TODO: Handle these if needed. 145 | # '/local_lan/node/conn_status.json': query_handlers.connection_status_handler, 146 | # '/local_lan/connect_status': query_handlers.module_request_handler, 147 | # '/local_lan/status.json': query_handlers.setup_device_details_handler, 148 | # '/local_lan/wifi_scan.json': query_handlers.module_request_handler, 149 | # '/local_lan/wifi_scan_results.json': query_handlers.module_request_handler, 150 | # '/local_lan/wifi_status.json': query_handlers.module_request_handler, 151 | # '/local_lan/regtoken.json': query_handlers.module_request_handler, 152 | # '/local_lan/wifi_stop_ap.json': query_handlers.module_request_handler 153 | ]) 154 | runner = web.AppRunner(app) 155 | await runner.setup() 156 | site = web.TCPSite(runner, port=parsed_args.port) 157 | await site.start() 158 | 159 | 160 | async def mqtt_loop(mqtt_client: MqttClient): 161 | _MQTT_LOOP_TIMEOUT = 1 162 | while True: 163 | mqtt_client.loop() 164 | await asyncio.sleep(_MQTT_LOOP_TIMEOUT) 165 | 166 | 167 | async def run(parsed_args): 168 | notifier = Notifier(parsed_args.port, parsed_args.local_ip) 169 | devices = [] 170 | for i in range(len(parsed_args.config)): 171 | with open(parsed_args.config[i], 'rb') as f: 172 | config = json.load(f) 173 | device = Device.create(config, notifier.notify) 174 | notifier.register_device(device) 175 | devices.append(device) 176 | 177 | mqtt_client = None 178 | if parsed_args.mqtt_host: 179 | mqtt_topics = { 180 | 'pub': 181 | '/'.join((parsed_args.mqtt_topic, '{}', '{}', 'status')), 182 | 'sub': 183 | '/'.join((parsed_args.mqtt_topic, '{}', '{}', 'command')), 184 | 'lwt': 185 | '/'.join((parsed_args.mqtt_topic, 'LWT')), 186 | 'discovery': 187 | '/'.join((parsed_args.mqtt_discovery_prefix, 'climate', '{}', 'hvac', 'config')) 188 | } 189 | mqtt_client = MqttClient(parsed_args.mqtt_client_id, mqtt_topics, devices) 190 | if parsed_args.mqtt_user: 191 | mqtt_client.username_pw_set(*parsed_args.mqtt_user.split(':', 1)) 192 | mqtt_client.will_set(mqtt_topics['lwt'], payload='offline', retain=True) 193 | mqtt_client.connect(parsed_args.mqtt_host, parsed_args.mqtt_port) 194 | mqtt_client.publish(mqtt_topics['lwt'], payload='online', retain=True) 195 | for device in devices: 196 | config = { 197 | 'unique_id': device.mac_address, 198 | 'device': { 199 | 'identifiers': [f'hisense_ac_{device.mac_address}'], 200 | 'manufacturer': f'Hisense ({device.app})', 201 | 'model': device.model, 202 | 'name': device.name, 203 | 'sw_version': device.sw_version 204 | }, 205 | 'availability': [ 206 | { 207 | 'topic': mqtt_topics['lwt'] 208 | }, 209 | { 210 | 'topic': mqtt_topics['pub'].format(device.mac_address, 'available') 211 | }, 212 | ], 213 | 'precision': 1.0, 214 | 'temperature_unit': 'F' if device.is_fahrenheit else 'C' 215 | } 216 | topics = device.topics 217 | if 'env_temp' in topics: 218 | config['current_temperature_topic'] = mqtt_topics['pub'].format( 219 | device.mac_address, topics['env_temp']) 220 | if 'fan_speed' in topics: 221 | config['fan_mode_command_topic'] = mqtt_topics['sub'].format(device.mac_address, 222 | topics['fan_speed']) 223 | config['fan_mode_state_topic'] = mqtt_topics['pub'].format(device.mac_address, 224 | topics['fan_speed']) 225 | config['fan_modes'] = device.fan_modes 226 | if 'work_mode' in topics: 227 | config['mode_command_topic'] = mqtt_topics['sub'].format(device.mac_address, 228 | topics['work_mode']) 229 | config['mode_state_topic'] = mqtt_topics['pub'].format(device.mac_address, 230 | topics['work_mode']) 231 | config['modes'] = device.work_modes 232 | if 'swing_mode' in topics: 233 | config['swing_mode_command_topic'] = mqtt_topics['sub'].format( 234 | device.mac_address, topics['swing_mode']) 235 | config['swing_mode_state_topic'] = mqtt_topics['pub'].format(device.mac_address, 236 | topics['swing_mode']) 237 | config['swing_modes'] = ['on', 'off'] 238 | if 'temp' in topics: 239 | config['temperature_command_topic'] = mqtt_topics['sub'].format( 240 | device.mac_address, topics['temp']) 241 | config['temperature_state_topic'] = mqtt_topics['pub'].format(device.mac_address, 242 | topics['temp']) 243 | config['max_temp'] = '86' if device.is_fahrenheit else '30' 244 | config['min_temp'] = '61' if device.is_fahrenheit else '16' 245 | mqtt_client.publish(mqtt_topics['discovery'].format(device.mac_address), 246 | payload=json.dumps(config), 247 | retain=True) 248 | device.add_property_change_listener(mqtt_client.mqtt_publish_update) 249 | 250 | async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(connect=5.0)) as session: 251 | await asyncio.gather(mqtt_loop(mqtt_client), setup_and_run_http_server(parsed_args, devices), 252 | query_status_worker(devices), notifier.start(session)) 253 | 254 | 255 | def _escape_name(name: str): 256 | safe_name = name.replace(' ', '_').lower() 257 | return ''.join(x for x in safe_name if x.isalnum()) 258 | 259 | 260 | async def discovery(parsed_args): 261 | async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(connect=5.0)) as session: 262 | try: 263 | all_configs = await perform_discovery(session, parsed_args.app, parsed_args.user, 264 | parsed_args.passwd, parsed_args.device, 265 | parsed_args.properties) 266 | except Exception as e: 267 | print(f'Error occurred:\n{e!r}') 268 | sys.exit(1) 269 | 270 | for config in all_configs: 271 | properties_text = '' 272 | if 'properties' in config.keys(): 273 | properties_text = f'Properties:\n{json.dumps(config["properties"], indent=2)}' 274 | print( 275 | textwrap.dedent(f"""Device {config['product_name']} has: 276 | IP address: {config['lan_ip']} 277 | lanip_key: {config['lanip_key']} 278 | lanip_key_id: {config['lanip_key_id']} 279 | {properties_text} 280 | """)) 281 | 282 | file_content = { 283 | 'name': config['product_name'], 284 | 'app': parsed_args.app, 285 | 'model': config['oem_model'], 286 | 'sw_version': config['sw_version'], 287 | 'dsn': config['dsn'], 288 | 'temp_type': config['temp_type'], 289 | 'mac_address': config['mac'], 290 | 'ip_address': config['lan_ip'], 291 | 'lanip_key': config['lanip_key'], 292 | 'lanip_key_id': config['lanip_key_id'], 293 | } 294 | with open(parsed_args.prefix + _escape_name(config['product_name']) + '.json', 'w') as f: 295 | f.write(json.dumps(file_content)) 296 | 297 | 298 | if __name__ == '__main__': 299 | parsed_args = ParseArguments() # type: argparse.Namespace 300 | 301 | if parsed_args.cmd == 'run': 302 | setup_logger(parsed_args.log_level) 303 | asyncio.run(run(parsed_args)) 304 | elif parsed_args.cmd == 'discovery': 305 | setup_logger(parsed_args.log_level, use_stderr=True) 306 | asyncio.run(discovery(parsed_args)) 307 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HiSense Air Conditioners 2 | 3 | This program implements the Ayla Networks LAN API to interact with HiSense WiFi Air Conditioner module, models AEH-W4B1 and AEH-W4E1, as well as Fujitsu FGLair. 4 | 5 | As discussed [here](../../issues/1), the program doesn't seem to fit the AEH-W4A1 module, which relies on entirely different protocol (implemented by the apps [Hi-Smart Life](https://play.google.com/store/apps/details?id=com.qd.android.livehome), [AirConnect](https://play.google.com/store/apps/details?id=com.oem.android.airconnect), [Smart Cool](https://play.google.com/store/apps/details?id=com.oem.android.livehome), [AC WIFI](https://play.google.com/store/apps/details?id=com.oem.android.ecold) and [טורנדו WiFi](https://play.google.com/store/apps/details?id=com.oem.android.tornadowifi)). Please let me know if you have a different experience, or tried it with other modules. 6 | 7 | The module is installed in A/Cs and humidifiers that are either manufactured or only branded by many other companies. These include Beko, Westinghouse, Winia, Tornado, York and more. 8 | 9 | **This program is not affiliated with Ayla Networks, HiSense, Fujitsu, any of their subsidiaries, or any of their resellers.** 10 | 11 | ## Prerequisites 12 | 13 | 1. Air Conditioner with HiSense AEH-W4B1 or AEH-W4E1 installed, or a Fujitsu FGLair. 14 | 1. Have Python 3.10 or above installed. If using Raspberry Pi, either upgrade to Raspbian Buster, or manually install it in Raspbian Stretch. 15 | 1. Configure the A/Cs with the dedicated app. Links to each app are available in the table below. Log into the app, associate each A/C and connect it to the network, as described in the app documentation. 16 | 1. Once everything has been configured, the A/Cs can be blocked from connecting to the internet, as it will no longer be needed. Set them static IP addresses in the router, and write them down. 17 | * Note: _To avoid the need for manual changes later, make sure the app is aware of the new IP addresses before disconnecting the A/Cs from the internet._ 18 | 1. Find the code for your app, from the list below: 19 | 20 | | Code | App Name | App link 21 | |------------|---------------------|---------| 22 | | beko-eu | Beko? | | 23 | | haxxair | HAXXAIR WIFI REMOTE | [![](https://lh3.googleusercontent.com/-9FX7-sYlE2xDwG9uymjPejV-P8nI_hQ9zN7QDu6OgyYILbjdg5o38nQTvAmFTPyiw=s50-rw)](https://play.google.com/store/apps/details?id=com.aylanetworks.accontrol.haxxair) | 24 | | denali-us | Denali Aire | [![](https://lh3.googleusercontent.com/8NYl3eNN7M_cXmvo4ywj9al5794Ci_dzGYxYZopHd96Z4yr1M12e8xzk9mkz5cMELQ=s50-rw)](https://play.google.com/store/apps/details?id=com.smart.internationalus.denaliaire) | 25 | | fglair-eu | FGLair | [![](https://lh3.googleusercontent.com/LcrpWfFdRi3GriCV3MqPhkKsxV-IkwFHxZHHDugC__iaO1HE-7UyKuQj-bEWyggo8DFP=s50-rw)](https://play.google.com/store/apps/details?id=com.fujitsu.fglair) | 26 | | field-us | HiSmart Air | [![](https://lh3.googleusercontent.com/9p4SUOklfccVzJdrbhHZW8MlmioF-YgfLWOQBtad2N_A5AWtcyNv7X-M3QT1e2Fdam00=s50-rw)](https://play.google.com/store/apps/details?id=com.aylanetworks.accontrol.hisense) | 27 | | hisense-eu | HiSmart Life | [![](https://lh3.googleusercontent.com/AbCPfEScNDwgsKozku6jmItFPVq9WJCl30jZKlSDFDAtlAiC3WRZZ4MlWEEWR8ZxKA=s50-rw)](https://play.google.com/store/apps/details?id=com.hisense.hismartinternationalforandroid) | 28 | | hisense-us | HiSmart Home | [![](https://lh3.googleusercontent.com/Qs9UJVhczWYk-ij7UiRWoCDi2pYIoOUYuU5pBwOKQSD_07KHyAnLGg-myF7U9a387w=s50-rw)](https://play.google.com/store/apps/details?id=com.hisense.hismartinternationalus) | 29 | | hismart-eu | Smart-Living | [![](https://lh3.googleusercontent.com/k9p0RMiW_xax5FIU5tpwSZav1In7tu6szGQopRWhSyRd2dIr0_L0IWHPVLSHxbrWrA=s50-rw)](https://play.google.com/store/apps/details?id=com.smart.international2) | 30 | | hismart-us | AI-Home | [![](https://lh3.googleusercontent.com/eUJicIOk50rP391IFs0Xw6306adghQuiQtaLgUkxImuP6bAdHvQjS1gbIKY75Bd2mkA=s50-rw)](https://play.google.com/store/apps/details?id=com.smart.internationalus) | 31 | | huihe-us | SunHome | [![](https://lh3.googleusercontent.com/3tI6Nbx4ZlphD_b5O7bW3XcMEKnFkViOKMS9-cL9K9OQVyGJRjRmKu67JU8_t_w93iZs=s50-rw)](https://play.google.com/store/apps/details?id=com.sunvalley.sunhome) | 32 | | mid-eu | WiFi AC | [![](https://lh3.googleusercontent.com/LWmnlcSnT2hYmdwB2vq5SoBuaawkS8eu0F6n9Tytowrftp7kflmUXRAt_uWg7C0Fgspn=s50-rw)](https://play.google.com/store/apps/details?id=com.accontrol.mid.europe.hisense) | 33 | | mid-us | Smiling Air | [![](https://lh3.googleusercontent.com/op7-cqkm6N3JinyViCONKKgIVeMWI4BGO4TP3atRheGKG_vzsufh1PmEa-v9b8OAEPI=s50-rw)](https://play.google.com/store/apps/details?id=com.accontrol.mid.america.hisense) | 34 | | oem-eu | Hi-Smart AC | [![](https://lh3.googleusercontent.com/-HdiS1L18OjviXxGY68fvuBO3I4J1XGEEPOIc0f8p268f0ZJYkADHVvOgzH2wttsBwnk=s50-rw)](https://play.google.com/store/apps/details?id=com.accontrol.europe.hisense) | 35 | | oem-us | Hisense? | | 36 | | tornado-us | ⁧טורנדו WIFI גרסה 2⁩ | [![](https://lh3.googleusercontent.com/M9kU7oYeZTU8hVLChdJQL4giJacgUT2yFw-pqNk8JR4kbqbvl9x8dT88BC0admZrrQ=s50-rw)](https://play.google.com/store/apps/details?id=com.accontrol.tornado.america.hisense) | 37 | | winia-us | 위니아 에어컨 홈스마트 | [![](https://lh3.googleusercontent.com/IGIkHlnLbFxTFGOk_aql3sVGgL9DLOtc3Ti_oDhQLUT8_-8PGmXjVBcQnmgqWxitB_U=s50-rw)](https://play.google.com/store/apps/details?id=com.accontrol.winia.america.hisense) | 38 | | wwh-us | Westinghouse? | | 39 | | york-us | YORK Smart | [![](https://lh3.googleusercontent.com/udf-qe7lXPJ5d7pi96WC8ex20-DuzAvAfyYX1i9B0zyvKjj0TLqoWwZmju-M5y0dQwE=s50-rw)](https://play.google.com/store/apps/details?id=com.accontrol.york.america.hisense) | 40 | 41 | ## Run the A/C control server as a HomeAssistant add-on. 42 | 43 | If using [HomeAssistant], this is the preferred method. 44 | 45 | 1. In the HomeAssistant UI, enter **Supervisor → Add-on Store**. 46 | 1. Click **⋮ menu → Repositories**. 47 | 1. Add `https://github.com/deiger/AirCon` to the list. 48 | 1. Choose **HiSense Air Conditioner** and install it. 49 | 1. Update the configuration as detailed within the add-on. 50 | 1. Start the add-on. Do not forget to enable **Start on boot** and **Watchdog**. 51 | 52 | ## Run the A/C control server in docker 53 | 54 | Use this method if not using HomeAssistant, or if you prefer to set it up outside of HomeAssistant. 55 | 56 | 1. Download the [`docker-compose.yaml`](docker-compose.yaml) and [`options.json`](options.json). Update all the relevant fields in `options.json`: 57 | - For every app (multiple apps are supported), set `username` and `password` to your app login credentials, and `code` to the app code from the list above. 58 | These will be used to discover you A/Cs and get their LAN keys, if there are no config files in the config directory (`/opt/hisense`). 59 | - Set `mqtt_host` to the [MQTT] broker server, use `localhost` if running on the same host. 60 | Leave blank if not using [MQTT]. 61 | - Set `mqtt_user` and `mqtt_pass` to the MQTT credentials. Leave null (or drop) if no authentication is used. 62 | - Set `port` to the port to be used by the web server. 63 | - Set `log_level` to your desired verbosity level. 64 | 65 | 1. Run: 66 | ```bash 67 | docker-compose up -d 68 | ``` 69 | 1. Check the logs and verify that everything is in shape: 70 | ```bash 71 | journalctl CONTAINER_NAME=hisense_ac 72 | ``` 73 | 74 | 1. Profit! 75 | The A/Cs should now be auto-discovered by [HomeAssistant] or [openHAB] 76 | (using the [HomeAssistant MQTT Components Binding](https://www.openhab.org/addons/bindings/mqtt.homeassistant/)). 77 | [SmartThings] requires manual setup, using the [groovy file](devicetypes/deiger/hisense-air-conditioner.src/hisense-air-conditioner.groovy), see below. 78 | 79 | ## Run the A/C control server manually 80 | 81 | Use this method if the docker setup above does not work for you. 82 | 83 | 1. Download and install aircon module: 84 | ```bash 85 | python3.10 setup.py install 86 | ``` 87 | 88 | 1. Run discovery command to fetch the LAN keys that will allow connecting to the A/C. Pass it your login credentials, as well as the code for your app from the list below: 89 | 90 | For example: 91 | ```bash 92 | python3.10 -m aircon discovery tornado-us foo@example.com my_pass 93 | ``` 94 | The CLI will generate a config file for each A/C, that needs to be passed to the A/C 95 | control server below. You can select the A/C that the config is generated for by 96 | setting the `--device` flag to the device name you configured in the app. 97 | 98 | * Note: _To update the server from head, run `git pull` on the repository and 99 | run setup. You may also need to re-run discovery._ 100 | 101 | 1. Test out that you can run the server, e.g.: 102 | ```bash 103 | python3.10 -m aircon run --port 8888 --config config.json --mqtt_host localhost 104 | ``` 105 | Parameters: 106 | - `--port` or `-p` - Port for the web server. 107 | - `--config` - The config file with the credentials to connect to the A/C. 108 | - `--mqtt_host` - The MQTT broker hostname or IP address. Must be set to enable MQTT. 109 | - `--mqtt_port` - The MQTT broker port. Default is 1883. 110 | - `--mqtt_client_id` - The MQTT client ID. If not set, a random client ID will be generated. 111 | - `--mqtt_user` - <user:password> for the MQTT channel. If not set, no authentication is used. 112 | - `--mqtt_topic` - The MQTT root topic. Default is "hisense_ac". The server will listen on topics 113 | <{mqtt_topic}/{property_name}/command> and publish to <{mqtt_topic}/{property_name}/status>. 114 | - `--log_level` - The minimal log level to send to syslog. Default is WARNING. 115 | - `--local_ip` - The local IP address to report to the AC unit(s) as target server. Useful in case the server running this application has multiple IP addresses (e.g. in multiple VLANs), since some/most(?) AC units will refuse to report to an IP address outside of their subnet. 116 | 1. Access e.g. using curl: 117 | ```bash 118 | curl -ik 'http://localhost:8888/hisense/status' 119 | curl -ik 'http://localhost:8888/hisense/command?property=t_power&value=ON' 120 | ``` 121 | 122 | ### Multiple Air Conditioners 123 | In order to use with multiple Air Conditioners, simply add multiple --config params. 124 | MQTT topic will contain your topic defined by flag --mqtt_topic (hisense_ac by default) and device MAC address (for uniqueness). 125 | 126 | ### Run as a service 127 | Assuming your username is "pi" 128 | 129 | 1. Create a dedicated directory for the script files, and move the files to it. 130 | Pass the ownership to root. e.g.: 131 | ```bash 132 | sudo mkdir /opt/hisense 133 | sudo mv config*.json /opt/hisense 134 | sudo chown pi:pi /opt/hisense/* 135 | ``` 136 | 1. Create a service configuration file (as root), e.g. `/lib/systemd/system/hisense.service`: 137 | ```INI 138 | [Unit] 139 | Description=Hisense A/C server 140 | After=network.target 141 | 142 | [Service] 143 | ExecStart=/usr/bin/python3.10 -m aircon run --port 8888 --config config.json --mqtt_host localhost 144 | WorkingDirectory=/opt/hisense 145 | StandardOutput=inherit 146 | StandardError=inherit 147 | Restart=always 148 | User=pi 149 | 150 | [Install] 151 | WantedBy=multi-user.target 152 | ``` 153 | 1. Link to it from `/etc/systemd/system/`: 154 | ```bash 155 | sudo ln -s /lib/systemd/system/hisense.service /etc/systemd/system/multi-user.target.wants/hisense.service 156 | ``` 157 | 1. Enable and start the new service: 158 | ```bash 159 | sudo systemctl enable hisense.service 160 | sudo systemctl start hisense.service 161 | ``` 162 | 1. If you use [MQTT](http://en.wikipedia.org/wiki/Mqtt) for [HomeAssistant] or 163 | [openHAB](https://www.openhab.org/), the broker should now provide the updated status of the A/C, and accepts commands. 164 | 165 | ## Available Properties 166 | 167 | Listed here are the properties available through the API for standard A/Cs 168 | (FGLair and humidifers have different properties): 169 | 170 | | Property | Read Only | Values | Comment | 171 | |------------------|-----------|----------------------------------------|--------------------------------------------------------------------------| 172 | | f_electricity | x | Integer | | 173 | | f_e_arkgrille | x | 0, 1 | Alarm from cabinet grille protection | 174 | | f_e_incoiltemp | x | 0, 1 | Indoor coil temperature sensor in fault | 175 | | f_e_incom | x | 0, 1 | Indoor and outdoor communication in fault | 176 | | f_e_indisplay | x | 0, 1 | Communication faulty between indoor control panel and display panel | 177 | | f_e_ineeprom | x | 0, 1 | Error in EEPROM of indoor control panel | 178 | | f_e_inele | x | 0, 1 | Communication faulty between indoor control panel and indoor power panel | 179 | | f_e_infanmotor | x | 0, 1 | Indoor fan motor operation abnormal | 180 | | f_e_inhumidity | x | 0, 1 | Indoor humidity sensor in fault | 181 | | f_e_inkeys | x | 0, 1 | Communication faulty between indoor control panel and keyboard plate | 182 | | f_e_inlow | x | 0, 1 | | 183 | | f_e_intemp | x | 0, 1 | Indoor temperature sensor in fault | 184 | | f_e_invzero | x | 0, 1 | Fault found from indoor voltage crossing zero detection | 185 | | f_e_outcoiltemp | x | 0, 1 | The temperature sensor in outdoor coil faulty | 186 | | f_e_outeeprom | x | 0, 1 | Outdoor EEPROM error | 187 | | f_e_outgastemp | x | 0, 1 | Exhaust temperature sensor faulty | 188 | | f_e_outmachine2 | x | 0, 1 | | 189 | | f_e_outmachine | x | 0, 1 | | 190 | | f_e_outtemp | x | 0, 1 | Outdoor ambient temperature sensor faulty | 191 | | f_e_outtemplow | x | 0, 1 | | 192 | | f_e_push | x | 0, 1 | Communication faulty between WiFi control panel and indoor control panel | 193 | | f_filterclean | x | 0, 1 | Does the filter require cleaning | 194 | | f_humidity | x | Integer | Relative humidity percent | 195 | | f_power_display | x | 0, 1 | | 196 | | f_temp_in | x | Decimal | Environment temperature in Fahrenheit | 197 | | f_voltage | x | Integer | | 198 | | t_backlight | | ON, OFF | Turn the display on/off | 199 | | t_device_info | | 0, 1 | | 200 | | t_display_power | | 0, 1 | | 201 | | t_eco | | OFF, ON | Economy mode | 202 | | t_fan_leftright | | OFF, ON | Horizontal air flow | 203 | | t_fan_mute | | OFF, ON | Quite mode | 204 | | t_fan_power | | OFF, ON | Vertical air flow | 205 | | t_fan_speed | | AUTO, LOWER, LOW, MEDIUM, HIGH, HIGHER | Fan Speed | 206 | | t_ftkt_start | | Integer | | 207 | | t_power | | OFF, ON | Power | 208 | | t_run_mode | | OFF, ON | Double frequency | 209 | | t_setmulti_value | | Integer | | 210 | | t_sleep | | STOP, ONE, TWO, THREE, FOUR | Sleep mode | 211 | | t_temp | | Integer | Temperature in Fahrenheit | 212 | | t_temptype | | CELSIUS, FAHRENHEIT | Displayed temperature unit | 213 | | t_temp_eight | | OFF, ON | Eight heat mode | 214 | | t_temp_heatcold | | OFF, ON | Fast cool heat | 215 | | t_work_mode | | FAN, HEAT, COOL, DRY, AUTO | Work mode | 216 | 217 | ## SmartThings and HomeAssistant support 218 | You will need a groovy script to enable SmartThings integration with the Air Conditioner, through the control server above. 219 | It currently implements the main functionality (turn on/off, AC mode, fan speed, dimmer etc.). 220 | 221 | The groovy file is available [here](devicetypes/deiger/hisense-air-conditioner.src/hisense-air-conditioner.groovy), for download and installation through the [Groovy IDE](https://graph.api.smartthings.com). As I'm continuously improving this script, it would be more efficient to use the IDE's github integration, in order to stay up-to-date. 222 | 223 | HomeAsststant is now fully supported through [MQTT Discovery]. Properly configured devices are auto-configured and populated in the Lovelace dashboard. 224 | 225 | ## Code Contributions 226 | Pull requests are always welcome. 227 | 228 | Please use [YAPF] with the style config defined here to style your code. 229 | Single quotes are used throughout the code-base. Unfortunately YAPF still doesn't support mandating this (support exists in the [fixers branch](https://github.com/google/yapf/tree/fixers)), so please be mindful. 230 | 231 | [HomeAssistant]: https://www.home-assistant.io/ 232 | [MQTT Discovery]: https://www.home-assistant.io/docs/mqtt/discovery/ 233 | [openHAB]: https://www.openhab.org/ 234 | [SmartThings]: https://www.smartthings.com/ 235 | [MQTT]: http://en.wikipedia.org/wiki/Mqtt 236 | [YAPF]: https://github.com/google/yapf 237 | -------------------------------------------------------------------------------- /aircon/aircon.py: -------------------------------------------------------------------------------- 1 | from copy import deepcopy 2 | from dataclasses import dataclass, field, fields 3 | import enum 4 | import logging 5 | import random 6 | import re 7 | import string 8 | import threading 9 | import time 10 | from typing import Any, Callable, Dict, List 11 | import queue 12 | from Crypto.Cipher import AES 13 | 14 | from . import control_value 15 | from .config import Config, Encryption 16 | from .error import Error 17 | from .properties import (AcProperties, AirFlow, AirFlowState, Economy, FanSpeed, FastColdHeat, 18 | FglProperties, FglBProperties, HumidifierProperties, Properties, Power, 19 | AcWorkMode, Quiet, TemperatureUnit, SleepMode) 20 | 21 | 22 | @dataclass(order=True) 23 | class Command: 24 | priority: int 25 | timestamp: int # Aligns equal priority commands in FIFO. 26 | command: Dict = field(compare=False) 27 | updater: Callable = field(compare=False) 28 | 29 | 30 | class Device(object): 31 | 32 | _FGL_DEVICES = re.compile(r'AP-W[ACDF]\dE') 33 | _FGLB_DEVICES = re.compile(r'AP-WB\dE') 34 | _HUMI_DEVICES = re.compile(r'0001-0401-000[12]') 35 | 36 | def __init__(self, config: Dict[str, str], properties: Properties, notifier: Callable[[None], 37 | None]): 38 | self.name = config['name'] 39 | self.app = config['app'] 40 | self.model = config['model'] 41 | self.sw_version = config['sw_version'] 42 | self.mac_address = config['mac_address'] 43 | self.ip_address = config['ip_address'] 44 | self.temp_type = (TemperatureUnit.CELSIUS 45 | if config.get('temp_type') == 'C' else TemperatureUnit.FAHRENHEIT) 46 | self._config = Config(config['lanip_key'], config['lanip_key_id']) 47 | self._properties = properties 48 | self._properties_lock = threading.RLock() 49 | self._queue_listener = notifier 50 | self._available = None 51 | self.topics = {} 52 | self.work_modes = [] 53 | self.fan_modes = [] 54 | 55 | self._next_command_id = 0 56 | 57 | self.commands_queue = queue.PriorityQueue() 58 | self._commands_seq_no = 0 59 | self._commands_seq_no_lock = threading.Lock() 60 | 61 | self._updates_seq_no = 0 62 | self._updates_seq_no_lock = threading.Lock() 63 | 64 | self._property_change_listeners = [] # type List[Callable[[str, Any], None]] 65 | 66 | @classmethod 67 | def create(cls, config: Dict[str, str], notifier: Callable[[None], None]): 68 | model = config['model'] 69 | if cls._FGL_DEVICES.fullmatch(model): 70 | return FglDevice(config, notifier) 71 | if cls._FGLB_DEVICES.fullmatch(model): 72 | return FglBDevice(config, notifier) 73 | if cls._HUMI_DEVICES.fullmatch(model): 74 | return HumidifierDevice(config, notifier) 75 | return AcDevice(config, notifier) 76 | 77 | @property 78 | def is_fahrenheit(self) -> bool: 79 | return self.temp_type == TemperatureUnit.FAHRENHEIT 80 | 81 | @property 82 | def available(self) -> bool: 83 | # Return False if was not set yet. 84 | return self._available or False 85 | 86 | @available.setter 87 | def available(self, value: bool): 88 | if self._available != value: 89 | self._available = value 90 | self._notify_listeners('available', 'online' if value else 'offline', retain=True) 91 | 92 | def add_property_change_listener(self, listener: Callable[[str, Any], None]): 93 | self._property_change_listeners.append(listener) 94 | 95 | def remove_property_change_listener(self, listener: Callable[[str, Any], None]): 96 | self._property_change_listeners.remove(listener) 97 | 98 | def _notify_listeners(self, prop_name: str, value, retain: bool = False): 99 | for listener in self._property_change_listeners: 100 | listener(self.mac_address, prop_name, value, retain) 101 | 102 | def get_all_properties(self) -> Properties: 103 | with self._properties_lock: 104 | return deepcopy(self._properties) 105 | 106 | def get_property(self, name: str): 107 | """Get a stored property (or None if doesn't exist).""" 108 | with self._properties_lock: 109 | return getattr(self._properties, name, None) 110 | 111 | def get_property_type(self, name: str): 112 | return self._properties.get_type(name) 113 | 114 | def update_property(self, name: str, value, notify_value=None) -> None: 115 | """Update the stored properties, if changed.""" 116 | # Update value precision for value sent from the A/C 117 | precision = self._properties.get_precision(name) 118 | if precision != 1: 119 | value = round(value * precision) 120 | 121 | if notify_value is None: 122 | notify_value = value 123 | 124 | with self._properties_lock: 125 | old_value = getattr(self._properties, name) 126 | if value != old_value: 127 | setattr(self._properties, name, value) 128 | # logging.debug('Updated properties: %s' % self._properties) 129 | if name == 't_control_value': 130 | self._update_controlled_properties(value) 131 | self._notify_listeners(name, notify_value) 132 | 133 | def _update_controlled_properties(self, control: int): 134 | raise NotImplementedError() 135 | 136 | def get_command_seq_no(self) -> int: 137 | with self._commands_seq_no_lock: 138 | seq_no = self._commands_seq_no 139 | self._commands_seq_no += 1 140 | return seq_no 141 | 142 | def is_update_valid(self, cur_update_no: int) -> bool: 143 | with self._updates_seq_no_lock: 144 | # Every once in a while the sequence number is zeroed out, so accept it. 145 | if self._updates_seq_no > cur_update_no and cur_update_no > 0: 146 | logging.error('Stale update found %d. Last update used is %d.', cur_update_no, 147 | self._updates_seq_no) 148 | return False # Old update 149 | self._updates_seq_no = cur_update_no 150 | return True 151 | 152 | def queue_command(self, name: str, value) -> None: 153 | if self._properties.get_read_only(name): 154 | raise Error('Cannot update read-only property "{}".'.format(name)) 155 | data_type = self._properties.get_type(name) 156 | 157 | # Device mode is set using t_control_value 158 | if issubclass(data_type, enum.Enum): 159 | data_value = data_type[value] 160 | elif data_type is int and type(value) is str and '.' in value: 161 | # Round rather than fail if the input is a float. 162 | # This is commonly the case for temperatures converted by HA from Celsius. 163 | data_value = round(float(value)) 164 | else: 165 | data_value = data_type(value) 166 | 167 | # If device has set t_control_value it is being controlled by this field. 168 | if name != 't_control_value' and self.get_property('t_control_value') and name != 't_sleep': 169 | self._convert_to_control_value(name, data_value) 170 | return 171 | 172 | typed_value = data_value 173 | if issubclass(data_type, enum.Enum): 174 | data_value = data_value.value 175 | typed_value = data_type[value] 176 | 177 | # Update value precision for value to be sent to the A/C 178 | precision = self._properties.get_precision(name) 179 | if precision != 1: 180 | data_value = round(data_value / precision) 181 | 182 | command = self._build_command(name, data_value) 183 | # There are (usually) no acks on commands, so also queue an update to the 184 | # property, to be run once the command is sent. 185 | property_updater = lambda: self.update_property(name, typed_value) 186 | # Add as a high priority command. 187 | self.commands_queue.put_nowait(Command(10, time.time_ns(), command, property_updater)) 188 | 189 | self._queue_listener() 190 | 191 | def _build_command(self, name: str, data_value: int): 192 | base_type = self._properties.get_base_type(name) 193 | return { 194 | 'properties': [{ 195 | 'property': { 196 | 'base_type': base_type, 197 | 'name': name, 198 | 'value': data_value, 199 | 'id': ''.join(random.choices(string.ascii_letters + string.digits, k=8)), 200 | } 201 | }] 202 | } 203 | 204 | def _convert_to_control_value(self, name: str, value) -> int: 205 | raise NotImplementedError() 206 | 207 | def queue_status(self) -> None: 208 | for data_field in fields(self._properties): 209 | command = { 210 | 'cmds': [{ 211 | 'cmd': { 212 | 'method': 'GET', 213 | 'resource': 'property.json?name=' + data_field.name, 214 | 'uri': '/local_lan/property/datapoint.json', 215 | 'data': '', 216 | 'cmd_id': self._next_command_id, 217 | } 218 | }] 219 | } 220 | self._next_command_id += 1 221 | # Add as a lower-priority command. 222 | self.commands_queue.put_nowait(Command(100, time.time_ns(), command, None)) 223 | self._queue_listener() 224 | 225 | def update_key(self, key: dict) -> dict: 226 | return self._config.update(key) 227 | 228 | def get_app_encryption(self) -> Encryption: 229 | return self._config.app 230 | 231 | def get_dev_encryption(self) -> Encryption: 232 | return self._config.dev 233 | 234 | 235 | class AcDevice(Device): 236 | 237 | def __init__(self, config: Dict[str, str], notifier: Callable[[None], None]): 238 | super().__init__(config, AcProperties(), notifier) 239 | self.topics = { 240 | 'env_temp': 'f_temp_in', 241 | 'fan_speed': 't_fan_speed', 242 | 'work_mode': 't_work_mode', 243 | 'power': 't_power', 244 | 'swing_mode': 't_fan_power', 245 | 'temp': 't_temp' 246 | } 247 | self.work_modes = ['off', 'fan_only', 'heat', 'cool', 'dry', 'auto'] 248 | self.fan_modes = ['auto', 'lower', 'low', 'medium', 'high', 'higher'] 249 | 250 | # @override to add special support for t_power. 251 | def update_property(self, name: str, value) -> None: 252 | with self._properties_lock: 253 | # HomeAssistant expects an 'off' work mode when the AC is off. 254 | notify_value = 'off' if name == 't_work_mode' and self.get_power() == Power.OFF else None 255 | super().update_property(name, value, notify_value) 256 | # HomeAssistant doesn't listen to changes in t_power, so notify also on a t_work_mode change. 257 | if name == 't_power': 258 | work_mode = 'off' if value == Power.OFF else self.get_work_mode() 259 | self._notify_listeners('t_work_mode', work_mode) 260 | 261 | # @override to add special support for t_power. 262 | def queue_command(self, name: str, value) -> None: 263 | # HomeAssistant doesn't have a designated turn on button in climate.mqtt. 264 | # Furthermore, turn_on doesn't send the right command... 265 | if name == 't_work_mode': 266 | if value == 'OFF': 267 | # Pass the command to t_power instead of t_work_mode. 268 | name = 't_power' 269 | else: 270 | # Also turn on the AC (if it hasn't already). 271 | super().queue_command('t_power', 'ON') 272 | 273 | # Run base. 274 | super().queue_command(name, value) 275 | 276 | # Handle turning on FastColdHeat 277 | if name == 't_temp_heatcold' and value == 'ON': 278 | super().queue_command('t_fan_speed', 'AUTO') 279 | super().queue_command('t_fan_mute', 'OFF') 280 | super().queue_command('t_sleep', 'STOP') 281 | super().queue_command('t_temp_eight', 'OFF') 282 | 283 | def get_env_temp(self) -> int: 284 | return self.get_property('f_temp_in') 285 | 286 | def set_power(self, setting: Power) -> None: 287 | control = self.get_property('t_control_value') 288 | control = control_value.clear_up_change_flags(control) 289 | if (control): 290 | control = control_value.set_power(control, setting) 291 | self.queue_command('t_control_value', control) 292 | else: 293 | self.queue_command('t_power', setting) 294 | 295 | def get_power(self) -> Power: 296 | control = self.get_property('t_control_value') 297 | if (control): 298 | return control_value.get_power(control) 299 | else: 300 | return self.get_property('t_power') 301 | 302 | def set_temperature(self, setting: int) -> None: 303 | control = self.get_property('t_control_value') 304 | control = control_value.clear_up_change_flags(control) 305 | if (control): 306 | control = control_value.set_temp(control, setting) 307 | self.queue_command('t_control_value', control) 308 | else: 309 | self.queue_command('t_temp', setting) 310 | 311 | def get_temperature(self) -> int: 312 | control = self.get_property('t_control_value') 313 | if (control): 314 | return control_value.get_temp(control) 315 | else: 316 | return self.get_property('t_temp') 317 | 318 | def set_sleep(self, setting: SleepMode) -> None: 319 | self.queue_command('t_control_value', setting) 320 | 321 | def get_sleep(self) -> SleepMode: 322 | self.get_property('t_sleep') 323 | 324 | def set_work_mode(self, setting: AcWorkMode) -> None: 325 | control = self.get_property('t_control_value') 326 | if (control): 327 | if control_value.get_power(control) == Power.OFF: 328 | control = control_value.set_power(control, Power.ON) 329 | control = control_value.set_work_mode(control, setting) 330 | self.queue_command('t_control_value', control) 331 | else: 332 | self.queue_command('t_work_mode', setting) 333 | 334 | def get_work_mode(self) -> AcWorkMode: 335 | control = self.get_property('t_control_value') 336 | if (control): 337 | return control_value.get_work_mode(control) 338 | else: 339 | return self.get_property('t_work_mode') 340 | 341 | def set_fan_speed(self, setting: FanSpeed) -> None: 342 | control = self.get_property('t_control_value') 343 | control = control_value.clear_up_change_flags(control) 344 | if (control): 345 | control = control_value.set_fan_speed(control, setting) 346 | self.queue_command('t_control_value', control) 347 | else: 348 | self.queue_command('t_fan_speed', setting) 349 | 350 | def get_fan_speed(self) -> FanSpeed: 351 | control = self.get_property('t_control_value') 352 | if (control): 353 | return control_value.get_fan_speed(control) 354 | else: 355 | return self.get_property('t_fan_speed') 356 | 357 | def set_fan_vertical(self, setting: AirFlow) -> None: 358 | control = self.get_property('t_control_value') 359 | control = control_value.clear_up_change_flags(control) 360 | if (control): 361 | control = control_value.set_fan_power(control, setting) 362 | self.queue_command('t_control_value', control) 363 | else: 364 | self.queue_command('t_fan_power', setting) 365 | 366 | def get_fan_vertical(self) -> AirFlow: 367 | control = self.get_property('t_control_value') 368 | if (control): 369 | return control_value.get_fan_power(control) 370 | else: 371 | return self.get_property('t_fan_power') 372 | 373 | def set_fan_horizontal(self, setting: AirFlow) -> None: 374 | control = self.get_property('t_control_value') 375 | control = control_value.clear_up_change_flags(control) 376 | if (control): 377 | control = control_value.set_fan_lr(control, setting) 378 | self.queue_command('t_control_value', control) 379 | else: 380 | self.queue_command('t_fan_leftright', setting) 381 | 382 | def get_fan_horizontal(self) -> AirFlow: 383 | control = self.get_property('t_control_value') 384 | if (control): 385 | return control_value.get_fan_lr(control) 386 | else: 387 | return self.get_property('t_fan_leftright') 388 | 389 | def set_fan_mute(self, setting: Quiet) -> None: 390 | control = self.get_property('t_control_value') 391 | control = control_value.clear_up_change_flags(control) 392 | if (control): 393 | control = control_value.set_fan_mute(control, setting) 394 | self.queue_command('t_control_value', control) 395 | else: 396 | self.queue_command('t_fan_mute', setting) 397 | 398 | def get_fan_mute(self) -> Quiet: 399 | control = self.get_property('t_control_value') 400 | if (control): 401 | return control_value.get_fan_mute(control) 402 | else: 403 | return self.get_property('t_fan_mute') 404 | 405 | def set_fast_heat_cold(self, setting: FastColdHeat): 406 | control = self.get_property('t_control_value') 407 | control = control_value.clear_up_change_flags(control) 408 | if (control): 409 | control = control_value.set_heat_cold(control, setting) 410 | self.queue_command('t_control_value', control) 411 | else: 412 | self.queue_command('t_temp_heatcold', setting) 413 | 414 | def get_fast_heat_cold(self) -> FastColdHeat: 415 | control = self.get_property('t_control_value') 416 | if (control): 417 | return control_value.get_heat_cold(control) 418 | else: 419 | return self.get_property('t_temp_heatcold') 420 | 421 | def set_eco(self, setting: Economy) -> None: 422 | control = self.get_property('t_control_value') 423 | control = control_value.clear_up_change_flags(control) 424 | if (control): 425 | control = control_value.set_eco(control, setting) 426 | self.queue_command('t_control_value', control) 427 | else: 428 | self.queue_command('t_eco', setting) 429 | 430 | def get_eco(self) -> Economy: 431 | control = self.get_property('t_control_value') 432 | if (control): 433 | return control_value.get_eco(control) 434 | else: 435 | return self.get_property('t_eco') 436 | 437 | def set_temptype(self, setting: TemperatureUnit) -> None: 438 | control = self.get_property('t_control_value') 439 | control = control_value.clear_up_change_flags(control) 440 | if (control): 441 | control = control_value.set_temptype(control, setting) 442 | self.queue_command('t_control_value', control) 443 | else: 444 | self.queue_command('t_temptype', setting) 445 | 446 | def get_temptype(self) -> TemperatureUnit: 447 | control = self.get_property('t_control_value') 448 | if (control): 449 | return control_value.get_temptype(control) 450 | else: 451 | return self.get_property('t_temptype') 452 | 453 | def set_swing(self, setting: AirFlowState) -> None: 454 | control = self.get_property("t_control_value") 455 | control = control_value.clear_up_change_flags(control) 456 | if control: 457 | if setting == AirFlowState.OFF: 458 | control = control_value.set_fan_power(control, AirFlow.OFF) 459 | control = control_value.set_fan_lr(control, AirFlow.OFF) 460 | elif setting == AirFlowState.VERTICAL_ONLY: 461 | control = control_value.set_fan_power(control, AirFlow.ON) 462 | control = control_value.set_fan_lr(control, AirFlow.OFF) 463 | elif setting == AirFlowState.HORIZONTAL_ONLY: 464 | control = control_value.set_fan_power(control, AirFlow.OFF) 465 | control = control_value.set_fan_lr(control, AirFlow.ON) 466 | elif setting == AirFlowState.VERTICAL_AND_HORIZONTAL: 467 | control = control_value.set_fan_power(control, AirFlow.ON) 468 | control = control_value.set_fan_lr(control, AirFlow.ON) 469 | self.queue_command("t_control_value", control) 470 | else: 471 | if setting == AirFlowState.OFF: 472 | self.queue_command("t_fan_speed", AirFlow.OFF) 473 | self.queue_command("t_fan_leftright", AirFlow.OFF) 474 | elif setting == AirFlowState.VERTICAL_ONLY: 475 | self.queue_command("t_fan_speed", AirFlow.ON) 476 | self.queue_command("t_fan_leftright", AirFlow.OFF) 477 | elif setting == AirFlowState.HORIZONTAL_ONLY: 478 | self.queue_command("t_fan_speed", AirFlow.OFF) 479 | self.queue_command("t_fan_leftright", AirFlow.ON) 480 | elif setting == AirFlowState.VERTICAL_AND_HORIZONTAL: 481 | self.queue_command("t_fan_speed", AirFlow.ON) 482 | self.queue_command("t_fan_leftright", AirFlow.ON) 483 | 484 | def _convert_to_control_value(self, name: str, value) -> int: 485 | if name == 't_power': 486 | return self.set_power(value) 487 | elif name == 't_fan_speed': 488 | return self.set_fan_speed(value) 489 | elif name == 't_work_mode': 490 | return self.set_work_mode(value) 491 | elif name == 't_temp_heatcold': 492 | return self.set_fast_heat_cold(value) 493 | elif name == 't_eco': 494 | return self.set_eco(value) 495 | elif name == 't_temp': 496 | return self.set_temperature(value) 497 | elif name == 't_fan_power': 498 | return self.set_fan_vertical(value) 499 | elif name == 't_fan_leftright': 500 | return self.set_fan_horizontal(value) 501 | elif name == 't_fan_mute': 502 | return self.set_fan_mute(value) 503 | elif name == 't_temptype': 504 | return self.set_temptype(value) 505 | else: 506 | logging.error('Cannot convert to control value property {}'.format(name)) 507 | raise ValueError() 508 | 509 | def _update_controlled_properties(self, control: int): 510 | power = control_value.get_power(control) 511 | self.update_property('t_power', power) 512 | 513 | fan_speed = control_value.get_fan_speed(control) 514 | self.update_property('t_fan_speed', fan_speed) 515 | 516 | work_mode = control_value.get_work_mode(control) 517 | self.update_property('t_work_mode', work_mode) 518 | 519 | temp_heatcold = control_value.get_heat_cold(control) 520 | self.update_property('t_temp_heatcold', temp_heatcold) 521 | 522 | eco = control_value.get_eco(control) 523 | self.update_property('t_eco', eco) 524 | 525 | temp = control_value.get_temp(control) 526 | self.update_property('t_temp', temp) 527 | 528 | fan_power = control_value.get_fan_power(control) 529 | self.update_property('t_fan_power', fan_power) 530 | 531 | fan_horizontal = control_value.get_fan_lr(control) 532 | self.update_property('t_fan_leftright', fan_horizontal) 533 | 534 | fan_mute = control_value.get_fan_mute(control) 535 | self.update_property('t_fan_mute', fan_mute) 536 | 537 | temptype = control_value.get_temptype(control) 538 | self.update_property('t_temptype', temptype) 539 | 540 | 541 | class FglDevice(Device): 542 | 543 | def __init__(self, config: Dict[str, str], notifier: Callable[[None], None]): 544 | super().__init__(config, FglProperties(), notifier) 545 | self.topics = { 546 | 'fan_speed': 'fan_speed', 547 | 'work_mode': 'operation_mode', 548 | 'swing_mode': 'af_vertical_swing', 549 | 'temp': 'adjust_temperature' 550 | } 551 | self.work_modes = ['off', 'fan_only', 'heat', 'cool', 'dry', 'auto'] 552 | self.fan_modes = ['auto', 'quiet', 'low', 'medium', 'high'] 553 | 554 | 555 | class FglBDevice(Device): 556 | 557 | def __init__(self, config: Dict[str, str], notifier: Callable[[None], None]): 558 | super().__init__(config, FglBProperties(), notifier) 559 | self.topics = { 560 | 'fan_speed': 'fan_speed', 561 | 'work_mode': 'operation_mode', 562 | 'temp': 'adjust_temperature' 563 | } 564 | self.work_modes = ['off', 'fan_only', 'heat', 'cool', 'dry', 'auto'] 565 | self.fan_modes = ['auto', 'quiet', 'low', 'medium', 'high'] 566 | 567 | 568 | class HumidifierDevice(Device): 569 | 570 | def __init__(self, config: Dict[str, str], notifier: Callable[[None], None]): 571 | super().__init__(config, HumidifierProperties(), notifier) 572 | self.topics = {'env_temp': 'temp', 'power': 'switch'} 573 | -------------------------------------------------------------------------------- /aircon/properties.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass, field 2 | from dataclasses_json import dataclass_json 3 | import enum 4 | 5 | 6 | class AirFlowState(enum.IntEnum): 7 | OFF = 0 8 | VERTICAL_ONLY = 1 9 | HORIZONTAL_ONLY = 2 10 | VERTICAL_AND_HORIZONTAL = 3 11 | 12 | 13 | class FanSpeed(enum.IntEnum): 14 | AUTO = 0 15 | LOWER = 5 16 | LOW = 6 17 | MEDIUM = 7 18 | HIGH = 8 19 | HIGHER = 9 20 | 21 | 22 | class SleepMode(enum.IntEnum): 23 | STOP = 0 24 | ONE = 1 25 | TWO = 2 26 | THREE = 3 27 | FOUR = 4 28 | 29 | 30 | class StateMachine(enum.IntEnum): 31 | FANONLY = 0 32 | HEAT = 1 33 | COOL = 2 34 | DRY = 3 35 | AUTO = 4 36 | FAULTSHIELD = 5 37 | POWEROFF = 6 38 | OFFLINE = 7 39 | READONLYSHARED = 8 40 | 41 | 42 | class AcWorkMode(enum.IntEnum): 43 | FAN = 0 44 | HEAT = 1 45 | COOL = 2 46 | DRY = 3 47 | AUTO = 4 48 | 49 | 50 | class AirFlow(enum.Enum): 51 | OFF = 0 52 | ON = 1 53 | 54 | 55 | class DeviceErrorStatus(enum.Enum): 56 | NORMALSTATE = 0 57 | FAULTSTATE = 1 58 | 59 | 60 | class Dimmer(enum.Enum): 61 | ON = 0 62 | OFF = 1 63 | 64 | 65 | class DoubleFrequency(enum.Enum): 66 | OFF = 0 67 | ON = 1 68 | 69 | 70 | class Economy(enum.Enum): 71 | OFF = 0 72 | ON = 1 73 | 74 | 75 | class EightHeat(enum.Enum): 76 | OFF = 0 77 | ON = 1 78 | 79 | 80 | class FastColdHeat(enum.Enum): 81 | OFF = 0 82 | ON = 1 83 | 84 | 85 | class Power(enum.Enum): 86 | OFF = 0 87 | ON = 1 88 | 89 | 90 | class Quiet(enum.Enum): 91 | OFF = 0 92 | ON = 1 93 | 94 | 95 | class TemperatureUnit(enum.Enum): 96 | CELSIUS = 0 97 | FAHRENHEIT = 1 98 | 99 | 100 | class HumidifierWorkMode(enum.Enum): 101 | NORMAL = 0 102 | NIGHTLIGHT = 1 103 | SLEEP = 2 104 | 105 | 106 | class HumidifierWater(enum.Enum): 107 | OK = 0 108 | NO_WATER = 1 109 | 110 | 111 | class Mist(enum.Enum): 112 | SMALL = 1 113 | MIDDLE = 2 114 | BIG = 3 115 | 116 | 117 | class MistState(enum.Enum): 118 | OFF = 0 119 | ON = 1 120 | 121 | 122 | class FglOperationMode(enum.IntEnum): 123 | OFF = 0 124 | ON = 1 125 | AUTO = 2 126 | COOL = 3 127 | DRY = 4 128 | FAN = 5 129 | HEAT = 6 130 | 131 | 132 | class FglFanSpeed(enum.IntEnum): 133 | QUIET = 0 134 | LOW = 1 135 | MEDIUM = 2 136 | HIGH = 3 137 | AUTO = 4 138 | 139 | 140 | class Properties(object): 141 | 142 | @classmethod 143 | def _get_metadata(cls, attr: str): 144 | return cls.__dataclass_fields__[attr].metadata 145 | 146 | @classmethod 147 | def get_type(cls, attr: str): 148 | return cls.__dataclass_fields__[attr].type 149 | 150 | @classmethod 151 | def get_base_type(cls, attr: str): 152 | return cls._get_metadata(attr)['base_type'] 153 | 154 | @classmethod 155 | def get_precision(cls, attr: str): 156 | return cls._get_metadata(attr).get('precision', 1) 157 | 158 | @classmethod 159 | def get_read_only(cls, attr: str): 160 | return cls._get_metadata(attr)['read_only'] 161 | 162 | 163 | @dataclass_json 164 | @dataclass 165 | class AcProperties(Properties): 166 | # ack_cmd: bool = field(default=None, metadata={'base_type': 'boolean', 'read_only': False}) 167 | f_electricity: int = field(default=100, metadata={'base_type': 'integer', 'read_only': True}) 168 | f_e_arkgrille: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 169 | f_e_incoiltemp: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 170 | f_e_incom: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 171 | f_e_indisplay: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 172 | f_e_ineeprom: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 173 | f_e_inele: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 174 | f_e_infanmotor: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 175 | f_e_inhumidity: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 176 | f_e_inkeys: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 177 | f_e_inlow: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 178 | f_e_intemp: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 179 | f_e_invzero: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 180 | f_e_outcoiltemp: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 181 | f_e_outeeprom: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 182 | f_e_outgastemp: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 183 | f_e_outmachine2: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 184 | f_e_outmachine: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 185 | f_e_outtemp: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 186 | f_e_outtemplow: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 187 | f_e_push: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 188 | f_filterclean: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 189 | f_humidity: int = field(default=50, metadata={ 190 | 'base_type': 'integer', 191 | 'read_only': True 192 | }) # Humidity 193 | f_power_display: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': True}) 194 | f_temp_in: float = field(default=81.0, metadata={ 195 | 'base_type': 'decimal', 196 | 'read_only': True 197 | }) # EnvironmentTemperature (Fahrenheit) 198 | f_voltage: int = field(default=0, metadata={'base_type': 'integer', 'read_only': True}) 199 | t_backlight: Dimmer = field(default=Dimmer.OFF, 200 | metadata={ 201 | 'base_type': 'boolean', 202 | 'read_only': False, 203 | 'dataclasses_json': { 204 | 'encoder': lambda x: x.name, 205 | 'decoder': lambda x: Dimmer[x] 206 | } 207 | }) # DimmerStatus 208 | t_control_value: int = field(default=None, metadata={'base_type': 'integer', 'read_only': False}) 209 | t_device_info: bool = field(default=0, metadata={'base_type': 'boolean', 'read_only': False}) 210 | t_display_power: bool = field(default=None, metadata={'base_type': 'boolean', 'read_only': False}) 211 | t_eco: Economy = field(default=Economy.OFF, 212 | metadata={ 213 | 'base_type': 'boolean', 214 | 'read_only': False, 215 | 'dataclasses_json': { 216 | 'encoder': lambda x: x.name, 217 | 'decoder': lambda x: Economy[x] 218 | } 219 | }) 220 | t_fan_leftright: AirFlow = field(default=AirFlow.OFF, 221 | metadata={ 222 | 'base_type': 'boolean', 223 | 'read_only': False, 224 | 'dataclasses_json': { 225 | 'encoder': lambda x: x.name, 226 | 'decoder': lambda x: AirFlow[x] 227 | } 228 | }) # HorizontalAirFlow 229 | t_fan_mute: Quiet = field(default=Quiet.OFF, 230 | metadata={ 231 | 'base_type': 'boolean', 232 | 'read_only': False, 233 | 'dataclasses_json': { 234 | 'encoder': lambda x: x.name, 235 | 'decoder': lambda x: Quiet[x] 236 | } 237 | }) # QuietModeStatus 238 | t_fan_power: AirFlow = field(default=AirFlow.OFF, 239 | metadata={ 240 | 'base_type': 'boolean', 241 | 'read_only': False, 242 | 'dataclasses_json': { 243 | 'encoder': lambda x: x.name, 244 | 'decoder': lambda x: AirFlow[x] 245 | } 246 | }) # VerticalAirFlow 247 | t_fan_speed: FanSpeed = field(default=FanSpeed.AUTO, 248 | metadata={ 249 | 'base_type': 'integer', 250 | 'read_only': False, 251 | 'dataclasses_json': { 252 | 'encoder': lambda x: x.name, 253 | 'decoder': lambda x: FanSpeed[x] 254 | } 255 | }) # FanSpeed 256 | t_ftkt_start: int = field(default=None, metadata={'base_type': 'integer', 'read_only': False}) 257 | t_power: Power = field(default=Power.ON, 258 | metadata={ 259 | 'base_type': 'boolean', 260 | 'read_only': False, 261 | 'dataclasses_json': { 262 | 'encoder': lambda x: x.name, 263 | 'decoder': lambda x: Power[x] 264 | } 265 | }) # PowerStatus 266 | t_run_mode: DoubleFrequency = field(default=DoubleFrequency.OFF, 267 | metadata={ 268 | 'base_type': 'boolean', 269 | 'read_only': False, 270 | 'dataclasses_json': { 271 | 'encoder': lambda x: x.name, 272 | 'decoder': lambda x: DoubleFrequency[x] 273 | } 274 | }) # DoubleFrequency 275 | t_setmulti_value: int = field(default=None, metadata={'base_type': 'integer', 'read_only': False}) 276 | t_sleep: SleepMode = field(default=SleepMode.STOP, 277 | metadata={ 278 | 'base_type': 'integer', 279 | 'read_only': False, 280 | 'dataclasses_json': { 281 | 'encoder': lambda x: x.name, 282 | 'decoder': lambda x: SleepMode[x] 283 | } 284 | }) # SleepMode 285 | t_temp: int = field(default=81, metadata={ 286 | 'base_type': 'integer', 287 | 'read_only': False 288 | }) # CurrentTemperature 289 | t_temptype: TemperatureUnit = field(default=TemperatureUnit.FAHRENHEIT, 290 | metadata={ 291 | 'base_type': 'boolean', 292 | 'read_only': False, 293 | 'dataclasses_json': { 294 | 'encoder': lambda x: x.name, 295 | 'decoder': lambda x: TemperatureUnit[x] 296 | } 297 | }) # CurrentTemperatureUnit 298 | t_temp_eight: EightHeat = field(default=EightHeat.OFF, 299 | metadata={ 300 | 'base_type': 'boolean', 301 | 'read_only': False, 302 | 'dataclasses_json': { 303 | 'encoder': lambda x: x.name, 304 | 'decoder': lambda x: EightHeat[x] 305 | } 306 | }) # EightHeatStatus 307 | t_temp_heatcold: FastColdHeat = field(default=FastColdHeat.OFF, 308 | metadata={ 309 | 'base_type': 'boolean', 310 | 'read_only': False, 311 | 'dataclasses_json': { 312 | 'encoder': lambda x: x.name, 313 | 'decoder': lambda x: FastColdHeat[x] 314 | } 315 | }) # FastCoolHeatStatus 316 | t_work_mode: AcWorkMode = field(default=AcWorkMode.AUTO, 317 | metadata={ 318 | 'base_type': 'integer', 319 | 'read_only': False, 320 | 'dataclasses_json': { 321 | 'encoder': lambda x: x.name, 322 | 'decoder': lambda x: AcWorkMode[x] 323 | } 324 | }) # WorkModeStatus 325 | 326 | 327 | @dataclass_json 328 | @dataclass 329 | class HumidifierProperties(Properties): 330 | humi: int = field(default=0, metadata={'base_type': 'integer', 'read_only': False}) 331 | mist: Mist = field(default=Mist.SMALL, 332 | metadata={ 333 | 'base_type': 'integer', 334 | 'read_only': False, 335 | 'dataclasses_json': { 336 | 'encoder': lambda x: x.name, 337 | 'decoder': lambda x: Mist[x] 338 | } 339 | }) 340 | mistSt: MistState = field(default=MistState.OFF, 341 | metadata={ 342 | 'base_type': 'integer', 343 | 'read_only': True, 344 | 'dataclasses_json': { 345 | 'encoder': lambda x: x.name, 346 | 'decoder': lambda x: MistState[x] 347 | } 348 | }) 349 | realhumi: int = field(default=0, metadata={'base_type': 'integer', 'read_only': True}) 350 | remain: int = field(default=0, metadata={'base_type': 'integer', 'read_only': True}) 351 | switch: Power = field(default=Power.ON, 352 | metadata={ 353 | 'base_type': 'boolean', 354 | 'read_only': False, 355 | 'dataclasses_json': { 356 | 'encoder': lambda x: x.name, 357 | 'decoder': lambda x: Power[x] 358 | } 359 | }) 360 | temp: int = field(default=81, metadata={'base_type': 'integer', 'read_only': True}) 361 | timer: int = field(default=-1, metadata={'base_type': 'integer', 'read_only': False}) 362 | water: HumidifierWater = field(default=HumidifierWater.OK, 363 | metadata={ 364 | 'base_type': 'boolean', 365 | 'read_only': True, 366 | 'dataclasses_json': { 367 | 'encoder': lambda x: x.name, 368 | 'decoder': lambda x: HumidifierWater[x] 369 | } 370 | }) 371 | workmode: HumidifierWorkMode = field(default=HumidifierWorkMode.NORMAL, 372 | metadata={ 373 | 'base_type': 'integer', 374 | 'read_only': False, 375 | 'dataclasses_json': { 376 | 'encoder': lambda x: x.name, 377 | 'decoder': lambda x: HumidifierWorkMode[x] 378 | } 379 | }) 380 | 381 | 382 | @dataclass_json 383 | @dataclass 384 | class FglProperties(Properties): 385 | operation_mode: FglOperationMode = field(default=FglOperationMode.AUTO, 386 | metadata={ 387 | 'base_type': 'integer', 388 | 'read_only': False, 389 | 'dataclasses_json': { 390 | 'encoder': lambda x: x.name, 391 | 'decoder': lambda x: FglOperationMode[x] 392 | } 393 | }) 394 | fan_speed: FglFanSpeed = field(default=FglFanSpeed.AUTO, 395 | metadata={ 396 | 'base_type': 'integer', 397 | 'read_only': False, 398 | 'dataclasses_json': { 399 | 'encoder': lambda x: x.name, 400 | 'decoder': lambda x: FglFanSpeed[x] 401 | } 402 | }) 403 | adjust_temperature: int = field(default=25, 404 | metadata={ 405 | 'base_type': 'integer', 406 | 'precision': 0.1, 407 | 'read_only': False 408 | }) 409 | display_temperature: int = field(default=25, 410 | metadata={ 411 | 'base_type': 'integer', 412 | 'precision': 0.1, 413 | 'read_only': True 414 | }) 415 | af_vertical_direction: int = field(default=3, 416 | metadata={ 417 | 'base_type': 'integer', 418 | 'read_only': False 419 | }) 420 | af_vertical_swing: AirFlow = field(default=AirFlow.OFF, 421 | metadata={ 422 | 'base_type': 'boolean', 423 | 'read_only': False, 424 | 'dataclasses_json': { 425 | 'encoder': lambda x: x.name, 426 | 'decoder': lambda x: AirFlow[x] 427 | } 428 | }) # HorizontalAirFlow 429 | af_horizontal_direction: int = field(default=3, 430 | metadata={ 431 | 'base_type': 'integer', 432 | 'read_only': False 433 | }) 434 | af_horizontal_swing: AirFlow = field(default=AirFlow.OFF, 435 | metadata={ 436 | 'base_type': 'boolean', 437 | 'read_only': False, 438 | 'dataclasses_json': { 439 | 'encoder': lambda x: x.name, 440 | 'decoder': lambda x: AirFlow[x] 441 | } 442 | }) # HorizontalAirFlow 443 | economy_mode: Economy = field(default=Economy.OFF, 444 | metadata={ 445 | 'base_type': 'boolean', 446 | 'read_only': False, 447 | 'dataclasses_json': { 448 | 'encoder': lambda x: x.name, 449 | 'decoder': lambda x: Economy[x] 450 | } 451 | }) 452 | 453 | 454 | @dataclass_json 455 | @dataclass 456 | class FglBProperties(Properties): 457 | operation_mode: FglOperationMode = field(default=FglOperationMode.AUTO, 458 | metadata={ 459 | 'base_type': 'integer', 460 | 'read_only': False, 461 | 'dataclasses_json': { 462 | 'encoder': lambda x: x.name, 463 | 'decoder': lambda x: FglOperationMode[x] 464 | } 465 | }) 466 | fan_speed: FglFanSpeed = field(default=FglFanSpeed.AUTO, 467 | metadata={ 468 | 'base_type': 'integer', 469 | 'read_only': False, 470 | 'dataclasses_json': { 471 | 'encoder': lambda x: x.name, 472 | 'decoder': lambda x: FglFanSpeed[x] 473 | } 474 | }) 475 | adjust_temperature: int = field(default=25, 476 | metadata={ 477 | 'base_type': 'integer', 478 | 'precision': 0.1, 479 | 'read_only': False 480 | }) 481 | display_temperature: int = field(default=25, 482 | metadata={ 483 | 'base_type': 'integer', 484 | 'precision': 0.1, 485 | 'read_only': True 486 | }) 487 | af_vertical_move_step1: int = field(default=3, 488 | metadata={ 489 | 'base_type': 'integer', 490 | 'read_only': False 491 | }) 492 | af_horizontal_move_step1: int = field(default=3, 493 | metadata={ 494 | 'base_type': 'integer', 495 | 'read_only': False 496 | }) 497 | economy_mode: Economy = field(default=Economy.OFF, 498 | metadata={ 499 | 'base_type': 'boolean', 500 | 'read_only': False, 501 | 'dataclasses_json': { 502 | 'encoder': lambda x: x.name, 503 | 'decoder': lambda x: Economy[x] 504 | } 505 | }) 506 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### Changelog 2 | 3 | All notable changes to this project will be documented in this file. Dates are displayed in UTC. 4 | 5 | Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). 6 | 7 | #### [0.3.17](https://github.com/deiger/AirCon/compare/0.3.16...0.3.17) 8 | 9 | > 7 August 2023 10 | 11 | - Add option to change the port for MQTT broker. [`#250`](https://github.com/deiger/AirCon/issues/250) 12 | - Add hismart-us to the Celsius API list. [`#246`](https://github.com/deiger/AirCon/issues/246) [`#142`](https://github.com/deiger/AirCon/issues/142) 13 | 14 | #### [0.3.16](https://github.com/deiger/AirCon/compare/0.3.15...0.3.16) 15 | 16 | > 6 August 2023 17 | 18 | - Remove setting of entity name to None. [`47ee470`](https://github.com/deiger/AirCon/commit/47ee4700f56f8f6c25e16f7a97d48d730add56a4) 19 | 20 | #### [0.3.15](https://github.com/deiger/AirCon/compare/0.3.14...0.3.15) 21 | 22 | > 3 August 2023 23 | 24 | - Bump aiohttp from 3.7.4 to 3.8.5 [`#243`](https://github.com/deiger/AirCon/pull/243) 25 | - Clear the entity name in order to conform with HA 2023.8 [`#248`](https://github.com/deiger/AirCon/issues/248) 26 | - Add a multiarch container to facilitate the build. [`4c2184f`](https://github.com/deiger/AirCon/commit/4c2184fbcd774b816302a7adc3d5d235887a62fc) 27 | 28 | #### [0.3.14](https://github.com/deiger/AirCon/compare/0.3.13...0.3.14) 29 | 30 | > 7 May 2023 31 | 32 | - Update properties.py [`#221`](https://github.com/deiger/AirCon/pull/221) 33 | 34 | #### [0.3.13](https://github.com/deiger/AirCon/compare/0.3.12...0.3.13) 35 | 36 | > 14 March 2023 37 | 38 | - Remove non-mandatory flag from prepopulated null setting. [`edb0a5d`](https://github.com/deiger/AirCon/commit/edb0a5d2a90488aa461158040817f0e973619a80) 39 | 40 | #### [0.3.12](https://github.com/deiger/AirCon/compare/0.3.11...0.3.12) 41 | 42 | > 14 March 2023 43 | 44 | - feat: Add option to specify local ip address to AC units to connect to [`#209`](https://github.com/deiger/AirCon/pull/209) 45 | 46 | #### [0.3.11](https://github.com/deiger/AirCon/compare/0.3.10...0.3.11) 47 | 48 | > 13 March 2023 49 | 50 | - Remove the deprecated power_*_topic. [`#217`](https://github.com/deiger/AirCon/issues/217) 51 | - Upgrade python to 3.10 [`48da9ba`](https://github.com/deiger/AirCon/commit/48da9ba3b3f119288109cdd6bdfc99609213b301) 52 | 53 | #### [0.3.10](https://github.com/deiger/AirCon/compare/0.3.9...0.3.10) 54 | 55 | > 31 January 2022 56 | 57 | - Add t_sleep control [`#128`](https://github.com/deiger/AirCon/pull/128) 58 | - Remove redundant parenthesis [`#93`](https://github.com/deiger/AirCon/issues/93) 59 | - Accomodate A/C `f_votage` typo [`#108`](https://github.com/deiger/AirCon/issues/108) 60 | - Explicitly create tasks for asyncio.wait [`#107`](https://github.com/deiger/AirCon/issues/107) 61 | - Bump paho-mqtt version to 1.6.1 [`21d9d00`](https://github.com/deiger/AirCon/commit/21d9d005f11ec91167a63c5785016f8e4d0c73c9) 62 | 63 | #### [0.3.9](https://github.com/deiger/AirCon/compare/0.3.8...0.3.9) 64 | 65 | > 14 March 2021 66 | 67 | - Bump aiohttp from 3.6.2 to 3.7.4 [`#86`](https://github.com/deiger/AirCon/pull/86) 68 | - Set the temperature precision for fglair to 0.1. [`#85`](https://github.com/deiger/AirCon/issues/85) 69 | - Update the A/C availability only on change. [`#83`](https://github.com/deiger/AirCon/issues/83) 70 | - Removed default app info, since it seems to override user data [`3fd0b7d`](https://github.com/deiger/AirCon/commit/3fd0b7d93cc87177981a90e65ab84f8c1dcd6516) 71 | - 0.3.8.2 [`544f7d0`](https://github.com/deiger/AirCon/commit/544f7d06721f56f9a022f1b12a772655933bd4d1) 72 | - 0.3.8.1 [`5a975c9`](https://github.com/deiger/AirCon/commit/5a975c9d6a614c900bbb14d2622d0a47091b75a4) 73 | 74 | #### [0.3.8](https://github.com/deiger/AirCon/compare/0.3.7...0.3.8) 75 | 76 | > 9 February 2021 77 | 78 | - bug fixes [`#81`](https://github.com/deiger/AirCon/pull/81) 79 | - Prefer user generated commands to periodical status updates. [`834fab2`](https://github.com/deiger/AirCon/commit/834fab200b2e358cf3d2600d39cbfd1d089c68a3) 80 | - Fix retry mechanism. [`f09a891`](https://github.com/deiger/AirCon/commit/f09a89165b31ff3a5535769e50ea30cbf658e2be) 81 | - Fixed: status query now runs async for each device - faster [`f5bfc51`](https://github.com/deiger/AirCon/commit/f5bfc51410f3eaa844b8f3d95a44dc0dfb0c69ce) 82 | 83 | #### [0.3.7](https://github.com/deiger/AirCon/compare/0.3.6...0.3.7) 84 | 85 | > 30 January 2021 86 | 87 | - Full changelog [`c338d92`](https://github.com/deiger/AirCon/commit/c338d926fff68abc31b1b3e51bb2068fe002042b) 88 | - Run keep_alive concurrently, and don't over-retry failing A/Cs [`95b36f0`](https://github.com/deiger/AirCon/commit/95b36f0b90b59939abb0a7c8922cd3f73e098097) 89 | - Convert ClientConnectorError to the internal error. [`b09bb61`](https://github.com/deiger/AirCon/commit/b09bb611c805f1e436ec520ec7d07ef87af7d50b) 90 | 91 | #### [0.3.6](https://github.com/deiger/AirCon/compare/0.3.5...0.3.6) 92 | 93 | > 15 January 2021 94 | 95 | - Fixed syntax glich bug [`#69`](https://github.com/deiger/AirCon/pull/69) 96 | - Bug fix. [`#67`](https://github.com/deiger/AirCon/issues/67) 97 | - Update docs about the use of add-on store. [`450117d`](https://github.com/deiger/AirCon/commit/450117dc110110d16748b4dcaa186678f7749fd4) 98 | - Add documentation for HA add-on. [`103b975`](https://github.com/deiger/AirCon/commit/103b9753eac974afd9b4130a1ab4761daba8ddc9) 99 | - Make get_property return None on invalid property. [`6261752`](https://github.com/deiger/AirCon/commit/62617526c416558ce38a8bdf3e0857f966635bfa) 100 | 101 | #### [0.3.5](https://github.com/deiger/AirCon/compare/0.3.4...0.3.5) 102 | 103 | > 13 January 2021 104 | 105 | - Move device type selection logic into the a model-based selection. [`1ef749f`](https://github.com/deiger/AirCon/commit/1ef749f5742ea87021b14a01273e4be14592d415) 106 | - Add support for discovery in FGLair. [`cc053c0`](https://github.com/deiger/AirCon/commit/cc053c03b2ff7dbba42248c3f32fdfab71b10a7e) 107 | - Fix docker-compose, make it copy the current config.json. [`6f6a337`](https://github.com/deiger/AirCon/commit/6f6a3375d32d7de9fb292e33907865a38d55ee2f) 108 | 109 | #### [0.3.4](https://github.com/deiger/AirCon/compare/0.3.3...0.3.4) 110 | 111 | > 12 January 2021 112 | 113 | - Fix HA config schema. [`#66`](https://github.com/deiger/AirCon/issues/66) 114 | - Install jq if it doesn't exist. [`2b51c88`](https://github.com/deiger/AirCon/commit/2b51c884bb4f5dc7bf114bd1776111a39bfe6a3e) 115 | 116 | #### [0.3.3](https://github.com/deiger/AirCon/compare/0.3.2...0.3.3) 117 | 118 | > 11 January 2021 119 | 120 | - Fix the docker compose volume. [`#65`](https://github.com/deiger/AirCon/issues/65) 121 | - Refactor the docker config to use HA-style options. [`68411b0`](https://github.com/deiger/AirCon/commit/68411b07eb3608d9a1d5c24cae1f352ebd6a9917) 122 | - Add HA readme. [`26eb247`](https://github.com/deiger/AirCon/commit/26eb2473834f8f1098680eb0ccde989862481a53) 123 | - Move the HA add-on config to a dedicated dir. [`3f5f526`](https://github.com/deiger/AirCon/commit/3f5f5261026746c26a0537ed35ad562a9a94ff82) 124 | 125 | #### [0.3.2](https://github.com/deiger/AirCon/compare/0.3.1...0.3.2) 126 | 127 | > 10 January 2021 128 | 129 | - Add change log. [`cec1056`](https://github.com/deiger/AirCon/commit/cec1056aa36e6911a3b07ebae7ac26706c536f49) 130 | - Avoid mandating a device IP when not needed. [`1808de3`](https://github.com/deiger/AirCon/commit/1808de3ed56afed42c9b4e0299288ba2f0bfe4d2) 131 | - Move the logo into the subdir. [`6daf129`](https://github.com/deiger/AirCon/commit/6daf129bb1d11442fd72646fddb814a34969630e) 132 | 133 | #### [0.3.1](https://github.com/deiger/AirCon/compare/0.3.0...0.3.1) 134 | 135 | > 10 January 2021 136 | 137 | - Handle the availability of each A/C on its own. [`8afbf4b`](https://github.com/deiger/AirCon/commit/8afbf4be02c79e57ed89a9c0a54f928a0303cd97) 138 | - Fix the HA add ons store config. [`1127fd9`](https://github.com/deiger/AirCon/commit/1127fd9e942dcc112dc6b56b17a4e27e1db83f3d) 139 | - Fix the config for HA addon. [`029fc9a`](https://github.com/deiger/AirCon/commit/029fc9a23cca4b986369f849d75404c221fd3cab) 140 | 141 | #### [0.3.0](https://github.com/deiger/AirCon/compare/0.2.14...0.3.0) 142 | 143 | > 9 January 2021 144 | 145 | - Fix: allow keep alive error to continue to the next device [`#61`](https://github.com/deiger/AirCon/pull/61) 146 | - Update README.md [`956fdf3`](https://github.com/deiger/AirCon/commit/956fdf35f009a0b711d9cb232977522badf55967) 147 | - Create configuration for HA addon. [`b4273b4`](https://github.com/deiger/AirCon/commit/b4273b43831e956b8f20c6fb038f794274978316) 148 | - Fixed: moved queues_empty = True to where it was [`dcdb756`](https://github.com/deiger/AirCon/commit/dcdb7565476c0f756428a82701f2cc1525551a96) 149 | 150 | #### [0.2.14](https://github.com/deiger/AirCon/compare/0.2.13...0.2.14) 151 | 152 | > 8 January 2021 153 | 154 | - Properly handle t_power vs t_work_mode merge in HA. [`ef0ca94`](https://github.com/deiger/AirCon/commit/ef0ca9412bdd4ccf779a3514cc94a6f229a7a227) 155 | - Use info rather than error in empty data response from the AC. [`34aaa87`](https://github.com/deiger/AirCon/commit/34aaa8763802736c87236e4a7c565e37a30b12da) 156 | - Properly handle t_power vs t_work_mode merge in HA. [`aeb2b2c`](https://github.com/deiger/AirCon/commit/aeb2b2c924ef4d62772d348544767462874c8b5d) 157 | 158 | #### [0.2.13](https://github.com/deiger/AirCon/compare/0.2.12...0.2.13) 159 | 160 | > 8 January 2021 161 | 162 | - Dockerfile support [`#55`](https://github.com/deiger/AirCon/pull/55) 163 | - Dockerfile [`e3e722a`](https://github.com/deiger/AirCon/commit/e3e722ad52358515edbf0a5237109bb7a49b81c0) 164 | - Add reason data to the response on error. [`65c334d`](https://github.com/deiger/AirCon/commit/65c334d4202256b8fa0d4d1ff1542a6c373d2bd9) 165 | - Docker: Added support for config volume [`46131c1`](https://github.com/deiger/AirCon/commit/46131c1fcabcbb339854eeebde02339c70f7c3fc) 166 | 167 | #### [0.2.12](https://github.com/deiger/AirCon/compare/0.2.11...0.2.12) 168 | 169 | > 6 January 2021 170 | 171 | - Propagate `temp_type` to config. [`#54`](https://github.com/deiger/AirCon/issues/54) 172 | - Fetch MAC address from network as fallback. [`ec9b1a9`](https://github.com/deiger/AirCon/commit/ec9b1a942e54859c5ece21439e871944a24f7d3b) 173 | 174 | #### [0.2.11](https://github.com/deiger/AirCon/compare/0.2.10...0.2.11) 175 | 176 | > 6 January 2021 177 | 178 | - Dockerfile [`e3e722a`](https://github.com/deiger/AirCon/commit/e3e722ad52358515edbf0a5237109bb7a49b81c0) 179 | - Added log_level to Dockerfile env [`85ea281`](https://github.com/deiger/AirCon/commit/85ea281b61d3e75746ee8d30bd12f531ccbfd929) 180 | 181 | #### [0.2.10](https://github.com/deiger/AirCon/compare/0.2.9...0.2.10) 182 | 183 | > 5 January 2021 184 | 185 | - Add `temp_type=C` to the AC config, for a predefined set of apps. [`#54`](https://github.com/deiger/AirCon/issues/54) 186 | - Bug fix. [`58d12e7`](https://github.com/deiger/AirCon/commit/58d12e79da70efce013a0bb4e28ac2acefe6d675) 187 | - Tiny bug fix. [`c1e2bd1`](https://github.com/deiger/AirCon/commit/c1e2bd1a9def008acfa6a5a85f85bf228d549caf) 188 | 189 | #### [0.2.9](https://github.com/deiger/AirCon/compare/0.2.8...0.2.9) 190 | 191 | > 29 December 2020 192 | 193 | - Update documentation for `--type` and remove `--ip`. [`#48`](https://github.com/deiger/AirCon/issues/48) 194 | - Get the right TimeoutError exception for asyncio, as it moved in Python3.8 [`#47`](https://github.com/deiger/AirCon/issues/47) 195 | - Turn AC on on mode change (mitigate HA bug). [`#26`](https://github.com/deiger/AirCon/issues/26) 196 | - Syntax fix [`df839f1`](https://github.com/deiger/AirCon/commit/df839f133aee19456f0c8fc08063559cb2fcac23) 197 | 198 | #### [0.2.8](https://github.com/deiger/AirCon/compare/0.2.7...0.2.8) 199 | 200 | > 28 December 2020 201 | 202 | - Code formatting, using yapf. [`8b26064`](https://github.com/deiger/AirCon/commit/8b2606402471d5345723e36ae5efc019d8f784a0) 203 | 204 | #### [0.2.7](https://github.com/deiger/AirCon/compare/0.2.6...0.2.7) 205 | 206 | > 28 December 2020 207 | 208 | - Refactoring. [`9f557f6`](https://github.com/deiger/AirCon/commit/9f557f628bd4d6342f0d541fe6103931ef409615) 209 | 210 | #### [0.2.6](https://github.com/deiger/AirCon/compare/0.2.5...0.2.6) 211 | 212 | > 28 December 2020 213 | 214 | - Clean up control_value code. [`8156fcd`](https://github.com/deiger/AirCon/commit/8156fcd501f29882f4f7b6107107cc461c46add9) 215 | - Fix the discovery code, reported in #46. [`3b6627e`](https://github.com/deiger/AirCon/commit/3b6627e3760a27e918524bb18f800d6a6430b52d) 216 | 217 | #### [0.2.5](https://github.com/deiger/AirCon/compare/0.2.4...0.2.5) 218 | 219 | > 27 December 2020 220 | 221 | - Add discovery for HomeAssistant, auto-generating Lovelace. Also fix the code, that was broken by 044375d. [`e0cfd67`](https://github.com/deiger/AirCon/commit/e0cfd67b53455f3659474fe9fbd95c32fc35c1bf) 222 | - Reference the newly added MQTT discovery support [`cbfd6e8`](https://github.com/deiger/AirCon/commit/cbfd6e83a4f83d13a60255e2ffe8b3c3a1b24d11) 223 | - chmod [`d8630cd`](https://github.com/deiger/AirCon/commit/d8630cdda7895c0d336d204a33d0206c2dd78e91) 224 | 225 | #### [0.2.4](https://github.com/deiger/AirCon/compare/0.2.3...0.2.4) 226 | 227 | > 13 October 2020 228 | 229 | - Decouple project [`#29`](https://github.com/deiger/AirCon/pull/29) 230 | - Apply changes after review [`9e628ee`](https://github.com/deiger/AirCon/commit/9e628ee491f78c17cd2714ee3330440318ad4696) 231 | 232 | #### [0.2.3](https://github.com/deiger/AirCon/compare/0.2.2...0.2.3) 233 | 234 | > 28 September 2020 235 | 236 | - Add support for async [`04b36c7`](https://github.com/deiger/AirCon/commit/04b36c7b554af28f1cab804ea42713ceb3d3e7b8) 237 | - Remove not needed import [`c3ee99e`](https://github.com/deiger/AirCon/commit/c3ee99e7318e596dd14342aa9dac0bb344f7a0e0) 238 | - Migrate to aiohttp [`83ed9a6`](https://github.com/deiger/AirCon/commit/83ed9a65fc825e90f77412792158b2edb23daa00) 239 | 240 | #### [0.2.2](https://github.com/deiger/AirCon/compare/0.2.1...0.2.2) 241 | 242 | > 13 July 2020 243 | 244 | - Remove Data class [`9a151e8`](https://github.com/deiger/AirCon/commit/9a151e83860eec66295c91b96640275016aa21a7) 245 | - Add getters and setters to AcDevice [`3f0933c`](https://github.com/deiger/AirCon/commit/3f0933c44208f9403078dbf53f7f243da35fea1c) 246 | - Allow multiple devices at once [`250d8d3`](https://github.com/deiger/AirCon/commit/250d8d370e7713eb097bca6cf797d132527fc6f7) 247 | 248 | #### [0.2.1](https://github.com/deiger/AirCon/compare/0.2.0...0.2.1) 249 | 250 | > 10 July 2020 251 | 252 | - Added discovery command [`a8a5df1`](https://github.com/deiger/AirCon/commit/a8a5df132504e21c1f05593c0aa91abdd4fdae78) 253 | - Fix small issues [`3bd7439`](https://github.com/deiger/AirCon/commit/3bd7439ee7e70fc4711f572b0274791302354de7) 254 | - Fix build [`c902896`](https://github.com/deiger/AirCon/commit/c902896d653bc85d9b97f42bd689037e4f255e0b) 255 | 256 | #### [0.2.0](https://github.com/deiger/AirCon/compare/0.1.21...0.2.0) 257 | 258 | > 6 July 2020 259 | 260 | - Copy files for refactoring. [`756c58c`](https://github.com/deiger/AirCon/commit/756c58cdce014a764fe7a9bdc3acfdf89608bb2d) 261 | - Remove some of the duplicated code [`eba31d2`](https://github.com/deiger/AirCon/commit/eba31d24b8317f09c1628c0738575085b706feb5) 262 | - Decouple [`f905db9`](https://github.com/deiger/AirCon/commit/f905db94cc690edf0459767d7e782e923392cf73) 263 | 264 | #### [0.1.21](https://github.com/deiger/AirCon/compare/0.1.20...0.1.21) 265 | 266 | > 17 July 2020 267 | 268 | - Error messages [`9bc46d9`](https://github.com/deiger/AirCon/commit/9bc46d97edba5e07c86f70a0568f28e8f4e8a948) 269 | - Explicitly shut down the http server on reg error. [`ffb2690`](https://github.com/deiger/AirCon/commit/ffb26909784ae3645d2ba37829f84bcfaff33fc6) 270 | - Exit on failure to send local_reg keep alive. [`3b6b4ae`](https://github.com/deiger/AirCon/commit/3b6b4aec24328436516abfaf1876bf0540881635) 271 | 272 | #### [0.1.20](https://github.com/deiger/AirCon/compare/0.1.19...0.1.20) 273 | 274 | > 14 June 2020 275 | 276 | - Add support for FGL devices [`6166f18`](https://github.com/deiger/AirCon/commit/6166f188b05573451595615d35dcd996fa111014) 277 | - Separate FGL and FGL-B modules [`e11b224`](https://github.com/deiger/AirCon/commit/e11b2246111056ad2cd9059d422d5ae8116be54b) 278 | - Document the support for FGLair [`f16f97d`](https://github.com/deiger/AirCon/commit/f16f97d9e845debfb674915b9c2441b76fe25a71) 279 | 280 | #### [0.1.19](https://github.com/deiger/AirCon/compare/0.1.18...0.1.19) 281 | 282 | > 4 June 2020 283 | 284 | - Add retry for local_reg [`473dc54`](https://github.com/deiger/AirCon/commit/473dc54e5b0229c50f079c549a807a9db6f3ea42) 285 | - Do not reuse the socket between retries. [`66e4ae2`](https://github.com/deiger/AirCon/commit/66e4ae22fa3dfe7a3fbb3348b527673da20df1ad) 286 | - Fix handling of connection [`85933c2`](https://github.com/deiger/AirCon/commit/85933c2f2198178c255690b128186109e76a1b07) 287 | 288 | #### [0.1.18](https://github.com/deiger/AirCon/compare/0.1.17...0.1.18) 289 | 290 | > 1 June 2020 291 | 292 | - Publish an update for new subscribers [`2f2ca59`](https://github.com/deiger/AirCon/commit/2f2ca59fbece64e78217a1d591eeb4c595deae82) 293 | - Add section for multiple A/Cs [`5869222`](https://github.com/deiger/AirCon/commit/58692225b38228b4cac48f91d5f4fde5a32f0042) 294 | - Accept (and round) float temperatures. [`6b08a35`](https://github.com/deiger/AirCon/commit/6b08a35581d95e47d20272ed3f1f44bc7ac65255) 295 | 296 | #### [0.1.17](https://github.com/deiger/AirCon/compare/0.1.16...0.1.17) 297 | 298 | > 31 May 2020 299 | 300 | - Compare enum values by identity [`#19`](https://github.com/deiger/AirCon/issues/19) 301 | - Configuration for Home Assistant [`f2d0245`](https://github.com/deiger/AirCon/commit/f2d02455d9f57febb1795bdb269a5a6b55b2d615) 302 | - Document the HomeAssistant support. [`90d35d4`](https://github.com/deiger/AirCon/commit/90d35d49ba97cf965ee591ba6bdbe437a39bab98) 303 | - Remove value_template, as JSON isn't used [`5adba58`](https://github.com/deiger/AirCon/commit/5adba5893e74c4e8aaaffaca6b18982f155a0c30) 304 | 305 | #### [0.1.16](https://github.com/deiger/AirCon/compare/0.1.15...0.1.16) 306 | 307 | > 12 May 2020 308 | 309 | - Add support for Fujitsu FGLair [`7946404`](https://github.com/deiger/AirCon/commit/79464042cf7c6fb2340b6fafc00af6459114ace3) 310 | - Add support for FGLair [`6055378`](https://github.com/deiger/AirCon/commit/6055378ee55cc8d5bd17e0520b5386288040d7c7) 311 | 312 | #### [0.1.15](https://github.com/deiger/AirCon/compare/0.1.14...0.1.15) 313 | 314 | > 5 May 2020 315 | 316 | - Move to separate topics per property [`187928b`](https://github.com/deiger/AirCon/commit/187928ba5f80b5a42a6b9750f90b712629d8226d) 317 | - Handle decimal temp [`813d6a4`](https://github.com/deiger/AirCon/commit/813d6a41fb01534f7e4570c924cae18169bed49a) 318 | - Add logging for incoming MQTT messages. [`e5b992d`](https://github.com/deiger/AirCon/commit/e5b992df5f5b41294bea328183a6cb7888ea6372) 319 | 320 | #### [0.1.14](https://github.com/deiger/AirCon/compare/0.1.13...0.1.14) 321 | 322 | > 27 April 2020 323 | 324 | - Set broadcast flags for socket on IP discovery [`00347c5`](https://github.com/deiger/AirCon/commit/00347c5018b3c4c0d0dc398334d0d774bb752782) 325 | 326 | #### [0.1.13](https://github.com/deiger/AirCon/compare/0.1.12...0.1.13) 327 | 328 | > 22 April 2020 329 | 330 | - Add an option to print the properties [`7faec95`](https://github.com/deiger/AirCon/commit/7faec957907b02efd9a88cb0ca740cedc0832b70) 331 | - More explicit warning for unsupported properties [`761f773`](https://github.com/deiger/AirCon/commit/761f773ed470035602ca367c0c98a550e281b3ba) 332 | 333 | #### [0.1.12](https://github.com/deiger/AirCon/compare/0.1.11...0.1.12) 334 | 335 | > 17 March 2020 336 | 337 | - Support gzipped response. [`57870f9`](https://github.com/deiger/AirCon/commit/57870f9cec1c9ddf3435f24aa3c38f2af9e37194) 338 | - Print the data when failing to parse JSON. [`bdeedf3`](https://github.com/deiger/AirCon/commit/bdeedf37199950dabb3f173796116466dc482831) 339 | - Return deleted newlines [`c3aed6e`](https://github.com/deiger/AirCon/commit/c3aed6efb0a6c299f80414272d507739b2097f23) 340 | 341 | #### [0.1.11](https://github.com/deiger/AirCon/compare/0.1.10...0.1.11) 342 | 343 | > 28 January 2020 344 | 345 | - Update documentation [`0536d89`](https://github.com/deiger/AirCon/commit/0536d89341f46107c17b880a0245d8d440b4ae64) 346 | - Add support for Denali Aire [`f417a2a`](https://github.com/deiger/AirCon/commit/f417a2a0a6ca9fed0cde9849d7f68cb6ee554b11) 347 | - Add support for HiSmart Home and AI-Home [`92691a3`](https://github.com/deiger/AirCon/commit/92691a31598840b194297f1600015e89e509801c) 348 | 349 | #### [0.1.10](https://github.com/deiger/AirCon/compare/0.1.9...0.1.10) 350 | 351 | > 12 January 2020 352 | 353 | - Add support for hismartinternationalforandroid [`f952489`](https://github.com/deiger/AirCon/commit/f952489a1598277c89dc5d8ce567ebc6cdd5810f) 354 | - Update app name [`848ef55`](https://github.com/deiger/AirCon/commit/848ef55997d92626afe6091a6d8c700f481b8f51) 355 | - Add support for hismartinternationalforandroid [`591a7ae`](https://github.com/deiger/AirCon/commit/591a7aea0151f7282c9e55cbb215dc0cc618a80b) 356 | 357 | #### [0.1.9](https://github.com/deiger/AirCon/compare/0.1.8...0.1.9) 358 | 359 | > 16 December 2019 360 | 361 | - Add support for humidifiers, that use the same protocol [`50910cb`](https://github.com/deiger/AirCon/commit/50910cbee04f5c11969a102af3495178a4406138) 362 | - Add enums for humidifiers [`8432a0f`](https://github.com/deiger/AirCon/commit/8432a0fd2c36c99ed6f3e439ad97bf59fc6b97a8) 363 | - Update the CLI to handle SunHome [`cffd837`](https://github.com/deiger/AirCon/commit/cffd837e543b67256e9bf6ffa9362c871d0f9df1) 364 | 365 | #### [0.1.8](https://github.com/deiger/AirCon/compare/0.1.7...0.1.8) 366 | 367 | > 15 October 2019 368 | 369 | - Properly handle logging on Windows [`e0abbf7`](https://github.com/deiger/AirCon/commit/e0abbf70fa25c3838c3616f6fbabb5fe43ee649a) 370 | - Add missing import. [`c2cc7c4`](https://github.com/deiger/AirCon/commit/c2cc7c4ac65e5138ec93ac963ec36c2e531a2b7b) 371 | 372 | #### [0.1.7](https://github.com/deiger/AirCon/compare/0.1.6...0.1.7) 373 | 374 | > 12 October 2019 375 | 376 | - Accommodate zeroed sequence number [`a62810e`](https://github.com/deiger/AirCon/commit/a62810e139247f94f40643f9a4693d14556eebe0) 377 | - Use the regional servers for each different app. [`c710fcd`](https://github.com/deiger/AirCon/commit/c710fcd55222cf2e3c1edbf15b1c9962c9834829) 378 | - Make the CLI error include the HTTP failure reason [`773046a`](https://github.com/deiger/AirCon/commit/773046a0ca276fae5a3ca2ebda5a6a96deef2df8) 379 | 380 | #### [0.1.6](https://github.com/deiger/AirCon/compare/0.1.5...0.1.6) 381 | 382 | > 13 September 2019 383 | 384 | - First version of the ST device handler. [`e3b537d`](https://github.com/deiger/AirCon/commit/e3b537d31675d101caae70144a703402f8c97b2f) 385 | - Fix indentation issues. [`96b733e`](https://github.com/deiger/AirCon/commit/96b733e0a5643c99cd03a76cb204ff039419a973) 386 | - Stability updates [`cc3bb94`](https://github.com/deiger/AirCon/commit/cc3bb94027a5fb8267fcf4ff149ff6f9bc2e5f33) 387 | 388 | #### [0.1.5](https://github.com/deiger/AirCon/compare/0.1.4...0.1.5) 389 | 390 | > 9 September 2019 391 | 392 | - Periodically update all properties [`e3c264e`](https://github.com/deiger/AirCon/commit/e3c264e3fc0806daafb00c3e617d8d1b2cd7279d) 393 | - Get the current state for all properties at startup [`bdb74d5`](https://github.com/deiger/AirCon/commit/bdb74d59a503b1da2a6f1efcd8d49568ad17f1bc) 394 | - Update the list of apps based on Xinlianfeng [`9940f19`](https://github.com/deiger/AirCon/commit/9940f19b3830a6ad021a65d93e2dd087469a5010) 395 | 396 | #### [0.1.4](https://github.com/deiger/AirCon/compare/0.1.3...0.1.4) 397 | 398 | > 8 September 2019 399 | 400 | - Update README.md [`7cf4827`](https://github.com/deiger/AirCon/commit/7cf482768854cfdf0efcc36ff1b975a4414d76e3) 401 | - Handle apps with non-standard prefix [`ecff1ba`](https://github.com/deiger/AirCon/commit/ecff1ba7ac11bec1287c74362cc05dc7847b50fa) 402 | - Update the list of supported and unsupported apps [`73b7c39`](https://github.com/deiger/AirCon/commit/73b7c39097e688cfe5862d7c0515561534e077bb) 403 | 404 | #### [0.1.3](https://github.com/deiger/AirCon/compare/0.1.2...0.1.3) 405 | 406 | > 7 September 2019 407 | 408 | - Publish to MQTT only the updated property [`fe92ff4`](https://github.com/deiger/AirCon/commit/fe92ff44b4932d81cb912c96f37573c8e6676835) 409 | - Bug fixes [`bd26103`](https://github.com/deiger/AirCon/commit/bd26103ee1e89853d7678644bda4e21bddc34410) 410 | - Bug fixes [`353782c`](https://github.com/deiger/AirCon/commit/353782c8e0b59d5d486a4b3caeeb9f4d596c0c88) 411 | 412 | #### [0.1.2](https://github.com/deiger/AirCon/compare/0.1.1...0.1.2) 413 | 414 | > 5 September 2019 415 | 416 | - Properly handle all properties [`7314c32`](https://github.com/deiger/AirCon/commit/7314c32c30b44ca2440d1bbf6dc9ce2efeec211a) 417 | - Switch to strings in enum values [`383bfe7`](https://github.com/deiger/AirCon/commit/383bfe784d5ae5123f5a507ce2b9587e3fa480a2) 418 | - Update README.md [`26b8121`](https://github.com/deiger/AirCon/commit/26b81217b6c94a438cbe4cd3258e2c1dd18fe089) 419 | 420 | #### [0.1.1](https://github.com/deiger/AirCon/compare/0.1.0...0.1.1) 421 | 422 | > 4 September 2019 423 | 424 | - Script to query HiSense servers [`28af9ba`](https://github.com/deiger/AirCon/commit/28af9ba8a0eee9f2367c3ffa73e97bd287d4ee74) 425 | - Update README.md [`b5a558c`](https://github.com/deiger/AirCon/commit/b5a558cd69204d6a38faa23c3adfbb427d19d145) 426 | - Documentation for CLI usage [`eb02ffa`](https://github.com/deiger/AirCon/commit/eb02ffac0d8e50e22b51c6724bf752be8c280fc1) 427 | 428 | #### 0.1.0 429 | 430 | > 11 August 2019 431 | 432 | - Create LICENSE [`48fd9f4`](https://github.com/deiger/AirCon/commit/48fd9f47b8b7f543fa50a4944715b9b75d835ea7) 433 | - Initial version for HiSense AC module [`e5306eb`](https://github.com/deiger/AirCon/commit/e5306ebd72b2ab4ad008cb90a70275276750327e) 434 | - Create README.md [`a5301cb`](https://github.com/deiger/AirCon/commit/a5301cbff6833fa2bec475b49c555e12f42d05a0) 435 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------