vscode-python: update sample

This commit is contained in:
Koushik Dutta
2021-12-02 20:45:39 -08:00
parent 5b0bc51fd8
commit 67b59f6e74
5 changed files with 33 additions and 8 deletions

View File

@@ -1,16 +1,38 @@
from __future__ import annotations
from typing import Any
import scrypted_sdk
import asyncio
from scrypted_sdk.types import OnOff
from scrypted_sdk.types import DeviceProvider, OnOff, ScryptedDeviceType, ScryptedInterface
class PythonLight(scrypted_sdk.ScryptedDeviceBase, OnOff):
def __init__(self, nativeId: str | None):
super().__init__(nativeId=nativeId)
async def turnOff(self) -> None:
print("turned off!")
self.print("turned off!")
self.on = False
async def turnOn(self) -> None:
print("turned on!")
self.print("turned on!")
self.on = True
class PythonDeviceProvider(scrypted_sdk.ScryptedDeviceBase, DeviceProvider):
def __init__(self):
super().__init__()
asyncio.run_coroutine_threadsafe(scrypted_sdk.deviceManager.onDevicesChanged({
'devices': [
{
'nativeId': 'light',
'interfaces': [ScryptedInterface.OnOff.value],
'type': ScryptedDeviceType.Light.value,
}
]
}), asyncio.get_event_loop())
async def getDevice(self, nativeId: str) -> Any:
return PythonLight(nativeId)
def create_scrypted_plugin():
return PythonLight()
return PythonDeviceProvider()