parent
895c0be82c
commit
a5044227a8
3 changed files with 23 additions and 6 deletions
|
@ -43,10 +43,10 @@ class GoogleMailSensor(GoogleMailEntity, SensorEntity):
|
||||||
"""Get the vacation data."""
|
"""Get the vacation data."""
|
||||||
service = await self.auth.get_resource()
|
service = await self.auth.get_resource()
|
||||||
settings: HttpRequest = service.users().settings().getVacation(userId="me")
|
settings: HttpRequest = service.users().settings().getVacation(userId="me")
|
||||||
data = await self.hass.async_add_executor_job(settings.execute)
|
data: dict = await self.hass.async_add_executor_job(settings.execute)
|
||||||
|
|
||||||
if data["enableAutoReply"]:
|
if data["enableAutoReply"] and (end := data.get("endTime")):
|
||||||
value = datetime.fromtimestamp(int(data["endTime"]) / 1000, tz=timezone.utc)
|
value = datetime.fromtimestamp(int(end) / 1000, tz=timezone.utc)
|
||||||
else:
|
else:
|
||||||
value = None
|
value = None
|
||||||
self._attr_native_value = value
|
self._attr_native_value = value
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"enableAutoReply": true,
|
||||||
|
"responseSubject": "Vacation",
|
||||||
|
"responseBodyPlainText": "I am on vacation.",
|
||||||
|
"restrictToContacts": false
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ from unittest.mock import patch
|
||||||
|
|
||||||
from google.auth.exceptions import RefreshError
|
from google.auth.exceptions import RefreshError
|
||||||
from httplib2 import Response
|
from httplib2 import Response
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.google_mail.const import DOMAIN
|
from homeassistant.components.google_mail.const import DOMAIN
|
||||||
|
@ -17,7 +18,17 @@ from .conftest import SENSOR, TOKEN, ComponentSetup
|
||||||
from tests.common import async_fire_time_changed, load_fixture
|
from tests.common import async_fire_time_changed, load_fixture
|
||||||
|
|
||||||
|
|
||||||
async def test_sensors(hass: HomeAssistant, setup_integration: ComponentSetup) -> None:
|
@pytest.mark.parametrize(
|
||||||
|
("fixture", "result"),
|
||||||
|
[
|
||||||
|
("get_vacation", "2022-11-18T05:00:00+00:00"),
|
||||||
|
("get_vacation_no_dates", STATE_UNKNOWN),
|
||||||
|
("get_vacation_off", STATE_UNKNOWN),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_sensors(
|
||||||
|
hass: HomeAssistant, setup_integration: ComponentSetup, fixture: str, result: str
|
||||||
|
) -> None:
|
||||||
"""Test we get sensor data."""
|
"""Test we get sensor data."""
|
||||||
await setup_integration()
|
await setup_integration()
|
||||||
|
|
||||||
|
@ -29,7 +40,7 @@ async def test_sensors(hass: HomeAssistant, setup_integration: ComponentSetup) -
|
||||||
"httplib2.Http.request",
|
"httplib2.Http.request",
|
||||||
return_value=(
|
return_value=(
|
||||||
Response({}),
|
Response({}),
|
||||||
bytes(load_fixture("google_mail/get_vacation_off.json"), encoding="UTF-8"),
|
bytes(load_fixture(f"google_mail/{fixture}.json"), encoding="UTF-8"),
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
next_update = dt_util.utcnow() + timedelta(minutes=15)
|
next_update = dt_util.utcnow() + timedelta(minutes=15)
|
||||||
|
@ -37,7 +48,7 @@ async def test_sensors(hass: HomeAssistant, setup_integration: ComponentSetup) -
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get(SENSOR)
|
state = hass.states.get(SENSOR)
|
||||||
assert state.state == STATE_UNKNOWN
|
assert state.state == result
|
||||||
|
|
||||||
|
|
||||||
async def test_sensor_reauth_trigger(
|
async def test_sensor_reauth_trigger(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue