mirror of
https://github.com/koush/scrypted.git
synced 2026-02-03 06:03:27 +00:00
vscode-python: update sample
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -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
1
external/sort
vendored
Submodule
Submodule external/sort added at bce9f0d1fc
1
plugins/vscode-python/.vscode/launch.json
vendored
1
plugins/vscode-python/.vscode/launch.json
vendored
@@ -23,7 +23,6 @@
|
||||
"localRoot": "${workspaceFolder}/src",
|
||||
"remoteRoot": "${config:scrypted.pythonRemoteRoot}"
|
||||
},
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user