Merge pull request #55753 from home-assistant/rc

This commit is contained in:
Paulus Schoutsen 2021-09-04 14:51:15 -07:00 committed by GitHub
commit df9a899bbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 63 deletions

View File

@ -9,6 +9,7 @@ from fritzconnection.core.exceptions import (
FritzActionError, FritzActionError,
FritzActionFailedError, FritzActionFailedError,
FritzConnectionException, FritzConnectionException,
FritzInternalError,
FritzServiceError, FritzServiceError,
) )
from fritzconnection.lib.fritzstatus import FritzStatus from fritzconnection.lib.fritzstatus import FritzStatus
@ -273,7 +274,12 @@ async def async_setup_entry(
"GetInfo", "GetInfo",
) )
dsl = dslinterface["NewEnable"] dsl = dslinterface["NewEnable"]
except (FritzActionError, FritzActionFailedError, FritzServiceError): except (
FritzInternalError,
FritzActionError,
FritzActionFailedError,
FritzServiceError,
):
pass pass
for sensor_type, sensor_data in SENSOR_DATA.items(): for sensor_type, sensor_data in SENSOR_DATA.items():

View File

@ -3,7 +3,7 @@
"name": "LIFX", "name": "LIFX",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/lifx", "documentation": "https://www.home-assistant.io/integrations/lifx",
"requirements": ["aiolifx==0.6.10", "aiolifx_effects==0.2.2"], "requirements": ["aiolifx==0.7.0", "aiolifx_effects==0.2.2"],
"homekit": { "homekit": {
"models": ["LIFX"] "models": ["LIFX"]
}, },

View File

@ -54,7 +54,7 @@ async def async_get_type(hass, cloud_id, install_code, host):
meters = await hub.get_device_list() meters = await hub.get_device_list()
except aioeagle.BadAuth as err: except aioeagle.BadAuth as err:
raise InvalidAuth from err raise InvalidAuth from err
except aiohttp.ClientError: except (KeyError, aiohttp.ClientError):
# This can happen if it's an eagle-100 # This can happen if it's an eagle-100
meters = None meters = None

View File

@ -240,7 +240,8 @@ class SamsungTVLegacyBridge(SamsungTVBridge):
def _send_key(self, key): def _send_key(self, key):
"""Send the key using legacy protocol.""" """Send the key using legacy protocol."""
self._get_remote().control(key) if remote := self._get_remote():
remote.control(key)
def stop(self): def stop(self):
"""Stop Bridge.""" """Stop Bridge."""
@ -315,7 +316,8 @@ class SamsungTVWSBridge(SamsungTVBridge):
"""Send the key using websocket protocol.""" """Send the key using websocket protocol."""
if key == "KEY_POWEROFF": if key == "KEY_POWEROFF":
key = "KEY_POWER" key = "KEY_POWER"
self._get_remote().send_key(key) if remote := self._get_remote():
remote.send_key(key)
def _get_remote(self, avoid_open: bool = False): def _get_remote(self, avoid_open: bool = False):
"""Create or return a remote control instance.""" """Create or return a remote control instance."""

View File

@ -129,13 +129,6 @@ def _get_entities(hass: HomeAssistant) -> list[tuple[str, str, str | None]]:
return entity_ids return entity_ids
# Faster than try/except
# From https://stackoverflow.com/a/23639915
def _is_number(s: str) -> bool: # pylint: disable=invalid-name
"""Return True if string is a number."""
return s.replace(".", "", 1).isdigit()
def _time_weighted_average( def _time_weighted_average(
fstates: list[tuple[float, State]], start: datetime.datetime, end: datetime.datetime fstates: list[tuple[float, State]], start: datetime.datetime, end: datetime.datetime
) -> float: ) -> float:
@ -190,9 +183,13 @@ def _normalize_states(
if device_class not in UNIT_CONVERSIONS: if device_class not in UNIT_CONVERSIONS:
# We're not normalizing this device class, return the state as they are # We're not normalizing this device class, return the state as they are
fstates = [ fstates = []
(float(el.state), el) for el in entity_history if _is_number(el.state) for state in entity_history:
] try:
fstates.append((float(state.state), state))
except ValueError:
continue
if fstates: if fstates:
all_units = _get_units(fstates) all_units = _get_units(fstates)
if len(all_units) > 1: if len(all_units) > 1:
@ -220,23 +217,22 @@ def _normalize_states(
fstates = [] fstates = []
for state in entity_history: for state in entity_history:
# Exclude non numerical states from statistics try:
if not _is_number(state.state): fstate = float(state.state)
continue unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
# Exclude unsupported units from statistics
if unit not in UNIT_CONVERSIONS[device_class]:
if WARN_UNSUPPORTED_UNIT not in hass.data:
hass.data[WARN_UNSUPPORTED_UNIT] = set()
if entity_id not in hass.data[WARN_UNSUPPORTED_UNIT]:
hass.data[WARN_UNSUPPORTED_UNIT].add(entity_id)
_LOGGER.warning("%s has unknown unit %s", entity_id, unit)
continue
fstate = float(state.state) fstates.append((UNIT_CONVERSIONS[device_class][unit](fstate), state))
unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) except ValueError:
# Exclude unsupported units from statistics
if unit not in UNIT_CONVERSIONS[device_class]:
if WARN_UNSUPPORTED_UNIT not in hass.data:
hass.data[WARN_UNSUPPORTED_UNIT] = set()
if entity_id not in hass.data[WARN_UNSUPPORTED_UNIT]:
hass.data[WARN_UNSUPPORTED_UNIT].add(entity_id)
_LOGGER.warning("%s has unknown unit %s", entity_id, unit)
continue continue
fstates.append((UNIT_CONVERSIONS[device_class][unit](fstate), state))
return DEVICE_CLASS_UNITS[device_class], fstates return DEVICE_CLASS_UNITS[device_class], fstates

View File

@ -5,7 +5,7 @@ from typing import Final
MAJOR_VERSION: Final = 2021 MAJOR_VERSION: Final = 2021
MINOR_VERSION: Final = 9 MINOR_VERSION: Final = 9
PATCH_VERSION: Final = "2" PATCH_VERSION: Final = "3"
__short_version__: Final = f"{MAJOR_VERSION}.{MINOR_VERSION}" __short_version__: Final = f"{MAJOR_VERSION}.{MINOR_VERSION}"
__version__: Final = f"{__short_version__}.{PATCH_VERSION}" __version__: Final = f"{__short_version__}.{PATCH_VERSION}"
REQUIRED_PYTHON_VER: Final[tuple[int, int, int]] = (3, 8, 0) REQUIRED_PYTHON_VER: Final[tuple[int, int, int]] = (3, 8, 0)

View File

@ -201,7 +201,7 @@ aiokafka==0.6.0
aiokef==0.2.16 aiokef==0.2.16
# homeassistant.components.lifx # homeassistant.components.lifx
aiolifx==0.6.10 aiolifx==0.7.0
# homeassistant.components.lifx # homeassistant.components.lifx
aiolifx_effects==0.2.2 aiolifx_effects==0.2.2

View File

@ -50,18 +50,18 @@ GAS_SENSOR_ATTRIBUTES = {
@pytest.mark.parametrize( @pytest.mark.parametrize(
"device_class,unit,native_unit,mean,min,max", "device_class,unit,native_unit,mean,min,max",
[ [
(None, "%", "%", 16.440677, 10, 30), (None, "%", "%", 13.050847, -10, 30),
("battery", "%", "%", 16.440677, 10, 30), ("battery", "%", "%", 13.050847, -10, 30),
("battery", None, None, 16.440677, 10, 30), ("battery", None, None, 13.050847, -10, 30),
("humidity", "%", "%", 16.440677, 10, 30), ("humidity", "%", "%", 13.050847, -10, 30),
("humidity", None, None, 16.440677, 10, 30), ("humidity", None, None, 13.050847, -10, 30),
("pressure", "Pa", "Pa", 16.440677, 10, 30), ("pressure", "Pa", "Pa", 13.050847, -10, 30),
("pressure", "hPa", "Pa", 1644.0677, 1000, 3000), ("pressure", "hPa", "Pa", 1305.0847, -1000, 3000),
("pressure", "mbar", "Pa", 1644.0677, 1000, 3000), ("pressure", "mbar", "Pa", 1305.0847, -1000, 3000),
("pressure", "inHg", "Pa", 55674.53, 33863.89, 101591.67), ("pressure", "inHg", "Pa", 44195.25, -33863.89, 101591.67),
("pressure", "psi", "Pa", 113354.48, 68947.57, 206842.71), ("pressure", "psi", "Pa", 89982.42, -68947.57, 206842.71),
("temperature", "°C", "°C", 16.440677, 10, 30), ("temperature", "°C", "°C", 13.050847, -10, 30),
("temperature", "°F", "°C", -8.644068, -12.22222, -1.111111), ("temperature", "°F", "°C", -10.52731, -23.33333, -1.111111),
], ],
) )
def test_compile_hourly_statistics( def test_compile_hourly_statistics(
@ -155,8 +155,8 @@ def test_compile_hourly_statistics_unsupported(hass_recorder, caplog, attributes
{ {
"statistic_id": "sensor.test1", "statistic_id": "sensor.test1",
"start": process_timestamp_to_utc_isoformat(zero), "start": process_timestamp_to_utc_isoformat(zero),
"mean": approx(16.440677966101696), "mean": approx(13.050847),
"min": approx(10.0), "min": approx(-10.0),
"max": approx(30.0), "max": approx(30.0),
"last_reset": None, "last_reset": None,
"state": None, "state": None,
@ -167,8 +167,8 @@ def test_compile_hourly_statistics_unsupported(hass_recorder, caplog, attributes
{ {
"statistic_id": "sensor.test6", "statistic_id": "sensor.test6",
"start": process_timestamp_to_utc_isoformat(zero), "start": process_timestamp_to_utc_isoformat(zero),
"mean": approx(16.440677966101696), "mean": approx(13.050847),
"min": approx(10.0), "min": approx(-10.0),
"max": approx(30.0), "max": approx(30.0),
"last_reset": None, "last_reset": None,
"state": None, "state": None,
@ -179,8 +179,8 @@ def test_compile_hourly_statistics_unsupported(hass_recorder, caplog, attributes
{ {
"statistic_id": "sensor.test7", "statistic_id": "sensor.test7",
"start": process_timestamp_to_utc_isoformat(zero), "start": process_timestamp_to_utc_isoformat(zero),
"mean": approx(16.440677966101696), "mean": approx(13.050847),
"min": approx(10.0), "min": approx(-10.0),
"max": approx(30.0), "max": approx(30.0),
"last_reset": None, "last_reset": None,
"state": None, "state": None,
@ -988,10 +988,10 @@ def test_list_statistic_ids_unsupported(hass_recorder, caplog, _attributes):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"device_class,unit,native_unit,mean,min,max", "device_class,unit,native_unit,mean,min,max",
[ [
(None, None, None, 16.440677, 10, 30), (None, None, None, 13.050847, -10, 30),
(None, "%", "%", 16.440677, 10, 30), (None, "%", "%", 13.050847, -10, 30),
("battery", "%", "%", 16.440677, 10, 30), ("battery", "%", "%", 13.050847, -10, 30),
("battery", None, None, 16.440677, 10, 30), ("battery", None, None, 13.050847, -10, 30),
], ],
) )
def test_compile_hourly_statistics_changing_units_1( def test_compile_hourly_statistics_changing_units_1(
@ -1074,10 +1074,10 @@ def test_compile_hourly_statistics_changing_units_1(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"device_class,unit,native_unit,mean,min,max", "device_class,unit,native_unit,mean,min,max",
[ [
(None, None, None, 16.440677, 10, 30), (None, None, None, 13.050847, -10, 30),
(None, "%", "%", 16.440677, 10, 30), (None, "%", "%", 13.050847, -10, 30),
("battery", "%", "%", 16.440677, 10, 30), ("battery", "%", "%", 13.050847, -10, 30),
("battery", None, None, 16.440677, 10, 30), ("battery", None, None, 13.050847, -10, 30),
], ],
) )
def test_compile_hourly_statistics_changing_units_2( def test_compile_hourly_statistics_changing_units_2(
@ -1119,10 +1119,10 @@ def test_compile_hourly_statistics_changing_units_2(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"device_class,unit,native_unit,mean,min,max", "device_class,unit,native_unit,mean,min,max",
[ [
(None, None, None, 16.440677, 10, 30), (None, None, None, 13.050847, -10, 30),
(None, "%", "%", 16.440677, 10, 30), (None, "%", "%", 13.050847, -10, 30),
("battery", "%", "%", 16.440677, 10, 30), ("battery", "%", "%", 13.050847, -10, 30),
("battery", None, None, 16.440677, 10, 30), ("battery", None, None, 13.050847, -10, 30),
], ],
) )
def test_compile_hourly_statistics_changing_units_3( def test_compile_hourly_statistics_changing_units_3(
@ -1203,7 +1203,7 @@ def test_compile_hourly_statistics_changing_units_3(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"device_class,unit,native_unit,mean,min,max", "device_class,unit,native_unit,mean,min,max",
[ [
(None, None, None, 16.440677, 10, 30), (None, None, None, 13.050847, -10, 30),
], ],
) )
def test_compile_hourly_statistics_changing_statistics( def test_compile_hourly_statistics_changing_statistics(
@ -1309,7 +1309,7 @@ def record_states(hass, zero, entity_id, attributes):
states = {entity_id: []} states = {entity_id: []}
with patch("homeassistant.components.recorder.dt_util.utcnow", return_value=one): with patch("homeassistant.components.recorder.dt_util.utcnow", return_value=one):
states[entity_id].append(set_state(entity_id, "10", attributes=attributes)) states[entity_id].append(set_state(entity_id, "-10", attributes=attributes))
with patch("homeassistant.components.recorder.dt_util.utcnow", return_value=two): with patch("homeassistant.components.recorder.dt_util.utcnow", return_value=two):
states[entity_id].append(set_state(entity_id, "15", attributes=attributes)) states[entity_id].append(set_state(entity_id, "15", attributes=attributes))