1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-29 22:24:26 +00:00

Feature/fix unit tests (#1129)

This commit is contained in:
Peter Kuehne
2020-07-14 12:11:58 +01:00
committed by GitHub
parent c8a4eb426c
commit 2012c769f6
4 changed files with 56 additions and 52 deletions

View File

@@ -104,7 +104,7 @@ def alphanumeric(value):
raise Invalid("string value is None")
value = str(value)
if not value.isalnum():
raise Invalid("string value is not alphanumeric")
raise Invalid(f"{value} is not alphanumeric")
return value

View File

@@ -24,15 +24,18 @@ class EsphomeError(Exception):
class HexInt(int):
def __str__(self):
if 0 <= self <= 255:
return f"0x{self:02X}"
return f"0x{self:X}"
value = self
sign = "-" if value < 0 else ""
value = abs(value)
if 0 <= value <= 255:
return f"{sign}0x{value:02X}"
return f"{sign}0x{value:X}"
class IPAddress:
def __init__(self, *args):
if len(args) != 4:
raise ValueError("IPAddress must consist up 4 items")
raise ValueError("IPAddress must consist of 4 items")
self.args = args
def __str__(self):