Use shared httpx client in gogogate2 (#45575)
This commit is contained in:
parent
7dec23d58b
commit
af832e5434
12 changed files with 28 additions and 26 deletions
|
@ -179,7 +179,7 @@ homeassistant/components/gios/* @bieniu
|
||||||
homeassistant/components/gitter/* @fabaff
|
homeassistant/components/gitter/* @fabaff
|
||||||
homeassistant/components/glances/* @fabaff @engrbm87
|
homeassistant/components/glances/* @fabaff @engrbm87
|
||||||
homeassistant/components/goalzero/* @tkdrob
|
homeassistant/components/goalzero/* @tkdrob
|
||||||
homeassistant/components/gogogate2/* @vangorra
|
homeassistant/components/gogogate2/* @vangorra @bdraco
|
||||||
homeassistant/components/google_assistant/* @home-assistant/cloud
|
homeassistant/components/google_assistant/* @home-assistant/cloud
|
||||||
homeassistant/components/google_cloud/* @lufton
|
homeassistant/components/google_cloud/* @lufton
|
||||||
homeassistant/components/gpsd/* @fabaff
|
homeassistant/components/gpsd/* @fabaff
|
||||||
|
|
|
@ -6,8 +6,8 @@ from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import Callable, NamedTuple
|
from typing import Callable, NamedTuple
|
||||||
|
|
||||||
from gogogate2_api import AbstractGateApi, GogoGate2Api, ISmartGateApi
|
from ismartgate import AbstractGateApi, GogoGate2Api, ISmartGateApi
|
||||||
from gogogate2_api.common import AbstractDoor, get_door_by_id
|
from ismartgate.common import AbstractDoor, get_door_by_id
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -18,6 +18,7 @@ from homeassistant.const import (
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.debounce import Debouncer
|
from homeassistant.helpers.debounce import Debouncer
|
||||||
|
from homeassistant.helpers.httpx_client import get_async_client
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
CoordinatorEntity,
|
CoordinatorEntity,
|
||||||
DataUpdateCoordinator,
|
DataUpdateCoordinator,
|
||||||
|
@ -112,7 +113,7 @@ def get_data_update_coordinator(
|
||||||
config_entry_data = hass.data[DOMAIN][config_entry.entry_id]
|
config_entry_data = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
|
||||||
if DATA_UPDATE_COORDINATOR not in config_entry_data:
|
if DATA_UPDATE_COORDINATOR not in config_entry_data:
|
||||||
api = get_api(config_entry.data)
|
api = get_api(hass, config_entry.data)
|
||||||
|
|
||||||
async def async_update_data():
|
async def async_update_data():
|
||||||
try:
|
try:
|
||||||
|
@ -148,7 +149,7 @@ def sensor_unique_id(
|
||||||
return f"{config_entry.unique_id}_{door.door_id}_{sensor_type}"
|
return f"{config_entry.unique_id}_{door.door_id}_{sensor_type}"
|
||||||
|
|
||||||
|
|
||||||
def get_api(config_data: dict) -> AbstractGateApi:
|
def get_api(hass: HomeAssistant, config_data: dict) -> AbstractGateApi:
|
||||||
"""Get an api object for config data."""
|
"""Get an api object for config data."""
|
||||||
gate_class = GogoGate2Api
|
gate_class = GogoGate2Api
|
||||||
|
|
||||||
|
@ -159,4 +160,5 @@ def get_api(config_data: dict) -> AbstractGateApi:
|
||||||
config_data[CONF_IP_ADDRESS],
|
config_data[CONF_IP_ADDRESS],
|
||||||
config_data[CONF_USERNAME],
|
config_data[CONF_USERNAME],
|
||||||
config_data[CONF_PASSWORD],
|
config_data[CONF_PASSWORD],
|
||||||
|
httpx_async_client=get_async_client(hass),
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from gogogate2_api.common import AbstractInfoResponse, ApiError
|
from ismartgate.common import AbstractInfoResponse, ApiError
|
||||||
from gogogate2_api.const import GogoGate2ApiErrorCode, ISmartGateApiErrorCode
|
from ismartgate.const import GogoGate2ApiErrorCode, ISmartGateApiErrorCode
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigFlow
|
from homeassistant.config_entries import SOURCE_IMPORT, ConfigFlow
|
||||||
|
@ -55,7 +55,7 @@ class Gogogate2FlowHandler(ConfigFlow, domain=DOMAIN):
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
if user_input:
|
if user_input:
|
||||||
api = get_api(user_input)
|
api = get_api(self.hass, user_input)
|
||||||
try:
|
try:
|
||||||
data: AbstractInfoResponse = await api.async_info()
|
data: AbstractInfoResponse = await api.async_info()
|
||||||
data_dict = dataclasses.asdict(data)
|
data_dict = dataclasses.asdict(data)
|
||||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from gogogate2_api.common import AbstractDoor, DoorStatus, get_configured_doors
|
from ismartgate.common import AbstractDoor, DoorStatus, get_configured_doors
|
||||||
|
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
DEVICE_CLASS_GARAGE,
|
DEVICE_CLASS_GARAGE,
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
"name": "Gogogate2 and iSmartGate",
|
"name": "Gogogate2 and iSmartGate",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/gogogate2",
|
"documentation": "https://www.home-assistant.io/integrations/gogogate2",
|
||||||
"requirements": ["gogogate2-api==3.0.0"],
|
"requirements": ["ismartgate==4.0.0"],
|
||||||
"codeowners": ["@vangorra"],
|
"codeowners": ["@vangorra", "@bdraco"],
|
||||||
"homekit": {
|
"homekit": {
|
||||||
"models": ["iSmartGate"]
|
"models": ["iSmartGate"]
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from gogogate2_api.common import AbstractDoor, get_configured_doors
|
from ismartgate.common import AbstractDoor, get_configured_doors
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
|
|
@ -671,9 +671,6 @@ gntp==1.0.3
|
||||||
# homeassistant.components.goalzero
|
# homeassistant.components.goalzero
|
||||||
goalzero==0.1.7
|
goalzero==0.1.7
|
||||||
|
|
||||||
# homeassistant.components.gogogate2
|
|
||||||
gogogate2-api==3.0.0
|
|
||||||
|
|
||||||
# homeassistant.components.google
|
# homeassistant.components.google
|
||||||
google-api-python-client==1.6.4
|
google-api-python-client==1.6.4
|
||||||
|
|
||||||
|
@ -833,6 +830,9 @@ influxdb==5.2.3
|
||||||
# homeassistant.components.iperf3
|
# homeassistant.components.iperf3
|
||||||
iperf3==0.1.11
|
iperf3==0.1.11
|
||||||
|
|
||||||
|
# homeassistant.components.gogogate2
|
||||||
|
ismartgate==4.0.0
|
||||||
|
|
||||||
# homeassistant.components.rest
|
# homeassistant.components.rest
|
||||||
jsonpath==0.82
|
jsonpath==0.82
|
||||||
|
|
||||||
|
|
|
@ -368,9 +368,6 @@ glances_api==0.2.0
|
||||||
# homeassistant.components.goalzero
|
# homeassistant.components.goalzero
|
||||||
goalzero==0.1.7
|
goalzero==0.1.7
|
||||||
|
|
||||||
# homeassistant.components.gogogate2
|
|
||||||
gogogate2-api==3.0.0
|
|
||||||
|
|
||||||
# homeassistant.components.google
|
# homeassistant.components.google
|
||||||
google-api-python-client==1.6.4
|
google-api-python-client==1.6.4
|
||||||
|
|
||||||
|
@ -462,6 +459,9 @@ influxdb-client==1.14.0
|
||||||
# homeassistant.components.influxdb
|
# homeassistant.components.influxdb
|
||||||
influxdb==5.2.3
|
influxdb==5.2.3
|
||||||
|
|
||||||
|
# homeassistant.components.gogogate2
|
||||||
|
ismartgate==4.0.0
|
||||||
|
|
||||||
# homeassistant.components.rest
|
# homeassistant.components.rest
|
||||||
jsonpath==0.82
|
jsonpath==0.82
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
"""Tests for the GogoGate2 component."""
|
"""Tests for the GogoGate2 component."""
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from gogogate2_api import GogoGate2Api
|
from ismartgate import GogoGate2Api
|
||||||
from gogogate2_api.common import ApiError
|
from ismartgate.common import ApiError
|
||||||
from gogogate2_api.const import GogoGate2ApiErrorCode
|
from ismartgate.const import GogoGate2ApiErrorCode
|
||||||
|
|
||||||
from homeassistant import config_entries, setup
|
from homeassistant import config_entries, setup
|
||||||
from homeassistant.components.gogogate2.const import (
|
from homeassistant.components.gogogate2.const import (
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from gogogate2_api import GogoGate2Api, ISmartGateApi
|
from ismartgate import GogoGate2Api, ISmartGateApi
|
||||||
from gogogate2_api.common import (
|
from ismartgate.common import (
|
||||||
ApiError,
|
ApiError,
|
||||||
DoorMode,
|
DoorMode,
|
||||||
DoorStatus,
|
DoorStatus,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from gogogate2_api import GogoGate2Api
|
from ismartgate import GogoGate2Api
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.gogogate2 import DEVICE_TYPE_GOGOGATE2, async_setup_entry
|
from homeassistant.components.gogogate2 import DEVICE_TYPE_GOGOGATE2, async_setup_entry
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from gogogate2_api import GogoGate2Api, ISmartGateApi
|
from ismartgate import GogoGate2Api, ISmartGateApi
|
||||||
from gogogate2_api.common import (
|
from ismartgate.common import (
|
||||||
DoorMode,
|
DoorMode,
|
||||||
DoorStatus,
|
DoorStatus,
|
||||||
GogoGate2ActivateResponse,
|
GogoGate2ActivateResponse,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue