Skip to content

Commit

Permalink
Merge pull request #350 from ikalchev/v3.5.1
Browse files Browse the repository at this point in the history
V3.5.1
  • Loading branch information
ikalchev authored Jul 4, 2021
2 parents a2a5ce1 + 51fe7cf commit 5178c0d
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.5, 3.6, 3.7, 3.8, 3.9, "3.10.0-alpha.5"]
python-version: [3.6, 3.7, 3.8, 3.9, "3.10.0-alpha.5"]

steps:
- uses: actions/checkout@v1
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ Sections
### Developers
-->

## [3.5.1] - 2021-07-04

# Changed
- Bumped zeroconf to 0.32. [#351](https://github.com/ikalchev/HAP-python/pull/351)

# Fixed
- Handle additional cases of invalid hostnames. [#348](https://github.com/ikalchev/HAP-python/pull/348)

# Breaking Changes
- Python 3.5 is no longer supported. [#354](https://github.com/ikalchev/HAP-python/pull/354)

## [3.5.0] - 2021-05-31

# Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ in [the accessories folder](accessories). See how to configure your camera in

## Installation <a name="Installation"></a>

As of version 2.0.0, HAP-python no longer supports python older than 3.5, because we
As of version 3.5.1, HAP-python no longer supports python older than 3.6, because we
are moving to asyncio. If your platform does not have a compatible python out of the
box, you can install it manually or just use an older version of HAP-python.

Expand Down
24 changes: 23 additions & 1 deletion pyhap/accessory_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
SERVICE_IIDS = "iids"
HAP_SERVICE_TYPE = "_hap._tcp.local."
VALID_MDNS_REGEX = re.compile(r"[^A-Za-z0-9\-]+")
LEADING_TRAILING_SPACE_DASH = re.compile(r"^[ -]+|[ -]+$")
DASH_REGEX = re.compile(r"[-]+")


class AccessoryMDNSServiceInfo(ServiceInfo):
Expand All @@ -77,9 +79,15 @@ def __init__(self, accessory, state):
self.state.mac[-8:].replace(":", ""),
HAP_SERVICE_TYPE,
)
server = "{}-{}.{}".format(
self._valid_host_name(),
self.state.mac[-8:].replace(":", ""),
"local.",
)
super().__init__(
HAP_SERVICE_TYPE,
name=name,
server=server,
port=self.state.port,
weight=0,
priority=0,
Expand All @@ -88,7 +96,21 @@ def __init__(self, accessory, state):
)

def _valid_name(self):
return re.sub(VALID_MDNS_REGEX, " ", self.accessory.display_name).strip()
return re.sub(
LEADING_TRAILING_SPACE_DASH,
"",
re.sub(VALID_MDNS_REGEX, " ", self.accessory.display_name),
)

def _valid_host_name(self):
return re.sub(
DASH_REGEX,
"-",
re.sub(VALID_MDNS_REGEX, " ", self.accessory.display_name)
.strip()
.replace(" ", "-")
.strip("-"),
)

def _setup_hash(self):
setup_hash_material = self.state.setup_id + self.state.mac
Expand Down
2 changes: 1 addition & 1 deletion pyhap/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""This module contains constants used by other modules."""
MAJOR_VERSION = 3
MINOR_VERSION = 5
PATCH_VERSION = 0
PATCH_VERSION = 1
__short_version__ = "{}.{}".format(MAJOR_VERSION, MINOR_VERSION)
__version__ = "{}.{}".format(__short_version__, PATCH_VERSION)
REQUIRED_PYTHON_VER = (3, 5)
Expand Down
2 changes: 1 addition & 1 deletion pyhap/hap_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
HAP_REPR_STATUS,
HAP_SERVER_STATUS,
)
import pyhap.tlv as tlv
from pyhap import tlv
from pyhap.util import long_to_bytes

from .hap_crypto import hap_hkdf, pad_tls_nonce
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'curve25519-donna',
'ed25519',
'cryptography',
'zeroconf>=0.30.0',
'zeroconf>=0.32.0',
'h11'
]

Expand Down
37 changes: 37 additions & 0 deletions tests/test_accessory_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ def test_mdns_service_info(driver):
mdns_info = AccessoryMDNSServiceInfo(acc, state)
assert mdns_info.type == "_hap._tcp.local."
assert mdns_info.name == "Test Accessory 000000._hap._tcp.local."
assert mdns_info.server == "Test-Accessory-000000.local."
assert mdns_info.port == port
assert mdns_info.addresses == [b"\xac\x00\x00\x01"]
assert mdns_info.properties == {
Expand All @@ -610,6 +611,42 @@ def test_mdns_service_info(driver):
}


@pytest.mark.parametrize(
"accessory_name, mdns_name, mdns_server",
[
(
"--h a p p y--",
"h a p p y AbcDEF._hap._tcp.local.",
"h-a-p-p-y-AbcDEF.local.",
),
(
"--H A P P Y--",
"H A P P Y AbcDEF._hap._tcp.local.",
"H-A-P-P-Y-AbcDEF.local.",
),
(
"- - H---A---P---P---Y - -",
"H---A---P---P---Y AbcDEF._hap._tcp.local.",
"H-A-P-P-Y-AbcDEF.local.",
),
],
)
def test_mdns_name_sanity(driver, accessory_name, mdns_name, mdns_server):
"""Test mdns name sanity."""
acc = Accessory(driver, accessory_name)
driver.add_accessory(acc)
addr = "172.0.0.1"
mac = "00:00:00:Ab:cD:EF"
pin = b"123-45-678"
port = 11111
state = State(address=addr, mac=mac, pincode=pin, port=port)
state.setup_id = "abc"
mdns_info = AccessoryMDNSServiceInfo(acc, state)
assert mdns_info.type == "_hap._tcp.local."
assert mdns_info.name == mdns_name
assert mdns_info.server == mdns_server


@pytest.mark.asyncio
async def test_start_service_and_update_config(async_zeroconf):
"""Test starting service and updating the config."""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import ed25519

import pyhap.encoder as encoder
from pyhap import encoder
from pyhap.state import State
from pyhap.util import generate_mac

Expand Down
2 changes: 1 addition & 1 deletion tests/test_hap_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pyhap import hap_handler
from pyhap.accessory import Accessory, Bridge
from pyhap.characteristic import CharacteristicError
import pyhap.tlv as tlv
from pyhap import tlv

CLIENT_UUID = UUID("7d0d1ee9-46fe-4a56-a115-69df3f6860c1")
PUBLIC_KEY = b"\x99\x98d%\x8c\xf6h\x06\xfa\x85\x9f\x90\x82\xf2\xe8\x18\x9f\xf8\xc75\x1f>~\xc32\xc1OC\x13\xbfH\xad"
Expand Down

0 comments on commit 5178c0d

Please sign in to comment.