Skip to content

Sensors interface #1731

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 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 19 additions & 1 deletion sdk/types/scrypted_python/scrypted_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class ScryptedInterface(str, Enum):
ScryptedSystemDevice = "ScryptedSystemDevice"
ScryptedUser = "ScryptedUser"
SecuritySystem = "SecuritySystem"
Sensors = "Sensors"
Settings = "Settings"
Sleep = "Sleep"
StartStop = "StartStop"
Expand Down Expand Up @@ -232,6 +233,16 @@ class SecuritySystemMode(str, Enum):
HomeArmed = "HomeArmed"
NightArmed = "NightArmed"

class Sensor(TypedDict):

name: str
value: str | float
unit: str

class Sensors:

sensors: Mapping[str, Sensor]

class SecuritySystemObstruction(str, Enum):

Error = "Error"
Expand Down Expand Up @@ -964,7 +975,7 @@ class TamperState(TypedDict):
pass


TYPES_VERSION = "0.3.108"
TYPES_VERSION = "0.3.109"


class AirPurifier:
Expand Down Expand Up @@ -2679,6 +2690,13 @@ def systemDevice(self, value: ScryptedSystemDeviceInfo):
"buttons"
]
},
"Sensors": {
"name": "Sensors",
"methods": [],
"properties": [
"sensors"
]
},
"PressButtons": {
"name": "PressButtons",
"methods": [
Expand Down
11 changes: 11 additions & 0 deletions sdk/types/src/types.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ export interface Buttons {
buttons?: ('doorbell' | string)[];
}

export interface Sensor {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name is required? what names are you using?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For homeassistant, the id would be the entity_id, which could be pragmatic, friendly_name can give a bit of context. Most of the times entity IDs are autogenerated and not comprehensible

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha, are there any other things you think might be necessary on the interface?

my thinking is if it starts duplicating properties from all of ScryptedDevice it may just be better to use a sub device.

Copy link
Contributor Author

@apocaliss92 apocaliss92 Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is enough, the unit can tell almost everything on how to treat the values
Scrypted needs something like this imho to avoid have thousand of different devices holding just 1 value

name: string;
value?: string | number;
unit?: string;
}

export interface Sensors {
sensors: Record<string, Sensor>;
}

export interface PressButtons {
pressButton(button: string): Promise<void>;
}
Expand Down Expand Up @@ -2287,6 +2297,7 @@ export enum ScryptedInterface {
ColorSettingHsv = "ColorSettingHsv",
Buttons = "Buttons",
PressButtons = "PressButtons",
Sensors = "Sensors",
Notifier = "Notifier",
StartStop = "StartStop",
Pause = "Pause",
Expand Down
Loading