Skip to content
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

Added detection of level.direction #86

Merged
merged 3 commits into from
Jan 15, 2025
Merged
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
12 changes: 8 additions & 4 deletions DEVICES.md
Original file line number Diff line number Diff line change
@@ -108,7 +108,8 @@ In [brackets] is given the class name of device.
| | TILT_STOP | button.stop.tilt | | boolean | W | E | | | `/^button\.stop\.tilt$/` |
| | TILT_OPEN | button.open.tilt | | boolean | W | E | | | `/^button\.open\.tilt$/` |
| | TILT_CLOSE | button.close.tilt | | boolean | W | E | | | `/^button\.close\.tilt$/` |
| | DIRECTION | indicator.direction | | | | | X | | `/^indicator\.direction$/` |
| | DIRECTION | indicator.direction | | boolean | | | X | | `/^indicator\.direction$/` |
| | DIRECTION | value.direction | | number | | | | | `/^(indicator|value)\.direction$/` |
| | WORKING | indicator.working | | | | | X | | `/^indicator\.working$/` |
| | UNREACH | indicator.maintenance.unreach | | boolean | | | X | | `/^indicator(\.maintenance)?\.unreach$/` |
| | LOWBAT | indicator.maintenance.lowbat | | boolean | | | X | | `/^indicator(\.maintenance)?\.lowbat$|^indicator(\.maintenance)?\.battery$/` |
@@ -130,7 +131,8 @@ In [brackets] is given the class name of device.
| | TILT_STOP | button.stop.tilt | | boolean | W | E | | | `/^button\.stop\.tilt$/` |
| | TILT_OPEN | button.open.tilt | | boolean | W | E | | | `/^button\.open\.tilt$/` |
| | TILT_CLOSE | button.close.tilt | | boolean | W | E | | | `/^button\.close\.tilt$/` |
| | DIRECTION | indicator.direction | | | | | X | | `/^indicator\.direction$/` |
| | DIRECTION | indicator.direction | | boolean | | | X | | `/^indicator\.direction$/` |
| | DIRECTION | value.direction | | number | | | | | `/^(indicator|value)\.direction$/` |
| | WORKING | indicator.working | | | | | X | | `/^indicator\.working$/` |
| | UNREACH | indicator.maintenance.unreach | | boolean | | | X | | `/^indicator(\.maintenance)?\.unreach$/` |
| | LOWBAT | indicator.maintenance.lowbat | | boolean | | | X | | `/^indicator(\.maintenance)?\.lowbat$|^indicator(\.maintenance)?\.battery$/` |
@@ -292,7 +294,8 @@ In [brackets] is given the class name of device.
| * | SET | switch.gate | | boolean | W | E | | | `/^switch(\.gate)?$/` |
| | ACTUAL | value.blind | % | number | | E | | | `/^value(\.position)?|^value(\.gate)?$/` |
| | STOP | button.stop | | boolean | W | E | | | `/^button\.stop$|^action\.stop$/` |
| | DIRECTION | indicator.direction | | | | | X | | `/^indicator\.direction$/` |
| | DIRECTION | indicator.direction | | boolean | | | X | | `/^indicator\.direction$/` |
| | DIRECTION | value.direction | | number | | | | | `/^(indicator|value)\.direction$/` |
| | WORKING | indicator.working | | | | | X | | `/^indicator\.working$/` |
| | UNREACH | indicator.maintenance.unreach | | boolean | | | X | | `/^indicator(\.maintenance)?\.unreach$/` |
| | MAINTAIN | indicator.maintenance | | boolean | | | X | | `/^indicator\.maintenance$/` |
@@ -435,7 +438,8 @@ In [brackets] is given the class name of device.
| * | SET | switch.lock | | boolean | W | | | `/^switch\.lock$/` |
| | ACTUAL | state | | boolean | - | | | `/^state$/` |
| | OPEN | button | | boolean | W | | | |
| | DIRECTION | indicator.direction | | | | X | | `/^indicator\.direction$/` |
| | DIRECTION | indicator.direction | | boolean | | X | | `/^indicator\.direction$/` |
| | DIRECTION | value.direction | | number | | | | `/^(indicator|value)\.direction$/` |
| | WORKING | indicator.working | | | | X | | `/^indicator\.working$/` |
| | UNREACH | indicator.maintenance.unreach | | boolean | | X | | `/^indicator(\.maintenance)?\.unreach$/` |
| | LOWBAT | indicator.maintenance.lowbat | | boolean | | X | | `/^indicator(\.maintenance)?\.lowbat$|^indicator(\.maintenance)?\.battery$/` |
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018-2024 Denis Haev <dogafox@gmail.com>
Copyright (c) 2018-2025 Denis Haev <dogafox@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -96,6 +96,10 @@ if (controls) {
-->

## Changelog
### **WORK IN PROGRESS**

- (@GermanBluefox) Added detection of `level.direction`

### 4.1.1 (2024-12-15)
- (@Apollon77) Fixed default unit for Illuminance to "lux"
- (@Apollon77) Added Low-Battery state for switch to be consistent with other devices
@@ -106,7 +110,7 @@ if (controls) {
- (@Garfonso) Added battery state
- (@Garfonso) Added the transition time state
- (@Garfonso) Allowed the mixed `device->state` and `device->channel->state` structures
- (@GermanBluefox) Used new eslint config library
- (@GermanBluefox) Used a new eslint config library
- (@GermanBluefox) Types were slightly changed
- (Apollon77) Removed File state type
- (Apollon77) Adjusted Camera states to remove Binary state and replace by link
@@ -256,6 +260,6 @@ if (controls) {

## License

Copyright (c) 2018-2024 Denis Haev <dogafox@gmail.com>
Copyright (c) 2018-2025 Denis Haev <dogafox@gmail.com>

MIT License
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
"@iobroker/eslint-config": "^1.0.0",
"chai": "^4.5.0",
"mocha": "^11.0.1",
"typescript": "~5.7.2"
"typescript": "~5.7.3"
},
"bugs": {
"url": "https://github.com/ioBroker/ioBroker.type-detector/issues"
15 changes: 15 additions & 0 deletions src/TypePatterns.ts
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ const SharedPatterns: {
maintain: InternalDetectorState;
error: InternalDetectorState;
direction: InternalDetectorState;
direction_enum: InternalDetectorState;
reachable: InternalDetectorState;
battery: InternalDetectorState;
} = {
@@ -83,11 +84,21 @@ const SharedPatterns: {
direction: {
role: /^indicator\.direction$/,
indicator: true,
type: StateType.Boolean,
notSingle: true,
name: 'DIRECTION',
required: false,
defaultRole: 'indicator.direction',
},
direction_enum: {
role: /^(indicator|value)\.direction$/, // some old adapters implement `indicator.direction` even for number types. So try to detect it too
type: StateType.Number,
notSingle: true,
name: 'DIRECTION',
required: false,
defaultStates: { 0: 'None', 1: 'Up/Open', 2: 'Down/Close', 3: 'Unknown' },
defaultRole: 'value.direction',
},
reachable: {
role: /^indicator\.reachable$/,
indicator: true,
@@ -1937,6 +1948,7 @@ export const patterns: { [key: string]: InternalPatternControl } = {
defaultRole: 'button.close.tilt',
},
SharedPatterns.direction,
SharedPatterns.direction_enum,
SharedPatterns.working,
SharedPatterns.unreach,
SharedPatterns.lowbat,
@@ -2036,6 +2048,7 @@ export const patterns: { [key: string]: InternalPatternControl } = {
defaultRole: 'button.close.tilt',
},
SharedPatterns.direction,
SharedPatterns.direction_enum,
SharedPatterns.working,
SharedPatterns.unreach,
SharedPatterns.lowbat,
@@ -2080,6 +2093,7 @@ export const patterns: { [key: string]: InternalPatternControl } = {
defaultRole: 'button.stop',
},
SharedPatterns.direction,
SharedPatterns.direction_enum,
SharedPatterns.working,
SharedPatterns.unreach,
SharedPatterns.maintain,
@@ -2296,6 +2310,7 @@ export const patterns: { [key: string]: InternalPatternControl } = {
defaultRole: 'button',
},
SharedPatterns.direction,
SharedPatterns.direction_enum,
SharedPatterns.working,
SharedPatterns.unreach,
SharedPatterns.lowbat,
10 changes: 5 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2018-2023 bluefox <dogafox@gmail.com>
* Copyright 2018-2025 bluefox <dogafox@gmail.com>
*
* The MIT License (MIT)
*
@@ -86,13 +86,13 @@ export interface InternalDetectorState {
min?: StateType; // type of attribute: number', 'string' or 'boolean'. This attribute must exist in common
max?: StateType; // type of attribute: number', 'string' or 'boolean'. This attribute must exist in common
required?: boolean; // if required to detect the pattern as valid
noSubscribe?: boolean; // no automatic subscription for this state (e.g., if write only)
searchInParent?: boolean; // if this pattern should be search in a device too and not only in channel
noSubscribe?: boolean; // no automatic subscription for this state (e.g., if write-only)
searchInParent?: boolean; // if this pattern should be searched in a device too and not only in channel
enums?: (obj: ioBroker.Object, enums: string[]) => boolean; // function to execute custom category detection
multiple?: boolean; // if more than one state may have this pattern in channel
noDeviceDetection?: boolean; // do not search indicators in parent device
noDeviceDetection?: boolean; // do not search indicators in a parent device
notSingle?: boolean; // this state may belong to more than one tile simultaneously (e.g., volume tile and media with volume)
inverted?: boolean; // is state of indicator must be inverted
inverted?: boolean; // if the state of indicator must be inverted
stateName?: RegExp; // regex for state names (IDs). Not suggested
defaultStates?: { [key: string]: string }; // is for detection irrelevant, but will be used by iobroker.devices.
defaultRole?: string; // is for detection irrelevant, but will be used by iobroker.devices - only states WITH defaultRole will show up in UI.