-
-
Notifications
You must be signed in to change notification settings - Fork 36.4k
Add integration for iotty Smart Home #103073
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
Merged
Merged
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 fc35303
Fixes to URL, and removed commits
pburgio 3c25e8f
Initial import 0.0.2
pburgio 2b2022a
Fixes to URL, and removed commits
pburgio 0f8be23
Added first test for iotty
pburgio f6c9bb6
First release
pburgio ae97d6f
Merge branch 'iotty' of https://iotty.visualstudio.com/iotty/_git/hom…
pburgio 213478f
Merge branch 'dev' into iotty
pburgio 2dfbcac
Merge branch 'dev' into iotty
pburgio fdbef16
Reviewers request #1
pburgio ac38fc5
Merge branch 'dev' into iotty
pburgio cd56f98
Merge branch 'iotty' of https://github.com/pburgio/homeassistant.core…
pburgio f27bb4b
Removed commmented code
pburgio 938a9af
Some modifications
pburgio 31a8d01
Modified REST EP for iotty CloudApi
pburgio fb65b75
Merge branch 'dev' into iotty
pburgio 63c4b2b
Initial import 0.0.2
pburgio 3525d64
Fixes to URL, and removed commits
pburgio 2a3d779
Added first test for iotty
pburgio d6a02a4
First release
pburgio b5223a5
Rebased and resolved conflicts
pburgio 014c3e5
Rebased and resolved conflicts
pburgio 0903fbd
Reviewers request #1
pburgio c719025
Removed commmented code
pburgio a7b9348
Some modifications
pburgio fea0e1d
Modified REST EP for iotty CloudApi
pburgio 4c77d3f
Removed empty entries in manifest.json
pburgio 0895ce4
Added test_config_flow
pburgio 102cc67
Resolved conflicts
pburgio 852e63e
Merge branch 'home-assistant:dev' into iotty
pburgio 263b056
Merge branch 'dev' into iotty
pburgio 2446c28
Fix as requested by @edenhaus
pburgio a8171e6
Merge branch 'dev' into iotty
pburgio 42df504
Merge branch 'home-assistant:dev' into iotty
pburgio a4bbf4d
Merge branch 'iotty' of https://github.com/pburgio/homeassistant.core…
pburgio fa97a76
Merge branch 'dev' into iotty
pburgio 41d1d5a
Merge branch 'iotty' of https://github.com/pburgio/homeassistant.core…
pburgio ab6afb1
Added test_init
pburgio 1adc04d
Removed comments, added one assert
pburgio a137732
Added TEST_CONFIG_FLOW
pburgio def435b
Added test for STORE_ENTITY
pburgio 2378530
Increased code coverage
pburgio a2c2e37
Full coverage for api.py
pburgio c72dec7
Added tests for switch component
pburgio 6b4ac81
Merge branch 'dev' into iotty
pburgio f0d1c82
Merge branch 'dev' into iotty
pburgio fd9d6b9
Merge branch 'iotty' of https://github.com/pburgio/homeassistant.core…
pburgio 235d95d
Converted INFO logs onto DEBUG logs
pburgio 57f93c7
Merge branch 'dev' into iotty
pburgio d9c1e7c
Merge branch 'iotty' of https://github.com/pburgio/homeassistant.core…
pburgio e131b4f
Merge branch 'dev' into iotty
pburgio e5657db
Merge branch 'dev' into iotty
pburgio ddd9155
Merge branch 'dev' into iotty
pburgio aa7d87c
Merge branch 'dev' into iotty
pburgio f6e8269
Merge branch 'dev' into iotty
pburgio 2406cea
Merge branch 'home-assistant:dev' into iotty
pburgio 45993ed
Removed .gitignore from commits
pburgio ef16522
Modifications to SWITCH.PY
pburgio 860cb78
Merge branch 'dev' into iotty
pburgio fb520ad
Initial import 0.0.2
pburgio b57182b
Fixes to URL, and removed commits
pburgio a6d9f43
Added first test for iotty
pburgio fd14b35
First release
pburgio 9954782
Rebased and resolved conflicts
pburgio b3e4195
Fixed conflicts
pburgio dc47223
Reviewers request #1
pburgio f3bf64b
Removed commmented code
pburgio 5df2e39
Some modifications
pburgio 85c85a7
Modified REST EP for iotty CloudApi
pburgio 7924c27
Removed empty entries in manifest.json
pburgio 40dd193
Added test_config_flow
pburgio 90c5cb5
Some modifications
pburgio 2874d26
Fix as requested by @edenhaus
pburgio 0d67c1c
Added test_init
pburgio 6c9054c
Removed comments, added one assert
pburgio d8ac598
Added TEST_CONFIG_FLOW
pburgio d5f447a
Added test for STORE_ENTITY
pburgio 202bdd7
Increased code coverage
pburgio 1c273e1
Full coverage for api.py
pburgio 4c30c1a
Added tests for switch component
pburgio eec1675
Converted INFO logs onto DEBUG logs
pburgio 76b20bb
Removed .gitignore from commits
pburgio 65317e0
Modifications to SWITCH.PY
pburgio c34e841
Fixed tests for SWITCH
pburgio f364332
Resolved conflicts
pburgio 92b5cd9
First working implementation of Coordinator
pburgio 3c07035
Increased code coverage
pburgio 291c89d
Full code coverage
pburgio 7d68719
Merge branch 'dev' into iotty
pburgio dec43e9
Missing a line in testing
pburgio 4953f33
Merge branch 'dev' into iotty
pburgio 3ab508c
Update homeassistant/components/iotty/__init__.py
pburgio d338e19
Update homeassistant/components/iotty/__init__.py
pburgio 02551d6
Modified coordinator as per request by edenhaus
pburgio e67903c
Merge branch 'dev' into iotty
pburgio 3df1fa7
use coordinator entities for switches
shapournemati-iotty 14ecf78
move platforms to constants
shapournemati-iotty 9b56504
Merge branch 'dev' into iotty
pburgio 6bc5d16
fix whitespace with ruff-format
shapournemati-iotty 2bf2cdd
Merge branch 'dev' into iotty
emontnemery 6371d37
correct iotty entry in application_credentials list
shapournemati-iotty 86b29da
Merge branch 'dev' into iotty
pburgio 84d9977
minor style improvements
shapournemati-iotty 0be59ce
refactor function name
shapournemati-iotty a3a32e0
Merge branch 'dev' into iotty
pburgio d2989f2
handle new and deleted devices
shapournemati-iotty fe9da43
Merge branch 'dev' into iotty
pburgio 4497c2c
Merge branch 'dev' into iotty
shapournemati-iotty d3b6cc5
improve code for adding devices after first initialization
shapournemati-iotty 56cf2cb
use typed config entry instead of adding known devices to hass.data
shapournemati-iotty 43e79c1
Merge branch 'dev' into iotty
pburgio 271e9e7
improve iotty entity removal
shapournemati-iotty a47a715
test listeners update cycle
shapournemati-iotty b02eea8
handle iotty as devices and not only as entities
shapournemati-iotty 02acc82
Merge branch 'dev' into iotty
shapournemati-iotty 01f8759
fix test typing for mock config entry
shapournemati-iotty 7278fec
test with fewer mocks for an integration test style opposed to the pr…
shapournemati-iotty 3328374
remove useless tests and add more integration style tests
shapournemati-iotty ce6e24e
check if device_to_remove is None
shapournemati-iotty 4eac992
integration style tests for turning switches on and off
shapournemati-iotty b6cbcff
remove redundant coordinator tests
shapournemati-iotty 4f14518
check device status after issuing command in tests
shapournemati-iotty 91cdb09
Merge branch 'dev' into iotty
shapournemati-iotty e87cead
remove unused fixtures
shapournemati-iotty 43c2662
add strict typing for iotty
shapournemati-iotty 055f775
Merge branch 'iotty' of https://github.com/pburgio/homeassistant.core…
shapournemati-iotty eb195a3
additional asserts and named snapshots in tests
shapournemati-iotty f07da58
fix mypy issues after enabling strict typing
shapournemati-iotty b90f820
upgrade iottycloud version to 0.1.3
shapournemati-iotty 383fc90
move coordinator to runtime_data
shapournemati-iotty c618e69
remove entity name
shapournemati-iotty c4ac6bb
fix typing issues
shapournemati-iotty 5e87f2a
coding style fixes
shapournemati-iotty 1399c04
improve tests coding style and assertion targets
shapournemati-iotty 967e260
test edge cases when apis are not working
shapournemati-iotty 0b17b2c
Merge branch 'dev' into iotty
pburgio 299d884
improve tests comments and assertions
shapournemati-iotty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .vscode/* | ||
|
|
||
| homeassistant/components/iotty/.vscode/* | ||
pburgio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # For your initial PR, limit it to 1 platform. | ||
pburgio marked this conversation as resolved.
Outdated
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.
Outdated
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.
Outdated
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) | ||
|
|
||
| iotty = api.IottyProxy(hass, aiohttp_client.async_get_clientsession(hass), session) | ||
|
|
||
| hass.async_add_job(iotty.init) | ||
|
|
||
| hass.data.setdefault(DOMAIN, {})[entry.entry_id] = iotty | ||
|
|
||
| await asyncio.sleep(3) | ||
pburgio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| 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) | ||
|
|
||
| return unload_ok | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| async def init(self): | ||
| """Initialize iotty middleware.""" | ||
| self._devices = await self.get_devices() | ||
| self._coroutine = self._hass.async_create_background_task( | ||
| 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)) | ||
|
|
||
| ret = [d for d in self._devices if d.device_type == device_type] | ||
|
|
||
| return ret | ||
|
|
||
| def store_entity(self, device_id: str, entity: Entity) -> None: | ||
| """Test.""" | ||
| _LOGGER.debug("store_entity %s", device_id) | ||
| self._entities[device_id] = entity | ||
|
|
||
| async def _polling(self) -> None: | ||
pburgio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Continuous polling from iottyCloud.""" | ||
| while True: | ||
| _LOGGER.debug("_polling routine from iottyCloud") | ||
|
|
||
| for device in self._devices: | ||
| res = await self.get_status(device.device_id) | ||
|
|
||
| if RESULT not in res or STATUS not in res[RESULT]: | ||
| _LOGGER.warning( | ||
| "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) | ||
|
|
||
| if device.device_id not in self._entities: | ||
| _LOGGER.warning( | ||
| "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() | ||
|
|
||
| await asyncio.sleep(5) | ||
pburgio marked this conversation as resolved.
Outdated
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() | ||
|
|
||
| return self._oauth_session.token["access_token"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Outdated
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, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Outdated
Show resolved
Hide resolved
|
||
| "integration_type": "device", | ||
| "iot_class": "cloud_polling", | ||
| "requirements": ["iottycloud==0.1.0"], | ||
| "ssdp": [], | ||
| "zeroconf": [] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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%]" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| """Turn the entity on.""" | ||
| import logging | ||
| from typing import Any | ||
|
|
||
| from iottycloud.lightswitch import LightSwitch | ||
| from iottycloud.verbs import LS_DEVICE_TYPE_UID | ||
|
|
||
| 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 | ||
|
|
||
| from .api import IottyProxy | ||
| from .const import DOMAIN | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class IottyLightSwitch(SwitchEntity): | ||
pburgio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
edenhaus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Haas entity class for iotty LightSwitch.""" | ||
|
|
||
| _attr_entity_category = EntityCategory.CONFIG | ||
emontnemery marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _attr_device_class = SwitchDeviceClass.SWITCH | ||
| _iotty_cloud: Any | ||
| _iotty_device: Any | ||
pburgio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # _attr_should_poll = False | ||
|
|
||
| def __init__(self, iotty: IottyProxy, iotty_device: LightSwitch) -> None: | ||
| """Initialize the LightSwitch device.""" | ||
| _LOGGER.debug( | ||
| "__init__ (%s) %s", iotty_device.device_type, iotty_device.device_id | ||
| ) | ||
|
|
||
| super().__init__() | ||
| self._iotty_cloud = iotty | ||
| self._iotty_device = iotty_device | ||
|
|
||
| @property | ||
| def device_id(self) -> str: | ||
| """Get the ID of this iotty Device.""" | ||
| return self._iotty_device.device_id | ||
|
|
||
emontnemery marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @property | ||
| def name(self) -> str: | ||
pburgio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Get the name of this iotty Device.""" | ||
| return self._iotty_device.name | ||
|
|
||
| @property | ||
| def is_on(self) -> bool: | ||
| """Return true if the LightSwitch is on.""" | ||
| _LOGGER.debug( | ||
| "is_on %s ? %s", self._iotty_device.device_id, self._iotty_device.is_on | ||
| ) | ||
| return self._iotty_device.is_on | ||
|
|
||
| async def async_turn_on(self, **kwargs: Any) -> None: | ||
| """Turn the LightSwitch on.""" | ||
| _LOGGER.debug("[%s] async_turn_on", self._iotty_device.device_id) | ||
| await self._iotty_cloud.command( | ||
| self._iotty_device.device_id, self._iotty_device.cmd_turn_on() | ||
| ) | ||
|
|
||
| async def async_turn_off(self, **kwargs: Any) -> None: | ||
| """Turn the LightSwitch off.""" | ||
| _LOGGER.debug("[%s] async_turn_off", self._iotty_device.device_id) | ||
| await self._iotty_cloud.command( | ||
| self._iotty_device.device_id, self._iotty_device.cmd_turn_off() | ||
| ) | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| 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) | ||
|
|
||
| iotty = hass.data[DOMAIN][config_entry.entry_id] | ||
| _ls_list = await iotty.devices(LS_DEVICE_TYPE_UID) | ||
|
|
||
| _LOGGER.info("Found %d LightSwitches", len(_ls_list)) | ||
pburgio marked this conversation as resolved.
Outdated
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) | ||
|
|
||
| async_add_entities(entities) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| "google_sheets", | ||
| "google_tasks", | ||
| "home_connect", | ||
| "iotty", | ||
| "lametric", | ||
| "lyric", | ||
| "neato", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,6 +225,7 @@ | |
| "intellifire", | ||
| "ios", | ||
| "iotawatt", | ||
| "iotty", | ||
| "ipma", | ||
| "ipp", | ||
| "iqvia", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Tests for iotty.""" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.