Add Google Mail integration (#82637)

* Add Google Mail integration

* oops

* prettier

* Add email service

* adjustments

* update

* move email to notify

* break out services

* tweaks

* Add CC and BCC support

* drop scope check, breakout tests

* use abstract auth

* tweak

* bump dependency

* dependency bump

* remove oauth2client
This commit is contained in:
Robert Hillis 2023-01-07 14:59:14 -05:00 committed by GitHub
parent d2537dacc6
commit ad65fc27bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 1303 additions and 0 deletions

View file

@ -0,0 +1,52 @@
"""Support for Google Mail Sensors."""
from __future__ import annotations
from datetime import datetime, timedelta, timezone
from googleapiclient.http import HttpRequest
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
from .entity import GoogleMailEntity
SCAN_INTERVAL = timedelta(minutes=15)
SENSOR_TYPE = SensorEntityDescription(
key="vacation_end_date",
name="Vacation end date",
icon="mdi:clock",
device_class=SensorDeviceClass.TIMESTAMP,
)
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up the Google Mail sensor."""
async_add_entities(
[GoogleMailSensor(hass.data[DOMAIN][entry.entry_id], SENSOR_TYPE)], True
)
class GoogleMailSensor(GoogleMailEntity, SensorEntity):
"""Representation of a Google Mail sensor."""
async def async_update(self) -> None:
"""Get the vacation data."""
service = await self.auth.get_resource()
settings: HttpRequest = service.users().settings().getVacation(userId="me")
data = await self.hass.async_add_executor_job(settings.execute)
if data["enableAutoReply"]:
value = datetime.fromtimestamp(int(data["endTime"]) / 1000, tz=timezone.utc)
else:
value = None
self._attr_native_value = value