mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-21 08:06:30 +00:00
Set connectivity state on network tasks (#2686)
* Set connectivity state on network tasks * target connectivity error
This commit is contained in:
parent
2b411b0bf9
commit
681a1ecff5
@ -303,6 +303,10 @@ class PwnedError(HassioError):
|
||||
"""Errors while checking pwned passwords."""
|
||||
|
||||
|
||||
class PwnedConnectivityError(PwnedError):
|
||||
"""Connectivity errors while checking pwned passwords."""
|
||||
|
||||
|
||||
# docker/api
|
||||
|
||||
|
||||
|
@ -89,6 +89,7 @@ class HassOS(CoreSysAttributes):
|
||||
return raucb
|
||||
|
||||
except (aiohttp.ClientError, asyncio.TimeoutError) as err:
|
||||
self.sys_supervisor.connectivity = False
|
||||
_LOGGER.warning("Can't fetch versions from %s: %s", url, err)
|
||||
|
||||
except OSError as err:
|
||||
|
@ -8,6 +8,7 @@ from typing import List, Optional, Union
|
||||
|
||||
import attr
|
||||
|
||||
from ..const import ATTR_HOST_INTERNET
|
||||
from ..coresys import CoreSys, CoreSysAttributes
|
||||
from ..dbus.const import (
|
||||
DBUS_NAME_NM_CONNECTION_ACTIVE_CHANGED,
|
||||
@ -46,6 +47,16 @@ class NetworkManager(CoreSysAttributes):
|
||||
"""Return true current connectivity state."""
|
||||
return self._connectivity
|
||||
|
||||
@connectivity.setter
|
||||
def connectivity(self, state: bool) -> None:
|
||||
"""Set host connectivity state."""
|
||||
if self._connectivity == state:
|
||||
return
|
||||
self._connectivity = state
|
||||
self.sys_homeassistant.websocket.supervisor_update_event(
|
||||
"network", {ATTR_HOST_INTERNET: state}
|
||||
)
|
||||
|
||||
@property
|
||||
def interfaces(self) -> List[Interface]:
|
||||
"""Return a dictionary of active interfaces."""
|
||||
@ -79,10 +90,10 @@ class NetworkManager(CoreSysAttributes):
|
||||
# Check connectivity
|
||||
try:
|
||||
state = await self.sys_dbus.network.check_connectivity()
|
||||
self._connectivity = state[0] == 4
|
||||
self.connectivity = state[0] == 4
|
||||
except DBusError as err:
|
||||
_LOGGER.warning("Can't update connectivity information: %s", err)
|
||||
self._connectivity = False
|
||||
self.connectivity = False
|
||||
|
||||
def get(self, inet_name: str) -> Interface:
|
||||
"""Return interface from interface name."""
|
||||
|
@ -4,7 +4,7 @@ from datetime import timedelta
|
||||
from typing import List, Optional
|
||||
|
||||
from ...const import AddonState, CoreState
|
||||
from ...exceptions import PwnedError
|
||||
from ...exceptions import PwnedConnectivityError, PwnedError
|
||||
from ...jobs.const import JobCondition, JobExecutionLimit
|
||||
from ...jobs.decorator import Job
|
||||
from ...utils.pwned import check_pwned_password
|
||||
@ -34,6 +34,9 @@ class CheckAddonPwned(CheckBase):
|
||||
try:
|
||||
if not await check_pwned_password(self.sys_websession, secret):
|
||||
continue
|
||||
except PwnedConnectivityError:
|
||||
self.sys_supervisor.connectivity = False
|
||||
continue
|
||||
except PwnedError:
|
||||
continue
|
||||
|
||||
|
@ -13,7 +13,7 @@ from awesomeversion import AwesomeVersion, AwesomeVersionException
|
||||
|
||||
from supervisor.jobs.decorator import Job, JobCondition
|
||||
|
||||
from .const import SUPERVISOR_VERSION, URL_HASSIO_APPARMOR
|
||||
from .const import ATTR_SUPERVISOR_INTERNET, SUPERVISOR_VERSION, URL_HASSIO_APPARMOR
|
||||
from .coresys import CoreSys, CoreSysAttributes
|
||||
from .docker.stats import DockerStats
|
||||
from .docker.supervisor import DockerSupervisor
|
||||
@ -53,6 +53,16 @@ class Supervisor(CoreSysAttributes):
|
||||
"""Return true if we are connected to the internet."""
|
||||
return self._connectivity
|
||||
|
||||
@connectivity.setter
|
||||
def connectivity(self, state: bool) -> None:
|
||||
"""Set supervisor connectivity state."""
|
||||
if self._connectivity == state:
|
||||
return
|
||||
self._connectivity = state
|
||||
self.sys_homeassistant.websocket.supervisor_update_event(
|
||||
"network", {ATTR_SUPERVISOR_INTERNET: state}
|
||||
)
|
||||
|
||||
@property
|
||||
def ip_address(self) -> IPv4Address:
|
||||
"""Return IP of Supervisor instance."""
|
||||
@ -98,6 +108,7 @@ class Supervisor(CoreSysAttributes):
|
||||
data = await request.text()
|
||||
|
||||
except (aiohttp.ClientError, asyncio.TimeoutError) as err:
|
||||
self.sys_supervisor.connectivity = False
|
||||
_LOGGER.warning("Can't fetch AppArmor profile: %s", err)
|
||||
raise SupervisorError() from err
|
||||
|
||||
@ -198,6 +209,6 @@ class Supervisor(CoreSysAttributes):
|
||||
"https://version.home-assistant.io/online.txt", timeout=timeout
|
||||
)
|
||||
except (ClientError, asyncio.TimeoutError):
|
||||
self._connectivity = False
|
||||
self.connectivity = False
|
||||
else:
|
||||
self._connectivity = True
|
||||
self.connectivity = True
|
||||
|
@ -186,6 +186,7 @@ class Updater(FileConfiguration, CoreSysAttributes):
|
||||
data = await request.json(content_type=None)
|
||||
|
||||
except (aiohttp.ClientError, asyncio.TimeoutError) as err:
|
||||
self.sys_supervisor.connectivity = False
|
||||
_LOGGER.warning("Can't fetch versions from %s: %s", url, err)
|
||||
raise UpdaterError() from err
|
||||
|
||||
|
@ -5,7 +5,7 @@ import logging
|
||||
|
||||
import aiohttp
|
||||
|
||||
from ..exceptions import PwnedError
|
||||
from ..exceptions import PwnedConnectivityError, PwnedError
|
||||
|
||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||
_API_CALL = "https://api.pwnedpasswords.com/range/{hash}"
|
||||
@ -30,6 +30,6 @@ async def check_pwned_password(websession: aiohttp.ClientSession, sha1_pw: str)
|
||||
|
||||
except (aiohttp.ClientError, asyncio.TimeoutError) as err:
|
||||
_LOGGER.warning("Can't fetch hibp data: %s", err)
|
||||
raise PwnedError() from err
|
||||
raise PwnedConnectivityError() from err
|
||||
|
||||
return False
|
||||
|
Loading…
x
Reference in New Issue
Block a user