Skip to content

Commit

Permalink
Merge pull request #66829 from home-assistant/rc
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Feb 18, 2022
2 parents e3a2b51 + 15ca244 commit c95a72d
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 20 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/frontend/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Home Assistant Frontend",
"documentation": "https://www.home-assistant.io/integrations/frontend",
"requirements": [
"home-assistant-frontend==20220203.0"
"home-assistant-frontend==20220203.1"
],
"dependencies": [
"api",
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hue/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Philips Hue",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/hue",
"requirements": ["aiohue==4.2.0"],
"requirements": ["aiohue==4.2.1"],
"ssdp": [
{
"manufacturer": "Royal Philips Electronics",
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/insteon/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Insteon",
"documentation": "https://www.home-assistant.io/integrations/insteon",
"requirements": [
"pyinsteon==1.0.14"
"pyinsteon==1.0.16"
],
"codeowners": [
"@teharris1"
Expand Down
14 changes: 14 additions & 0 deletions homeassistant/components/samsungtv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from homeassistant.exceptions import ConfigEntryNotReady
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
from homeassistant.util.async_ import run_callback_threadsafe

from .bridge import (
SamsungTVBridge,
Expand Down Expand Up @@ -117,6 +118,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# Initialize bridge
bridge = await _async_create_bridge_with_updated_data(hass, entry)

# Ensure new token gets saved against the config_entry
def _update_token() -> None:
"""Update config entry with the new token."""
hass.config_entries.async_update_entry(
entry, data={**entry.data, CONF_TOKEN: bridge.token}
)

def new_token_callback() -> None:
"""Update config entry with the new token."""
run_callback_threadsafe(hass.loop, _update_token)

bridge.register_new_token_callback(new_token_callback)

def stop_bridge(event: Event) -> None:
"""Stop SamsungTV bridge connection."""
bridge.stop()
Expand Down
25 changes: 18 additions & 7 deletions homeassistant/components/samsungtv/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,16 @@ def __init__(self, method: str, host: str, port: int | None = None) -> None:
self.host = host
self.token: str | None = None
self._remote: Remote | None = None
self._callback: CALLBACK_TYPE | None = None
self._reauth_callback: CALLBACK_TYPE | None = None
self._new_token_callback: CALLBACK_TYPE | None = None

def register_reauth_callback(self, func: CALLBACK_TYPE) -> None:
"""Register a callback function."""
self._callback = func
self._reauth_callback = func

def register_new_token_callback(self, func: CALLBACK_TYPE) -> None:
"""Register a callback function."""
self._new_token_callback = func

@abstractmethod
def try_connect(self) -> str | None:
Expand Down Expand Up @@ -176,10 +181,15 @@ def close_remote(self) -> None:
except OSError:
LOGGER.debug("Could not establish connection")

def _notify_callback(self) -> None:
def _notify_reauth_callback(self) -> None:
"""Notify access denied callback."""
if self._callback is not None:
self._callback()
if self._reauth_callback is not None:
self._reauth_callback()

def _notify_new_token_callback(self) -> None:
"""Notify new token callback."""
if self._new_token_callback is not None:
self._new_token_callback()


class SamsungTVLegacyBridge(SamsungTVBridge):
Expand Down Expand Up @@ -245,7 +255,7 @@ def _get_remote(self, avoid_open: bool = False) -> Remote:
# This is only happening when the auth was switched to DENY
# A removed auth will lead to socket timeout because waiting for auth popup is just an open socket
except AccessDenied:
self._notify_callback()
self._notify_reauth_callback()
raise
except (ConnectionClosed, OSError):
pass
Expand Down Expand Up @@ -355,7 +365,7 @@ def _get_remote(self, avoid_open: bool = False) -> Remote:
# This is only happening when the auth was switched to DENY
# A removed auth will lead to socket timeout because waiting for auth popup is just an open socket
except ConnectionFailure:
self._notify_callback()
self._notify_reauth_callback()
except (WebSocketException, OSError):
self._remote = None
else:
Expand All @@ -365,6 +375,7 @@ def _get_remote(self, avoid_open: bool = False) -> Remote:
self._remote.token,
)
self.token = self._remote.token
self._notify_new_token_callback()
return self._remote

def stop(self) -> None:
Expand Down
7 changes: 7 additions & 0 deletions homeassistant/components/tuya/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,13 @@ def current_temperature(self) -> float | None:
if temperature is None:
return None

if self._current_temperature.scale == 0 and self._current_temperature.step != 1:
# The current temperature can have a scale of 0 or 1 and is used for
# rounding, Home Assistant doesn't need to round but we will always
# need to divide the value by 10^1 in case of 0 as scale.
# https://developer.tuya.com/en/docs/iot/shift-temperature-scale-follow-the-setting-of-app-account-center?id=Ka9qo7so58efq#title-7-Round%20values
temperature = temperature / 10

return self._current_temperature.scale_value(temperature)

@property
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/webostv/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def async_send_message(self, message: str = "", **kwargs: Any) -> None:
await self._client.connect()

data = kwargs.get(ATTR_DATA)
icon_path = data.get(CONF_ICON, "") if data else None
icon_path = data.get(CONF_ICON) if data else None
await self._client.send_message(message, icon_path=icon_path)
except WebOsTvPairError:
_LOGGER.error("Pairing with TV failed")
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

MAJOR_VERSION: Final = 2022
MINOR_VERSION: Final = 2
PATCH_VERSION: Final = "8"
PATCH_VERSION: Final = "9"
__short_version__: Final = f"{MAJOR_VERSION}.{MINOR_VERSION}"
__version__: Final = f"{__short_version__}.{PATCH_VERSION}"
REQUIRED_PYTHON_VER: Final[tuple[int, int, int]] = (3, 9, 0)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/package_constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ciso8601==2.2.0
cryptography==35.0.0
emoji==1.6.3
hass-nabucasa==0.52.0
home-assistant-frontend==20220203.0
home-assistant-frontend==20220203.1
httpx==0.21.3
ifaddr==0.1.7
jinja2==3.0.3
Expand Down
6 changes: 3 additions & 3 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ aiohomekit==0.6.11
aiohttp_cors==0.7.0

# homeassistant.components.hue
aiohue==4.2.0
aiohue==4.2.1

# homeassistant.components.homewizard
aiohwenergy==0.8.0
Expand Down Expand Up @@ -842,7 +842,7 @@ hole==0.7.0
holidays==0.12

# homeassistant.components.frontend
home-assistant-frontend==20220203.0
home-assistant-frontend==20220203.1

# homeassistant.components.zwave
homeassistant-pyozw==0.1.10
Expand Down Expand Up @@ -1582,7 +1582,7 @@ pyialarm==1.9.0
pyicloud==0.10.2

# homeassistant.components.insteon
pyinsteon==1.0.14
pyinsteon==1.0.16

# homeassistant.components.intesishome
pyintesishome==1.7.6
Expand Down
6 changes: 3 additions & 3 deletions requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ aiohomekit==0.6.11
aiohttp_cors==0.7.0

# homeassistant.components.hue
aiohue==4.2.0
aiohue==4.2.1

# homeassistant.components.homewizard
aiohwenergy==0.8.0
Expand Down Expand Up @@ -543,7 +543,7 @@ hole==0.7.0
holidays==0.12

# homeassistant.components.frontend
home-assistant-frontend==20220203.0
home-assistant-frontend==20220203.1

# homeassistant.components.zwave
homeassistant-pyozw==0.1.10
Expand Down Expand Up @@ -987,7 +987,7 @@ pyialarm==1.9.0
pyicloud==0.10.2

# homeassistant.components.insteon
pyinsteon==1.0.14
pyinsteon==1.0.16

# homeassistant.components.ipma
pyipma==2.0.5
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = homeassistant
version = 2022.2.8
version = 2022.2.9
author = The Home Assistant Authors
author_email = hello@home-assistant.io
license = Apache-2.0
Expand Down
15 changes: 15 additions & 0 deletions tests/components/webostv/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ async def test_notify(hass, client):
assert client.connect.call_count == 1
client.send_message.assert_called_with(MESSAGE, icon_path=ICON_PATH)

await hass.services.async_call(
NOTIFY_DOMAIN,
TV_NAME,
{
ATTR_MESSAGE: MESSAGE,
CONF_SERVICE_DATA: {
"OTHER_DATA": "not_used",
},
},
blocking=True,
)
assert client.mock_calls[0] == call.connect()
assert client.connect.call_count == 1
client.send_message.assert_called_with(MESSAGE, icon_path=None)


async def test_notify_not_connected(hass, client, monkeypatch):
"""Test sending a message when client is not connected."""
Expand Down

0 comments on commit c95a72d

Please sign in to comment.