Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration for iotty Smart Home #103073

Merged
merged 137 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
18ab298
Initial import 0.0.2
pburgio Oct 26, 2023
fc35303
Fixes to URL, and removed commits
pburgio Oct 26, 2023
3c25e8f
Initial import 0.0.2
pburgio Oct 26, 2023
2b2022a
Fixes to URL, and removed commits
pburgio Oct 26, 2023
0f8be23
Added first test for iotty
pburgio Oct 29, 2023
f6c9bb6
First release
pburgio Oct 30, 2023
ae97d6f
Merge branch 'iotty' of https://iotty.visualstudio.com/iotty/_git/hom…
pburgio Oct 30, 2023
213478f
Merge branch 'dev' into iotty
pburgio Oct 31, 2023
2dfbcac
Merge branch 'dev' into iotty
pburgio Nov 5, 2023
fdbef16
Reviewers request #1
pburgio Nov 5, 2023
ac38fc5
Merge branch 'dev' into iotty
pburgio Nov 5, 2023
cd56f98
Merge branch 'iotty' of https://github.com/pburgio/homeassistant.core…
pburgio Nov 5, 2023
f27bb4b
Removed commmented code
pburgio Nov 5, 2023
938a9af
Some modifications
pburgio Nov 5, 2023
31a8d01
Modified REST EP for iotty CloudApi
pburgio Nov 6, 2023
fb65b75
Merge branch 'dev' into iotty
pburgio Nov 6, 2023
63c4b2b
Initial import 0.0.2
pburgio Oct 26, 2023
3525d64
Fixes to URL, and removed commits
pburgio Oct 26, 2023
2a3d779
Added first test for iotty
pburgio Oct 29, 2023
d6a02a4
First release
pburgio Oct 30, 2023
b5223a5
Rebased and resolved conflicts
pburgio Nov 6, 2023
014c3e5
Rebased and resolved conflicts
pburgio Nov 6, 2023
0903fbd
Reviewers request #1
pburgio Nov 5, 2023
c719025
Removed commmented code
pburgio Nov 5, 2023
a7b9348
Some modifications
pburgio Nov 5, 2023
fea0e1d
Modified REST EP for iotty CloudApi
pburgio Nov 6, 2023
4c77d3f
Removed empty entries in manifest.json
pburgio Nov 6, 2023
0895ce4
Added test_config_flow
pburgio Nov 6, 2023
102cc67
Resolved conflicts
pburgio Nov 6, 2023
852e63e
Merge branch 'home-assistant:dev' into iotty
pburgio Nov 7, 2023
263b056
Merge branch 'dev' into iotty
pburgio Nov 7, 2023
2446c28
Fix as requested by @edenhaus
pburgio Nov 7, 2023
a8171e6
Merge branch 'dev' into iotty
pburgio Nov 7, 2023
42df504
Merge branch 'home-assistant:dev' into iotty
pburgio Nov 20, 2023
a4bbf4d
Merge branch 'iotty' of https://github.com/pburgio/homeassistant.core…
pburgio Nov 20, 2023
fa97a76
Merge branch 'dev' into iotty
pburgio Nov 23, 2023
41d1d5a
Merge branch 'iotty' of https://github.com/pburgio/homeassistant.core…
pburgio Nov 23, 2023
ab6afb1
Added test_init
pburgio Nov 23, 2023
1adc04d
Removed comments, added one assert
pburgio Nov 23, 2023
a137732
Added TEST_CONFIG_FLOW
pburgio Nov 27, 2023
def435b
Added test for STORE_ENTITY
pburgio Nov 27, 2023
2378530
Increased code coverage
pburgio Dec 1, 2023
a2c2e37
Full coverage for api.py
pburgio Dec 1, 2023
c72dec7
Added tests for switch component
pburgio Dec 1, 2023
6b4ac81
Merge branch 'dev' into iotty
pburgio Dec 6, 2023
f0d1c82
Merge branch 'dev' into iotty
pburgio Dec 6, 2023
fd9d6b9
Merge branch 'iotty' of https://github.com/pburgio/homeassistant.core…
pburgio Dec 6, 2023
235d95d
Converted INFO logs onto DEBUG logs
pburgio Dec 7, 2023
57f93c7
Merge branch 'dev' into iotty
pburgio Dec 7, 2023
d9c1e7c
Merge branch 'iotty' of https://github.com/pburgio/homeassistant.core…
pburgio Dec 7, 2023
e131b4f
Merge branch 'dev' into iotty
pburgio Dec 13, 2023
e5657db
Merge branch 'dev' into iotty
pburgio Dec 13, 2023
ddd9155
Merge branch 'dev' into iotty
pburgio Dec 18, 2023
aa7d87c
Merge branch 'dev' into iotty
pburgio Dec 19, 2023
f6e8269
Merge branch 'dev' into iotty
pburgio Jan 18, 2024
2406cea
Merge branch 'home-assistant:dev' into iotty
pburgio Jan 18, 2024
45993ed
Removed .gitignore from commits
pburgio Jan 18, 2024
ef16522
Modifications to SWITCH.PY
pburgio Jan 18, 2024
860cb78
Merge branch 'dev' into iotty
pburgio Jan 19, 2024
fb520ad
Initial import 0.0.2
pburgio Oct 26, 2023
b57182b
Fixes to URL, and removed commits
pburgio Oct 26, 2023
a6d9f43
Added first test for iotty
pburgio Oct 29, 2023
fd14b35
First release
pburgio Oct 30, 2023
9954782
Rebased and resolved conflicts
pburgio Nov 6, 2023
b3e4195
Fixed conflicts
pburgio Oct 30, 2023
dc47223
Reviewers request #1
pburgio Nov 5, 2023
f3bf64b
Removed commmented code
pburgio Nov 5, 2023
5df2e39
Some modifications
pburgio Nov 5, 2023
85c85a7
Modified REST EP for iotty CloudApi
pburgio Nov 6, 2023
7924c27
Removed empty entries in manifest.json
pburgio Nov 6, 2023
40dd193
Added test_config_flow
pburgio Nov 6, 2023
90c5cb5
Some modifications
pburgio Nov 5, 2023
2874d26
Fix as requested by @edenhaus
pburgio Nov 7, 2023
0d67c1c
Added test_init
pburgio Nov 23, 2023
6c9054c
Removed comments, added one assert
pburgio Nov 23, 2023
d8ac598
Added TEST_CONFIG_FLOW
pburgio Nov 27, 2023
d5f447a
Added test for STORE_ENTITY
pburgio Nov 27, 2023
202bdd7
Increased code coverage
pburgio Dec 1, 2023
1c273e1
Full coverage for api.py
pburgio Dec 1, 2023
4c30c1a
Added tests for switch component
pburgio Dec 1, 2023
eec1675
Converted INFO logs onto DEBUG logs
pburgio Dec 7, 2023
76b20bb
Removed .gitignore from commits
pburgio Jan 18, 2024
65317e0
Modifications to SWITCH.PY
pburgio Jan 18, 2024
c34e841
Fixed tests for SWITCH
pburgio Jan 19, 2024
f364332
Resolved conflicts
pburgio Jan 19, 2024
92b5cd9
First working implementation of Coordinator
pburgio Jan 25, 2024
3c07035
Increased code coverage
pburgio Jan 25, 2024
291c89d
Full code coverage
pburgio Jan 26, 2024
7d68719
Merge branch 'dev' into iotty
pburgio Jan 27, 2024
dec43e9
Missing a line in testing
pburgio Jan 27, 2024
4953f33
Merge branch 'dev' into iotty
pburgio Feb 3, 2024
3ab508c
Update homeassistant/components/iotty/__init__.py
pburgio Feb 3, 2024
d338e19
Update homeassistant/components/iotty/__init__.py
pburgio Feb 3, 2024
02551d6
Modified coordinator as per request by edenhaus
pburgio Feb 3, 2024
e67903c
Merge branch 'dev' into iotty
pburgio Mar 14, 2024
3df1fa7
use coordinator entities for switches
shapournemati-iotty Apr 23, 2024
14ecf78
move platforms to constants
shapournemati-iotty Apr 23, 2024
9b56504
Merge branch 'dev' into iotty
pburgio Apr 24, 2024
6bc5d16
fix whitespace with ruff-format
shapournemati-iotty May 9, 2024
2bf2cdd
Merge branch 'dev' into iotty
emontnemery May 14, 2024
6371d37
correct iotty entry in application_credentials list
shapournemati-iotty May 15, 2024
86b29da
Merge branch 'dev' into iotty
pburgio May 15, 2024
84d9977
minor style improvements
shapournemati-iotty May 16, 2024
0be59ce
refactor function name
shapournemati-iotty May 16, 2024
a3a32e0
Merge branch 'dev' into iotty
pburgio May 16, 2024
d2989f2
handle new and deleted devices
shapournemati-iotty May 28, 2024
fe9da43
Merge branch 'dev' into iotty
pburgio May 29, 2024
4497c2c
Merge branch 'dev' into iotty
shapournemati-iotty Jun 5, 2024
d3b6cc5
improve code for adding devices after first initialization
shapournemati-iotty Jun 6, 2024
56cf2cb
use typed config entry instead of adding known devices to hass.data
shapournemati-iotty Jun 6, 2024
43e79c1
Merge branch 'dev' into iotty
pburgio Jun 7, 2024
271e9e7
improve iotty entity removal
shapournemati-iotty Jun 17, 2024
a47a715
test listeners update cycle
shapournemati-iotty Jun 19, 2024
b02eea8
handle iotty as devices and not only as entities
shapournemati-iotty Jul 1, 2024
02acc82
Merge branch 'dev' into iotty
shapournemati-iotty Jul 1, 2024
01f8759
fix test typing for mock config entry
shapournemati-iotty Jul 1, 2024
7278fec
test with fewer mocks for an integration test style opposed to the pr…
shapournemati-iotty Jul 2, 2024
3328374
remove useless tests and add more integration style tests
shapournemati-iotty Jul 3, 2024
ce6e24e
check if device_to_remove is None
shapournemati-iotty Jul 4, 2024
4eac992
integration style tests for turning switches on and off
shapournemati-iotty Jul 4, 2024
b6cbcff
remove redundant coordinator tests
shapournemati-iotty Jul 4, 2024
4f14518
check device status after issuing command in tests
shapournemati-iotty Jul 4, 2024
91cdb09
Merge branch 'dev' into iotty
shapournemati-iotty Jul 4, 2024
e87cead
remove unused fixtures
shapournemati-iotty Jul 5, 2024
43c2662
add strict typing for iotty
shapournemati-iotty Jul 5, 2024
055f775
Merge branch 'iotty' of https://github.com/pburgio/homeassistant.core…
shapournemati-iotty Jul 5, 2024
eb195a3
additional asserts and named snapshots in tests
shapournemati-iotty Jul 5, 2024
f07da58
fix mypy issues after enabling strict typing
shapournemati-iotty Jul 5, 2024
b90f820
upgrade iottycloud version to 0.1.3
shapournemati-iotty Jul 5, 2024
383fc90
move coordinator to runtime_data
shapournemati-iotty Jul 5, 2024
c618e69
remove entity name
shapournemati-iotty Jul 5, 2024
c4ac6bb
fix typing issues
shapournemati-iotty Jul 8, 2024
5e87f2a
coding style fixes
shapournemati-iotty Jul 10, 2024
1399c04
improve tests coding style and assertion targets
shapournemati-iotty Jul 10, 2024
967e260
test edge cases when apis are not working
shapournemati-iotty Jul 18, 2024
0b17b2c
Merge branch 'dev' into iotty
pburgio Jul 18, 2024
299d884
improve tests comments and assertions
shapournemati-iotty Jul 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ build.json @home-assistant/supervisor
/tests/components/ios/ @robbiet480
/homeassistant/components/iotawatt/ @gtdiehl @jyavenard
/tests/components/iotawatt/ @gtdiehl @jyavenard
/homeassistant/components/iotty/ @pburgio
/tests/components/iotty/ @pburgio
/homeassistant/components/iperf3/ @rohankapoorcom
/homeassistant/components/ipma/ @dgomes
/tests/components/ipma/ @dgomes
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/iotty/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode/*

pburgio marked this conversation as resolved.
Show resolved Hide resolved
homeassistant/components/iotty/.vscode/*
pburgio marked this conversation as resolved.
Show resolved Hide resolved
55 changes: 55 additions & 0 deletions homeassistant/components/iotty/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""The iotty integration."""
from __future__ import annotations

import asyncio
import logging

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import aiohttp_client, config_entry_oauth2_flow

from . import api
from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)

# Uncomment these when developing
# _LOGGER.setLevel(logging.DEBUG)
# logging.getLogger("iottycloud").setLevel(logging.DEBUG)
pburgio marked this conversation as resolved.
Show resolved Hide resolved

# For your initial PR, limit it to 1 platform.
pburgio marked this conversation as resolved.
Show resolved Hide resolved
PLATFORMS: list[Platform] = [Platform.SWITCH]


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
emontnemery marked this conversation as resolved.
Show resolved Hide resolved
"""Set up iotty from a config entry."""
_LOGGER.debug("async_setup_entry DOMAIN %s entry_id=%s", DOMAIN, entry.entry_id)
pburgio marked this conversation as resolved.
Show resolved Hide resolved

implementation = (
await config_entry_oauth2_flow.async_get_config_entry_implementation(
hass, entry
)
)

session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)

Check warning on line 35 in homeassistant/components/iotty/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/__init__.py#L35

Added line #L35 was not covered by tests

iotty = api.IottyProxy(hass, aiohttp_client.async_get_clientsession(hass), session)

Check warning on line 37 in homeassistant/components/iotty/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/__init__.py#L37

Added line #L37 was not covered by tests

hass.async_add_job(iotty.init)

Check warning on line 39 in homeassistant/components/iotty/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/__init__.py#L39

Added line #L39 was not covered by tests

hass.data.setdefault(DOMAIN, {})[entry.entry_id] = iotty

Check warning on line 41 in homeassistant/components/iotty/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/__init__.py#L41

Added line #L41 was not covered by tests

await asyncio.sleep(3)

Check warning on line 43 in homeassistant/components/iotty/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/__init__.py#L43

Added line #L43 was not covered by tests
pburgio marked this conversation as resolved.
Show resolved Hide resolved

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

Check warning on line 45 in homeassistant/components/iotty/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/__init__.py#L45

Added line #L45 was not covered by tests

return True

Check warning on line 47 in homeassistant/components/iotty/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/__init__.py#L47

Added line #L47 was not covered by tests


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
hass.data[DOMAIN].pop(entry.entry_id)

Check warning on line 53 in homeassistant/components/iotty/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/__init__.py#L52-L53

Added lines #L52 - L53 were not covered by tests

return unload_ok

Check warning on line 55 in homeassistant/components/iotty/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/__init__.py#L55

Added line #L55 was not covered by tests
97 changes: 97 additions & 0 deletions homeassistant/components/iotty/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""API for iotty bound to Home Assistant OAuth."""

import asyncio
import logging
from typing import Any

from aiohttp import ClientSession
from iottycloud.cloudapi import CloudApi
from iottycloud.device import Device
from iottycloud.verbs import RESULT, STATUS

from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_oauth2_flow
from homeassistant.helpers.entity import Entity

from .const import IOTTYAPI_BASE, OAUTH2_CLIENT_ID

_LOGGER = logging.getLogger(__name__)


class IottyProxy(CloudApi):
"""Provide iotty authentication tied to an OAuth2 based config entry."""

_devices: list[Device]
_entities: dict
_coroutine: Any

def __init__(
self,
hass: HomeAssistant,
websession: ClientSession,
oauth_session: config_entry_oauth2_flow.OAuth2Session,
) -> None:
"""Initialize iotty auth."""

super().__init__(websession, IOTTYAPI_BASE, OAUTH2_CLIENT_ID)
self._oauth_session = oauth_session
self._devices = []
self._entities = {}
self._hass = hass

Check warning on line 40 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L36-L40

Added lines #L36 - L40 were not covered by tests

async def init(self):
"""Initialize iotty middleware."""
self._devices = await self.get_devices()
self._coroutine = self._hass.async_create_background_task(

Check warning on line 45 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L44-L45

Added lines #L44 - L45 were not covered by tests
self._polling(), "polling_task"
)

async def devices(self, device_type: str) -> Any:
"""Get devices for a specific type."""

_LOGGER.debug("There are %d devices", len(self._devices))

Check warning on line 52 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L52

Added line #L52 was not covered by tests

ret = [d for d in self._devices if d.device_type == device_type]

Check warning on line 54 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L54

Added line #L54 was not covered by tests

return ret

Check warning on line 56 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L56

Added line #L56 was not covered by tests

def store_entity(self, device_id: str, entity: Entity) -> None:
"""Test."""
_LOGGER.debug("store_entity %s", device_id)
self._entities[device_id] = entity

Check warning on line 61 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L60-L61

Added lines #L60 - L61 were not covered by tests

async def _polling(self) -> None:
pburgio marked this conversation as resolved.
Show resolved Hide resolved
"""Continuous polling from iottyCloud."""
while True:
_LOGGER.debug("_polling routine from iottyCloud")

Check warning on line 66 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L65-L66

Added lines #L65 - L66 were not covered by tests

for device in self._devices:
res = await self.get_status(device.device_id)

Check warning on line 69 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L68-L69

Added lines #L68 - L69 were not covered by tests

if RESULT not in res or STATUS not in res[RESULT]:
_LOGGER.warning(

Check warning on line 72 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L71-L72

Added lines #L71 - L72 were not covered by tests
"Unable to read status for device %s", device.device_id
)

status = res[RESULT][STATUS]
_LOGGER.debug("status: '%s' for device %s", status, device.device_id)
device.update_status(status)

Check warning on line 78 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L76-L78

Added lines #L76 - L78 were not covered by tests

if device.device_id not in self._entities:
_LOGGER.warning(

Check warning on line 81 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L80-L81

Added lines #L80 - L81 were not covered by tests
"Cannot find device %s (of type: %s) in _entities",
device.device_id,
device.device_type,
)
else:
self._entities[device.device_id].schedule_update_ha_state()

Check warning on line 87 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L87

Added line #L87 was not covered by tests

await asyncio.sleep(5)

Check warning on line 89 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L89

Added line #L89 was not covered by tests
pburgio marked this conversation as resolved.
Show resolved Hide resolved

async def async_get_access_token(self) -> str:
"""Return a valid access token."""

if not self._oauth_session.valid_token:
await self._oauth_session.async_ensure_token_valid()

Check warning on line 95 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L94-L95

Added lines #L94 - L95 were not covered by tests

return self._oauth_session.token["access_token"]

Check warning on line 97 in homeassistant/components/iotty/api.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/api.py#L97

Added line #L97 was not covered by tests
14 changes: 14 additions & 0 deletions homeassistant/components/iotty/application_credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""application_credentials platform the iotty integration."""
emontnemery marked this conversation as resolved.
Show resolved Hide resolved

from homeassistant.components.application_credentials import AuthorizationServer
from homeassistant.core import HomeAssistant

from .const import OAUTH2_AUTHORIZE, OAUTH2_TOKEN


async def async_get_authorization_server(hass: HomeAssistant) -> AuthorizationServer:
"""Return authorization server."""
return AuthorizationServer(
authorize_url=OAUTH2_AUTHORIZE,
token_url=OAUTH2_TOKEN,
)
19 changes: 19 additions & 0 deletions homeassistant/components/iotty/config_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Config flow for iotty."""
import logging

from homeassistant.helpers import config_entry_oauth2_flow

from .const import DOMAIN


class OAuth2FlowHandler(
config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=DOMAIN
):
"""Config flow to handle iotty OAuth2 authentication."""

DOMAIN = DOMAIN

@property
def logger(self) -> logging.Logger:
"""Return logger."""
return logging.getLogger(__name__)

Check warning on line 19 in homeassistant/components/iotty/config_flow.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/config_flow.py#L19

Added line #L19 was not covered by tests
9 changes: 9 additions & 0 deletions homeassistant/components/iotty/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Constants for the iotty integration."""

DOMAIN = "iotty"

OAUTH2_AUTHORIZE = "https://auth.iotty.com/.auth/oauth2/login"
OAUTH2_TOKEN = "https://auth.iotty.com/.auth/oauth2/token"
OAUTH2_CLIENT_ID = "hass-iotty"

IOTTYAPI_BASE = "https://cloudapi.iotty.com/"
14 changes: 14 additions & 0 deletions homeassistant/components/iotty/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"domain": "iotty",
"name": "iotty",
"codeowners": ["@pburgio"],
"config_flow": true,
"dependencies": ["application_credentials"],
"documentation": "https://www.home-assistant.io/integrations/iotty",
"homekit": {},
pburgio marked this conversation as resolved.
Show resolved Hide resolved
"integration_type": "device",
"iot_class": "cloud_polling",
"requirements": ["iottycloud==0.1.0"],
"ssdp": [],
"zeroconf": []
}
21 changes: 21 additions & 0 deletions homeassistant/components/iotty/strings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"config": {
"step": {
"pick_implementation": {
"title": "[%key:common::config_flow::title::oauth2_pick_implementation%]"
}
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]",
"already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]",
"oauth_error": "[%key:common::config_flow::abort::oauth2_error%]",
"missing_configuration": "[%key:common::config_flow::abort::oauth2_missing_configuration%]",
"authorize_url_timeout": "[%key:common::config_flow::abort::oauth2_authorize_url_timeout%]",
"no_url_available": "[%key:common::config_flow::abort::oauth2_no_url_available%]",
"user_rejected_authorize": "[%key:common::config_flow::abort::oauth2_user_rejected_authorize%]"
},
"create_entry": {
"default": "[%key:common::config_flow::create_entry::authenticated%]"
}
}
}
92 changes: 92 additions & 0 deletions homeassistant/components/iotty/switch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""Turn the entity on."""
import logging
from typing import Any

Check warning on line 3 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L2-L3

Added lines #L2 - L3 were not covered by tests

from iottycloud.lightswitch import LightSwitch
from iottycloud.verbs import LS_DEVICE_TYPE_UID

Check warning on line 6 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L5-L6

Added lines #L5 - L6 were not covered by tests

from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

Check warning on line 12 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L8-L12

Added lines #L8 - L12 were not covered by tests

from .api import IottyProxy
from .const import DOMAIN

Check warning on line 15 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L14-L15

Added lines #L14 - L15 were not covered by tests

_LOGGER = logging.getLogger(__name__)

Check warning on line 17 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L17

Added line #L17 was not covered by tests


class IottyLightSwitch(SwitchEntity):

Check warning on line 20 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L20

Added line #L20 was not covered by tests
pburgio marked this conversation as resolved.
Show resolved Hide resolved
edenhaus marked this conversation as resolved.
Show resolved Hide resolved
"""Haas entity class for iotty LightSwitch."""

_attr_entity_category = EntityCategory.CONFIG
emontnemery marked this conversation as resolved.
Show resolved Hide resolved
_attr_device_class = SwitchDeviceClass.SWITCH
_iotty_cloud: Any
_iotty_device: Any

Check warning on line 26 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L23-L26

Added lines #L23 - L26 were not covered by tests
pburgio marked this conversation as resolved.
Show resolved Hide resolved

# _attr_should_poll = False

def __init__(self, iotty: IottyProxy, iotty_device: LightSwitch) -> None:

Check warning on line 30 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L30

Added line #L30 was not covered by tests
"""Initialize the LightSwitch device."""
_LOGGER.debug(

Check warning on line 32 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L32

Added line #L32 was not covered by tests
"__init__ (%s) %s", iotty_device.device_type, iotty_device.device_id
)

super().__init__()
self._iotty_cloud = iotty
self._iotty_device = iotty_device

Check warning on line 38 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L36-L38

Added lines #L36 - L38 were not covered by tests

@property
def device_id(self) -> str:

Check warning on line 41 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L40-L41

Added lines #L40 - L41 were not covered by tests
"""Get the ID of this iotty Device."""
return self._iotty_device.device_id

Check warning on line 43 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L43

Added line #L43 was not covered by tests

emontnemery marked this conversation as resolved.
Show resolved Hide resolved
@property
def name(self) -> str:

Check warning on line 46 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L45-L46

Added lines #L45 - L46 were not covered by tests
pburgio marked this conversation as resolved.
Show resolved Hide resolved
"""Get the name of this iotty Device."""
return self._iotty_device.name

Check warning on line 48 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L48

Added line #L48 was not covered by tests

@property
def is_on(self) -> bool:

Check warning on line 51 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L50-L51

Added lines #L50 - L51 were not covered by tests
"""Return true if the LightSwitch is on."""
_LOGGER.debug(

Check warning on line 53 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L53

Added line #L53 was not covered by tests
"is_on %s ? %s", self._iotty_device.device_id, self._iotty_device.is_on
)
return self._iotty_device.is_on

Check warning on line 56 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L56

Added line #L56 was not covered by tests

async def async_turn_on(self, **kwargs: Any) -> None:

Check warning on line 58 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L58

Added line #L58 was not covered by tests
"""Turn the LightSwitch on."""
_LOGGER.debug("[%s] async_turn_on", self._iotty_device.device_id)
await self._iotty_cloud.command(

Check warning on line 61 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L60-L61

Added lines #L60 - L61 were not covered by tests
self._iotty_device.device_id, self._iotty_device.cmd_turn_on()
)

async def async_turn_off(self, **kwargs: Any) -> None:

Check warning on line 65 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L65

Added line #L65 was not covered by tests
"""Turn the LightSwitch off."""
_LOGGER.debug("[%s] async_turn_off", self._iotty_device.device_id)
await self._iotty_cloud.command(

Check warning on line 68 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L67-L68

Added lines #L67 - L68 were not covered by tests
self._iotty_device.device_id, self._iotty_device.cmd_turn_off()
)


async def async_setup_entry(

Check warning on line 73 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L73

Added line #L73 was not covered by tests
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Activate the iotty LightSwitch component."""
_LOGGER.debug("async_setup_entry id is %s", config_entry.entry_id)

Check warning on line 79 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L79

Added line #L79 was not covered by tests

iotty = hass.data[DOMAIN][config_entry.entry_id]
_ls_list = await iotty.devices(LS_DEVICE_TYPE_UID)

Check warning on line 82 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L81-L82

Added lines #L81 - L82 were not covered by tests

_LOGGER.info("Found %d LightSwitches", len(_ls_list))

Check warning on line 84 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L84

Added line #L84 was not covered by tests
pburgio marked this conversation as resolved.
Show resolved Hide resolved

entities = []
for _ls in _ls_list:
new_entity = IottyLightSwitch(iotty, _ls)
iotty.store_entity(_ls.device_id, new_entity)
entities.append(new_entity)

Check warning on line 90 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L86-L90

Added lines #L86 - L90 were not covered by tests

async_add_entities(entities)

Check warning on line 92 in homeassistant/components/iotty/switch.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/iotty/switch.py#L92

Added line #L92 was not covered by tests
1 change: 1 addition & 0 deletions homeassistant/generated/application_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"google_sheets",
"google_tasks",
"home_connect",
"iotty",
"lametric",
"lyric",
"neato",
Expand Down
1 change: 1 addition & 0 deletions homeassistant/generated/config_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
"intellifire",
"ios",
"iotawatt",
"iotty",
"ipma",
"ipp",
"iqvia",
Expand Down
6 changes: 6 additions & 0 deletions homeassistant/generated/integrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -2685,6 +2685,12 @@
"config_flow": true,
"iot_class": "local_polling"
},
"iotty": {
"name": "iotty",
"integration_type": "device",
"config_flow": true,
"iot_class": "cloud_polling"
},
"iperf3": {
"name": "Iperf3",
"integration_type": "hub",
Expand Down
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,9 @@ insteon-frontend-home-assistant==0.4.0
# homeassistant.components.intellifire
intellifire4py==2.2.2

# homeassistant.components.iotty
iottycloud==0.1.0

# homeassistant.components.iperf3
iperf3==0.1.11

Expand Down
3 changes: 3 additions & 0 deletions requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,9 @@ insteon-frontend-home-assistant==0.4.0
# homeassistant.components.intellifire
intellifire4py==2.2.2

# homeassistant.components.iotty
iottycloud==0.1.0

# homeassistant.components.gogogate2
ismartgate==5.0.1

Expand Down
1 change: 1 addition & 0 deletions tests/components/iotty/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests for iotty."""
Loading
Loading