From 5a24dbf599862c5b04e1f288e1a537353c8cdb39 Mon Sep 17 00:00:00 2001 From: Felipe Martins Diel <41558831+felipediel@users.noreply.github.com> Date: Mon, 2 Dec 2019 18:20:36 -0300 Subject: [PATCH] Broadlink remote (#26528) * Add broadlink remote control platform * Fix order of the imports * Add remote.py to .coveragerc * Optimize MAC address validation * Use storage helper class and improve code readability * Add me to the manifest as a code owner * Fix dosctring * Add me to the code owners * Remove storage schemas, rename storage keys and improve readability --- .coveragerc | 1 + CODEOWNERS | 2 +- .../components/broadlink/__init__.py | 27 ++ .../components/broadlink/manifest.json | 3 +- homeassistant/components/broadlink/remote.py | 349 ++++++++++++++++++ 5 files changed, 380 insertions(+), 2 deletions(-) create mode 100644 homeassistant/components/broadlink/remote.py diff --git a/.coveragerc b/.coveragerc index 600701d792b..7f519f8970a 100644 --- a/.coveragerc +++ b/.coveragerc @@ -94,6 +94,7 @@ omit = homeassistant/components/bom/sensor.py homeassistant/components/bom/weather.py homeassistant/components/braviatv/media_player.py + homeassistant/components/broadlink/remote.py homeassistant/components/broadlink/sensor.py homeassistant/components/broadlink/switch.py homeassistant/components/brottsplatskartan/sensor.py diff --git a/CODEOWNERS b/CODEOWNERS index cb86e5c0c90..e859a9d0eac 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -50,7 +50,7 @@ homeassistant/components/bizkaibus/* @UgaitzEtxebarria homeassistant/components/blink/* @fronzbot homeassistant/components/bmw_connected_drive/* @gerard33 homeassistant/components/braviatv/* @robbiet480 -homeassistant/components/broadlink/* @danielhiversen +homeassistant/components/broadlink/* @danielhiversen @felipediel homeassistant/components/brunt/* @eavanvalkenburg homeassistant/components/bt_smarthub/* @jxwolstenholme homeassistant/components/buienradar/* @mjj4791 @ties diff --git a/homeassistant/components/broadlink/__init__.py b/homeassistant/components/broadlink/__init__.py index 589da62feaa..521cd68780c 100644 --- a/homeassistant/components/broadlink/__init__.py +++ b/homeassistant/components/broadlink/__init__.py @@ -1,7 +1,9 @@ """The broadlink component.""" import asyncio from base64 import b64decode, b64encode +from binascii import unhexlify import logging +import re import socket from datetime import timedelta @@ -27,6 +29,31 @@ def data_packet(value): return b64decode(value) +def hostname(value): + """Validate a hostname.""" + host = str(value).lower() + if len(host) > 253: + raise ValueError + if host[-1] == ".": + host = host[:-1] + allowed = re.compile(r"(?!-)[a-z\d-]{1,63}(?