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