10000 2022.6.5 by balloob · Pull Request #73334 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

2022.6.5 #73334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 10, 2022
Merged

2022.6.5 #73334

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions homeassistant/components/feedreader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self, url, scan_interval, max_entries, hass, storage):
self._last_entry_timestamp = None
self._last_update_successful = False
self._has_published_parsed = False
self._has_updated_parsed = False
self._event_type = EVENT_FEEDREADER
self._feed_id = url
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, lambda _: self._update())
Expand Down Expand Up @@ -122,7 +123,7 @@ def _update(self):
)
self._filter_entries()
self._publish_new_entries()
if self._has_published_parsed:
if self._has_published_parsed or self._has_updated_parsed:
self._storage.put_timestamp(
self._feed_id, self._last_entry_timestamp
)
Expand All @@ -143,17 +144,28 @@ def _filter_entries(self):

def _update_and_fire_entry(self, entry):
"""Update last_entry_timestamp and fire entry."""
# Check if the entry has a published date.
# Check if the entry has a published or updated date.
if "published_parsed" in entry and entry.published_parsed:
# We are lucky, `published_parsed` data available, let's make use of
# it to publish only new available entries since the last run
self._has_published_parsed = True
self._last_entry_timestamp = max(
entry.published_parsed, self._last_entry_timestamp
)
elif "updated_parsed" in entry and entry.updated_parsed:
# We are lucky, `updated_parsed` data available, let's make use of
# it to publish only new available entries since the last run
self._has_updated_parsed = True
self._last_entry_timestamp = max(
entry.updated_parsed, self._last_entry_timestamp
)
else:
self._has_published_parsed = False
_LOGGER.debug("No published_parsed info available for entry %s", entry)
self._has_updated_parsed = False
_LOGGER.debug(
"No published_parsed or updated_parsed info available for entry %s",
entry,
)
entry.update({"feed_url": self._url})
self._hass.bus.fire(self._event_type, entry)

Expand All @@ -167,9 +179,16 @@ def _publish_new_entries(self):
# Set last entry timestamp as epoch time if not available
self._last_entry_timestamp = datetime.utcfromtimestamp(0).timetuple()
for entry in self._feed.entries:
if self._firstrun or (
"published_parsed" in entry
and entry.published_parsed > self._last_entry_timestamp
if (
self._firstrun
or (
"published_parsed" in entry
and entry.published_parsed > self._last_entry_timestamp
)
or (
"updated_parsed" in entry
and entry.updated_parsed > self._last_entry_timestamp
)
):
self._update_and_fire_entry(entry)
new_entries = True
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def set_theme(call: ServiceCall) -> None:
async def reload_themes(_: ServiceCall) -> None:
"""Reload themes."""
config = await async_hass_config_yaml(hass)
new_themes = config[DOMAIN].get(CONF_THEMES, {})
new_themes = config.get(DOMAIN, {}).get(CONF_THEMES, {})
hass.data[DATA_THEMES] = new_themes
if hass.data[DATA_DEFAULT_THEME] not in new_themes:
hass.data[DATA_DEFAULT_THEME] = DEFAULT_THEME
Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/hive/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self):
self.data = {}
self.tokens = {}
self.entry = None
self.device_registration = False

async def async_step_user(self, user_input=None):
"""Prompt user input. Create or edit entry."""
Expand Down Expand Up @@ -88,6 +89,7 @@ async def async_step_2fa(self, user_input=None):

if not errors:
try:
self.device_registration = True
return await self.async_setup_hive_entry()
except UnknownHiveError:
errors["base"] = "unknown"
Expand All @@ -102,9 +104,10 @@ async def async_setup_hive_entry(self):
raise UnknownHiveError

# Setup the config entry
await self.hive_auth.device_registration("Home Assistant")
if self.device_registration:
await self.hive_auth.device_registration("Home Assistant")
self.data["device_data"] = await self.hive_auth.getDeviceData()
self.data["tokens"] = self.tokens
self.data["device_data"] = await self.hive_auth.getDeviceData()
if self.context["source"] == config_entries.SOURCE_REAUTH:
self.hass.config_entries.async_update_entry(
self.entry, title=self.data["username"], data=self.data
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hive/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Hive",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/hive",
"requirements": ["pyhiveapi==0.5.5"],
"requirements": ["pyhiveapi==0.5.9"],
"codeowners": ["@Rendili", "@KJonline"],
"iot_class": "cloud_polling",
"loggers": ["apyhiveapi"]
Expand Down
30 changes: 28 additions & 2 deletions homeassistant/components/mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@
from homeassistant.exceptions import TemplateError, Unauthorized
from homeassistant.helpers import config_validation as cv, event, template
from homeassistant.helpers.device_registry import DeviceEntry
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.dispatcher import (
async_dispatcher_connect,
async_dispatcher_send,
)
from homeassistant.helpers.reload import (
async_integration_yaml_config,
async_setup_reload_service,
)
from homeassistant.helpers.typing import ConfigType

# Loading the config flow file will register the flow
Expand Down Expand Up @@ -60,12 +67,14 @@
DATA_MQTT,
DATA_MQTT_CONFIG,
DATA_MQTT_RELOAD_NEEDED,
DATA_MQTT_UPDATED_CONFIG,
DEFAULT_ENCODING,
DEFAULT_QOS,
DEFAULT_RETAIN,
DOMAIN,
MQTT_CONNECTED,
MQTT_DISCONNECTED,
MQTT_RELOADED,
PLATFORMS,
)
from .models import ( # noqa: F401
Expand Down Expand Up @@ -227,7 +236,9 @@ async def _async_config_entry_updated(hass: HomeAssistant, entry: ConfigEntry) -
await _async_setup_discovery(hass, mqtt_client.conf, entry)


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_setup_entry( # noqa: C901
hass: HomeAssistant, entry: ConfigEntry
) -> bool:
"""Load a config entry."""
# Merge basic configuration, and add missing defaults for basic options
_merge_basic_config(hass, entry, hass.data.get(DATA_MQTT_CONFIG, {}))
Expand Down Expand Up @@ -364,6 +375,17 @@ async def finish_dump(_):
hass.data[DATA_CONFIG_ENTRY_LOCK] = asyncio.Lock()
hass.data[CONFIG_ENTRY_IS_SETUP] = set()

# Setup reload service. Once support for legacy config is removed in 2022.9, we
# should no longer call async_setup_reload_service but instead implement a custom
# service
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)

async def _async_reload_platforms(_: Event | None) -> None:
"""Discover entities for a platform."""
config_yaml = await async_integration_yaml_config(hass, DOMAIN) or {}
hass.data[DATA_MQTT_UPDATED_CONFIG] = config_yaml.get(DOMAIN, {})
async_dispatcher_send(hass, MQTT_RELOADED)

async def async_forward_entry_setup():
"""Forward the config entry setup to the platforms."""
async with hass.data[DATA_CONFIG_ENTRY_LOCK]:
Expand All @@ -374,6 +396,10 @@ async def async_forward_entry_setup():
await hass.config_entries.async_forward_entry_setup(
entry, component
)
# Setup reload service after all platforms have loaded
entry.async_on_unload(
hass.bus.async_listen("event_mqtt_reloaded", _async_reload_platforms)
)

hass.async_create_task(async_forward_entry_setup())

Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/mqtt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
DATA_MQTT = "mqtt"
DATA_MQTT_CONFIG = "mqtt_config"
DATA_MQTT_RELOAD_NEEDED = "mqtt_reload_needed"
DATA_MQTT_UPDATED_CONFIG = "mqtt_updated_config"

DEFAULT_PREFIX = "homeassistant"
DEFAULT_BIRTH_WILL_TOPIC = DEFAULT_PREFIX + "/status"
Expand Down Expand Up @@ -63,6 +64,7 @@

MQTT_CONNECTED = "mqtt_connected"
MQTT_DISCONNECTED = "mqtt_disconnected"
MQTT_RELOADED = "mqtt_reloaded"

PAYLOAD_EMPTY_JSON = "{}"
PAYLOAD_NONE = "None"
Expand Down
2 changes: 0 additions & 2 deletions homeassistant/components/mqtt/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
STATE_CLOSING,
STATE_OPEN,
STATE_OPENING,
STATE_UNKNOWN,
)
from homeassistant.core import HomeAssistant, callback
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -470,7 +469,6 @@ def position_message_received(msg):
}

if self._config.get(CONF_TILT_STATUS_TOPIC) is not None:
self._tilt_value = STATE_UNKNOWN
topics["tilt_status_topic"] = {
"topic": self._config.get(CONF_TILT_STATUS_TOPIC),
"msg_callback": tilt_message_received,
Expand Down
21 changes: 7 additions & 14 deletions homeassistant/components/mqtt/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
async_generate_entity_id,
)
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.reload import (
async_integration_yaml_config,
async_setup_reload_service,
)
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

from . import debug_info, subscription
Expand All @@ -67,13 +63,14 @@
DATA_MQTT,
DATA_MQTT_CONFIG,
DATA_MQTT_RELOAD_NEEDED,
DATA_MQTT_UPDATED_CONFIG,
DEFAULT_ENCODING,
DEFAULT_PAYLOAD_AVAILABLE,
DEFAULT_PAYLOAD_NOT_AVAILABLE,
DOMAIN,
MQTT_CONNECTED,
MQTT_DISCONNECTED,
PLATFORMS,
MQTT_RELOADED,
)
from .debug_info import log_message, log_messages
from .discovery import (
Expand Down Expand Up @@ -270,14 +267,11 @@ async def async_setup_platform_discovery(
) -> CALLBACK_TYPE:
"""Set up platform discovery for manual config."""

async def _async_discover_entities(event: Event | None) -> None:
async def _async_discover_entities() -> None:
"""Discover entities for a platform."""
if event:
if DATA_MQTT_UPDATED_CONFIG in hass.data:
# The platform has been reloaded
config_yaml = await async_integration_yaml_config(hass, DOMAIN)
if not config_yaml:
return
config_yaml = config_yaml.get(DOMAIN, {})
config_yaml = hass.data[DATA_MQTT_UPDATED_CONFIG]
else:
config_yaml = hass.data.get(DATA_MQTT_CONFIG, {})
if not config_yaml:
Expand All @@ -293,8 +287,8 @@ async def _async_discover_entities(event: Event | None) -> None:
)
)

unsub = hass.bus.async_listen("event_mqtt_reloaded", _async_discover_entities)
await _async_discover_entities(None)
unsub = async_dispatcher_connect(hass, MQTT_RELOADED, _async_discover_entities)
await _async_discover_entities()
return unsub


Expand Down Expand Up @@ -359,7 +353,6 @@ async def async_setup_platform_helper(
async_setup_entities: SetupEntity,
) -> None:
"""Return true if platform setup should be aborted."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
if not bool(hass.config_entries.async_entries(DOMAIN)):
hass.data[DATA_MQTT_RELOAD_NEEDED] = None
_LOGGER.warning(
Expand Down
7 changes: 3 additions & 4 deletions homeassistant/components/netgear/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
KEY_COORDINATOR_SPEED,
KEY_COORDINATOR_TRAFFIC,
KEY_ROUTER,
MODE_ROUTER,
PLATFORMS,
)
from .errors import CannotLoginException
Expand Down Expand Up @@ -72,7 +71,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

async def async_update_devices() -> bool:
"""Fetch data from the router."""
if router.mode == MODE_ROUTER:
if router.track_devices:
return await router.async_update_device_trackers()
return False

Expand Down Expand Up @@ -107,7 +106,7 @@ async def async_update_speed_test() -> dict[str, Any] | None:
update_interval=SPEED_TEST_INTERVAL,
)

if router.mode == MODE_ROUTER:
if router.track_devices:
await coordinator.async_config_entry_first_refresh()
await coordinator_traffic_meter.async_config_entry_first_refresh()

Expand All @@ -134,7 +133,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
if not hass.data[DOMAIN]:
hass.data.pop(DOMAIN)

if router.mode != MODE_ROUTER:
if not router.track_devices:
router_id = None
# Remove devices that are no longer tracked
device_registry = dr.async_get(hass)
Expand Down
17 changes: 15 additions & 2 deletions homeassistant/components/netgear/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
self.hardware_version = ""
self.serial_number = ""

self.track_devices = True
self.method_version = 1
consider_home_int = entry.options.get(
CONF_CONSIDER_HOME, DEFAULT_CONSIDER_HOME.total_seconds()
Expand Down Expand Up @@ -112,11 +113,23 @@ def _setup(self) -> bool:
self.serial_number = self._info["SerialNumber"]
self.mode = self._info.get("DeviceMode", MODE_ROUTER)

enabled_entries = [
entry
for entry in self.hass.config_entries.async_entries(DOMAIN)
if entry.disabled_by is None
]
self.track_devices = self.mode == MODE_ROUTER or len(enabled_entries) == 1
_LOGGER.debug(
"Netgear track_devices = '%s', device mode '%s'",
self.track_devices,
self.mode,
)

for model in MODELS_V2:
if self.model.startswith(model):
self.method_version = 2

if self.method_version == 2 and self.mode == MODE_ROUTER:
if self.method_version == 2 and self.track_devices:
if not self._api.get_attached_devices_2():
_LOGGER.error(
"Netgear Model '%s' in MODELS_V2 list, but failed to get attached devices using V2",
Expand All @@ -133,7 +146,7 @@ async def async_setup(self) -> bool:
return False

# set already known devices to away instead of unavailable
if self.mode == MODE_ROUTER:
if self.track_devices:
device_registry = dr.async_get(self.hass)
devices = dr.async_entries_for_config_entry(device_registry, self.entry_id)
for device_entry in devices:
Expand Down
43B0
Loading
0