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

3
.gitmodules vendored
View File

@@ -16,3 +16,6 @@
[submodule "external/axios-digest-auth"]
path = external/axios-digest-auth
url = git@github.com:koush/axios-digest-auth
[submodule "external/sort"]
path = external/sort
url = https://github.com/abewley/sort

1
external/sort vendored Submodule

Submodule external/sort added at bce9f0d1fc

View File

@@ -23,7 +23,6 @@
"localRoot": "${workspaceFolder}/src",
"remoteRoot": "${config:scrypted.pythonRemoteRoot}"
},
]
}
]

View File

@@ -12,11 +12,11 @@
"scrypted-webpack": "scrypted-webpack"
},
"scrypted": {
"name": "Python Light",
"name": "Python DeviceProvider",
"runtime": "python",
"type": "Light",
"type": "DeviceProvider",
"interfaces": [
"OnOff"
"DeviceProvider"
]
},
"dependencies": {

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()