Update gree to use the network component to set discovery interfaces (#75812)
This commit is contained in:
parent
c580bce879
commit
1aa0e64354
6 changed files with 13 additions and 6 deletions
|
@ -2,6 +2,7 @@
|
|||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from homeassistant.components.network import async_get_ipv4_broadcast_addresses
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -32,7 +33,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
async def _async_scan_update(_=None):
|
||||
await gree_discovery.discovery.scan()
|
||||
bcast_addr = list(await async_get_ipv4_broadcast_addresses(hass))
|
||||
await gree_discovery.discovery.scan(0, bcast_ifaces=bcast_addr)
|
||||
|
||||
_LOGGER.debug("Scanning network for Gree devices")
|
||||
await _async_scan_update()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Config flow for Gree."""
|
||||
from greeclimate.discovery import Discovery
|
||||
|
||||
from homeassistant.components.network import async_get_ipv4_broadcast_addresses
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_entry_flow
|
||||
|
||||
|
@ -10,7 +11,10 @@ from .const import DISCOVERY_TIMEOUT, DOMAIN
|
|||
async def _async_has_devices(hass: HomeAssistant) -> bool:
|
||||
"""Return if there are devices that can be discovered."""
|
||||
gree_discovery = Discovery(DISCOVERY_TIMEOUT)
|
||||
devices = await gree_discovery.scan(wait_for=DISCOVERY_TIMEOUT)
|
||||
bcast_addr = list(await async_get_ipv4_broadcast_addresses(hass))
|
||||
devices = await gree_discovery.scan(
|
||||
wait_for=DISCOVERY_TIMEOUT, bcast_ifaces=bcast_addr
|
||||
)
|
||||
return len(devices) > 0
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
"name": "Gree Climate",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/gree",
|
||||
"requirements": ["greeclimate==1.2.0"],
|
||||
"requirements": ["greeclimate==1.3.0"],
|
||||
"dependencies": ["network"],
|
||||
"codeowners": ["@cmroche"],
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["greeclimate"]
|
||||
|
|
|
@ -772,7 +772,7 @@ gpiozero==1.6.2
|
|||
gps3==0.33.3
|
||||
|
||||
# homeassistant.components.gree
|
||||
greeclimate==1.2.0
|
||||
greeclimate==1.3.0
|
||||
|
||||
# homeassistant.components.greeneye_monitor
|
||||
greeneye_monitor==3.0.3
|
||||
|
|
|
@ -564,7 +564,7 @@ googlemaps==2.5.1
|
|||
govee-ble==0.12.6
|
||||
|
||||
# homeassistant.components.gree
|
||||
greeclimate==1.2.0
|
||||
greeclimate==1.3.0
|
||||
|
||||
# homeassistant.components.greeneye_monitor
|
||||
greeneye_monitor==3.0.3
|
||||
|
|
|
@ -28,7 +28,7 @@ class FakeDiscovery:
|
|||
"""Add an event listener."""
|
||||
self._listeners.append(listener)
|
||||
|
||||
async def scan(self, wait_for: int = 0):
|
||||
async def scan(self, wait_for: int = 0, bcast_ifaces=None):
|
||||
"""Search for devices, return mocked data."""
|
||||
self.scan_count += 1
|
||||
_LOGGER.info("CALLED SCAN %d TIMES", self.scan_count)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue