SmartThings API is optional. You will need to set these parameters only if you want to use inputs! Please follow this tutorial.
"
+ "type": "help",
+ "helpvalue": "
SmartThings API is optional but highly recommended for more reliable power state (see \"Use SmartThings for Power State\") detection and input management. If provided, it will be used for enhanced functionality such as fetching the power state more effectively and managing inputs. Please follow this tutorial to set it up.
"
},
{
"key": "devices[].api_key",
@@ -274,7 +274,14 @@
{
"key": "devices[].device_id",
"title": "Device ID"
- }
+ },
+ {
+ "key": "devices[].use_smartthings_power",
+ "type": "boolean",
+ "default": false,
+ "title": "Use SmartThings for Power State",
+ "description": "Enable to use the SmartThings API to check the power state of the TV. This could provide more accurate power readings. Ensure you have provided a valid API Key and Device ID."
+ }
]
},
{
@@ -285,7 +292,7 @@
"items": [
{
"type": "help",
- "helpvalue": "
By default no inputs are set. Use this section to set your own inputs. You can find more informations on our documentation.
"
+ "helpvalue": "
By default, no inputs are set. Use this section to configure your own inputs. For more information, please refer to our documentation.
This section give you the option to create custom switches (separated accessories) that make specific actions. You can find more informations on our documentation.
"
+ "helpvalue": "
This section allows you to create custom switches (separate accessories) that perform specific actions. For more information, please visit our documentation.
"
},
{
"type": "array",
@@ -477,7 +484,7 @@
"wss": "Default",
"frame": "Frame"
},
- "description": "The plugin detects the type of TV automaticaly. Leave this option set to None unless you are having problems and the plugin don't detect your TV type correctly."
+ "description": "The plugin detects the type of TV automatically. Leave this option set to None unless you are having problems and the plugin don't detect your TV type correctly."
},
{
"key": "devices[].uuid",
@@ -489,14 +496,14 @@
"key": "devices[].delay",
"title": "Command Delay Interval",
"placeholder": "400",
- "description": "This is the delay between each command when you send multiple commands. By lowering the value you risk the commands not being executed. Value is in miliseconds."
+ "description": "This is the delay between each command when you send multiple commands. By lowering the value you risk the commands not being executed. Value is in milliseconds."
},
{
"key": "devices[].options",
"title": "Options",
"titleMap": {
- "Switch.DeviceName.Disable": "Disable prepending device name on custom switches",
- "Frame.RealPowerMode": "Display and control Real Power with Main Acccessory (for Frame TVs)",
+ "Switch.DeviceName.Disable": "Disable prepending the device name on custom switches",
+ "Frame.RealPowerMode": "Display and control Real Power with Main Accessory (for Frame TVs)",
"Frame.ArtSwitch.Disable": "Disable Art Switch (for Frame TVs)",
"Frame.PowerSwitch.Disable": "Disable Power Switch (for Frame TVs)"
}
@@ -511,7 +518,7 @@
"items": [
{
"type": "help",
- "helpvalue": "
You don't have to edit this section unless you want to change the default commands for Remote Control buttons. You can find more informations on our documentation.
",
+ "helpvalue": "
You do not need to edit this section unless you want to change the default commands for Remote Control buttons. For more information, please refer to our documentation.
",
"flex": "1 1 100%"
},
{
diff --git a/lib/device.js b/lib/device.js
index 946444a..ab693ba 100644
--- a/lib/device.js
+++ b/lib/device.js
@@ -23,7 +23,8 @@ module.exports = class Device extends EventEmitter {
wol : {},
options : [],
api_key : null,
- device_id : null
+ device_id : null,
+ use_smartthings_power : false
},
Platform.config,
config
diff --git a/lib/methods/base.js b/lib/methods/base.js
index a44722a..5b6ed69 100644
--- a/lib/methods/base.js
+++ b/lib/methods/base.js
@@ -19,21 +19,32 @@ module.exports = class Base {
this.cache = device.cache;
}
+ /**
+ * Cleans up resources or state.
+ */
destroy() {
this.destroyed = true;
}
+ /**
+ * Simulates a pairing delay.
+ * @return {Promise}
+ */
pair() {
return utils.delay(500);
}
/**
- * Get state of TV with cache
- * @return {Cache}
+ * Retrieves the TV's power state by first attempting a network ping.
+ * If the ping succeeds, it validates the power state via HTTP.
+ * If the ping fails, it assumes the TV is off, unless previously recorded as on.
+ * @return {Promise} Resolves with true if on, false if off.
*/
getState() {
return this.cache.get('state', () => this.getStatePing().then(status => {
+ this.device.log.debug(`Ping status: ${status}`);
if (status && this.device.storage.powerstate !== false) {
+ this.device.log.debug('Ping succeeded, fetching power state via HTTP...');
return this.cache.get('state-http', () => this.getStateHttp(status), 2500);
} else {
this.cache.forget('state-http');
@@ -44,10 +55,11 @@ module.exports = class Base {
}
/**
- * Get state of TV by sending a Ping
- * @return {Promise}
+ * Checks TV availability via network ping.
+ * @return {Promise}
*/
getStatePing() {
+ this.device.log.debug(`Pinging ${this.ip} with timeout ${this.timeout}ms.`);
return isPortReachable(8001, {
host: this.ip,
timeout: this.timeout
@@ -55,13 +67,15 @@ module.exports = class Base {
}
/**
- * Get state of TV from PowerState response
- * @param {boolean} fallback
- * @return {Promise}
+ * Fetches the TV's power state via its local API.
+ * @param {boolean} fallback - Fallback value if HTTP request fails.
+ * @return {Promise}
*/
getStateHttp(fallback = false) {
+ this.device.log.debug(`Fetching power state from ${this.ip} local TV API.`);
return this.getInfo().then(data => {
if (data.device && data.device.PowerState) {
+ this.device.log.debug(`Power state: ${data.device.PowerState}`);
return data.device.PowerState == 'on';
}
@@ -71,8 +85,8 @@ module.exports = class Base {
}
/**
- * Turn the TV On
- * @return {Promise}
+ * Powers on the TV. Uses Wake-on-LAN if necessary.
+ * @return {Promise}
*/
async setStateOn() {
// If TV is in Sleep mode just send command
@@ -90,16 +104,16 @@ module.exports = class Base {
}
/**
- * Turn the TV Off
- * @return {Promise}
+ * Powers off the TV.
+ * @return {Promise}
*/
setStateOff() {
return this.click('KEY_POWER');
}
/**
- * Get TV informations
- * @return {Promise}
+ * Retrieves device information from the TV's API.
+ * @return {Promise