Add google home alarm sensor (#20709)
* added googlehome alarm sensor * splitted update method * fix linting * remove whitespace * removed whitespace in line * changed accordingly to the review * removed redundant method * Update homeassistant/components/googlehome/__init__.py Co-Authored-By: eliseomartelli <martely98@gmail.com>
This commit is contained in:
1 parent
0cf71d5bcb
commit
a40c5bf70e
3 files changed
+140
-5
No files matched your search
@@ -24,6 +24,7 @@ NAME = 'GoogleHome'
|
||||
|
||||
CONF_DEVICE_TYPES = 'device_types'
|
||||
CONF_RSSI_THRESHOLD = 'rssi_threshold'
|
||||
CONF_TRACK_ALARMS = 'track_alarms'
|
||||
|
||||
DEVICE_TYPES = [1, 2, 3]
|
||||
DEFAULT_RSSI_THRESHOLD = -70
|
||||
@@ -35,6 +36,7 @@ DEVICE_CONFIG = vol.Schema({
|
||||
[vol.In(DEVICE_TYPES)]),
|
||||
vol.Optional(CONF_RSSI_THRESHOLD,
|
||||
default=DEFAULT_RSSI_THRESHOLD): vol.Coerce(int),
|
||||
vol.Optional(CONF_TRACK_ALARMS, default=False): cv.boolean,
|
||||
})
|
||||
|
||||
|
||||
@@ -56,6 +58,11 @@ async def async_setup(hass, config):
|
||||
discovery.async_load_platform(
|
||||
hass, 'device_tracker', DOMAIN, device, config))
|
||||
|
||||
if device[CONF_TRACK_ALARMS]:
|
||||
hass.async_create_task(
|
||||
discovery.async_load_platform(
|
||||
hass, 'sensor', DOMAIN, device, config))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -67,20 +74,38 @@ class GoogleHomeClient:
|
||||
self.hass = hass
|
||||
self._connected = None
|
||||
|
||||
async def update_data(self, host):
|
||||
async def update_info(self, host):
|
||||
"""Update data from Google Home."""
|
||||
from googledevices.api.connect import Cast
|
||||
_LOGGER.debug("Updating Google Home data for %s", host)
|
||||
_LOGGER.debug("Updating Google Home info for %s", host)
|
||||
session = async_get_clientsession(self.hass)
|
||||
|
||||
device_info = await Cast(host, self.hass.loop, session).info()
|
||||
device_info_data = await device_info.get_device_info()
|
||||
self._connected = bool(device_info_data)
|
||||
|
||||
self.hass.data[DOMAIN][host]['info'] = device_info_data
|
||||
|
||||
async def update_bluetooth(self, host):
|
||||
"""Update bluetooth from Google Home."""
|
||||
from googledevices.api.connect import Cast
|
||||
_LOGGER.debug("Updating Google Home bluetooth for %s", host)
|
||||
session = async_get_clientsession(self.hass)
|
||||
|
||||
bluetooth = await Cast(host, self.hass.loop, session).bluetooth()
|
||||
await bluetooth.scan_for_devices()
|
||||
await asyncio.sleep(5)
|
||||
bluetooth_data = await bluetooth.get_scan_result()
|
||||
|
||||
self.hass.data[DOMAIN][host]['info'] = device_info_data
|
||||
self.hass.data[DOMAIN][host]['bluetooth'] = bluetooth_data
|
||||
|
||||
async def update_alarms(self, host):
|
||||
"""Update alarms from Google Home."""
|
||||
from googledevices.api.connect import Cast
|
||||
_LOGGER.debug("Updating Google Home bluetooth for %s", host)
|
||||
session = async_get_clientsession(self.hass)
|
||||
|
||||
assistant = await Cast(host, self.hass.loop, session).assistant()
|
||||
alarms_data = await assistant.get_alarms()
|
||||
|
||||
self.hass.data[DOMAIN][host]['alarms'] = alarms_data
|
||||
Reference in new issue
Block a user