Skip to content
This repository has been archived by the owner on Jul 23, 2021. It is now read-only.

Commit

Permalink
Update init
Browse files Browse the repository at this point in the history
  • Loading branch information
robmarkcole committed Feb 11, 2020
1 parent 5b048ed commit c090554
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 69 deletions.
25 changes: 25 additions & 0 deletions custom_components/huesensor/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
"""The huesensors component."""
import asyncio
import async_timeout


def get_bridges(hass):
from homeassistant.components import hue
from homeassistant.components.hue.bridge import HueBridge

return [
entry
for entry in hass.data[hue.DOMAIN].values()
if isinstance(entry, HueBridge) and entry.api
]


async def update_api(api):
import aiohue

try:
with async_timeout.timeout(10):
await api.update()
except (asyncio.TimeoutError, aiohue.AiohueException) as err:
_LOGGER.debug("Failed to fetch sensors: %s", err)
return False
return True
25 changes: 2 additions & 23 deletions custom_components/huesensor/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.helpers.event import async_track_time_interval

from . import get_bridges, update_api

DEPENDENCIES = ["hue"]


Expand Down Expand Up @@ -113,29 +115,6 @@ def parse_sml(response):
return data


def get_bridges(hass):
from homeassistant.components import hue
from homeassistant.components.hue.bridge import HueBridge

return [
entry
for entry in hass.data[hue.DOMAIN].values()
if isinstance(entry, HueBridge) and entry.api
]


async def update_api(api):
import aiohue

try:
with async_timeout.timeout(10):
await api.update()
except (asyncio.TimeoutError, aiohue.AiohueException) as err:
_LOGGER.debug("Failed to fetch sensors: %s", err)
return False
return True


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Initialise Hue Bridge connection."""
data = HueSensorData(hass, async_add_entities)
Expand Down
24 changes: 1 addition & 23 deletions custom_components/huesensor/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from homeassistant.util import slugify
from homeassistant.components import zone

from . import get_bridges, update_api

DEPENDENCIES = ["hue"]

Expand All @@ -35,29 +36,6 @@
DEFAULT_SCAN_INTERVAL = timedelta(seconds=30)


def get_bridges(hass):
from homeassistant.components import hue
from homeassistant.components.hue.bridge import HueBridge

return [
entry
for entry in hass.data[hue.DOMAIN].values()
if isinstance(entry, HueBridge) and entry.api
]


async def update_api(api):
import aiohue

try:
with async_timeout.timeout(10):
await api.update()
except (asyncio.TimeoutError, aiohue.AiohueException) as err:
_LOGGER.debug("Failed to fetch sensors: %s", err)
return False
return True


async def async_setup_scanner(hass, config, async_see, discovery_info=None):
interval = config.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
scanner = HueDeviceScanner(hass, async_see)
Expand Down
25 changes: 2 additions & 23 deletions custom_components/huesensor/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from homeassistant.helpers.event import async_track_time_interval

from . import get_bridges, update_api

DEPENDENCIES = ["hue"]


Expand Down Expand Up @@ -211,29 +213,6 @@ def parse_z3_switch(response):
return data


def get_bridges(hass):
from homeassistant.components import hue
from homeassistant.components.hue.bridge import HueBridge

return [
entry
for entry in hass.data[hue.DOMAIN].values()
if isinstance(entry, HueBridge) and entry.api
]


async def update_api(api):
import aiohue

try:
with async_timeout.timeout(10):
await api.update()
except (asyncio.TimeoutError, aiohue.AiohueException) as err:
_LOGGER.debug("Failed to fetch sensors: %s", err)
return False
return True


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Initialise Hue Bridge connection."""
data = HueRemoteData(hass, async_add_entities)
Expand Down

0 comments on commit c090554

Please sign in to comment.