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

util._extend API deprecated & punycode module deprecated #303

Closed
kskenyon opened this issue Nov 24, 2024 · 8 comments
Closed

util._extend API deprecated & punycode module deprecated #303

kskenyon opened this issue Nov 24, 2024 · 8 comments
Assignees

Comments

@kskenyon
Copy link

[11/24/2024, 12:53:42 AM] [@danimal4326/homebridge-weather-plus] This plugin generated a warning from the characteristic 'Current Ambient Light Level': Characteristic not in required or optional characteristic section for service TemperatureSensor. Adding anyway.. See https://homebridge.io/w/JtMGR for more info.
(node:1189266) [DEP0060] DeprecationWarning: The util._extend API is deprecated. Please use Object.assign() instead.
(Use node --trace-deprecation ... to show where the warning was created)
(node:1189266) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.

@dacarson dacarson changed the title Misc. deprecation errors... util._extend API deprecated & punycode module deprecated Dec 4, 2024
@dacarson
Copy link
Collaborator

dacarson commented Dec 4, 2024

Tracking adding Characteristic issue here: #206
Request module is deprecated: #150

The other two sound new:

  1. (node:1189266) [DEP0060] DeprecationWarning: The util._extend API is deprecated. Please use Object.assign() instead.
    (Use node --trace-deprecation ... to show where the warning was created)
  2. (node:1189266) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.

Will use this ticket to track the two new issues.

@dacarson dacarson self-assigned this Dec 4, 2024
@dacarson
Copy link
Collaborator

dacarson commented Dec 4, 2024

Added the trace-deprecation flag and it says the psl? module is using it:

(node:901683) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
    at node:punycode:3:9
    at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:399:7)
    at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:338:10)
    at loadBuiltinModule (node:internal/modules/helpers:112:7)
    at Function._load (node:internal/modules/cjs/loader:1100:17)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:219:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:138:16)
    at Object.<anonymous> (/var/lib/homebridge/node_modules/homebridge-weather-plus/node_modules/psl/index.js:5:16)

@kskenyon
Copy link
Author

kskenyon commented Dec 4, 2024 via email

@kskenyon
Copy link
Author

kskenyon commented Dec 4, 2024 via email

@dacarson
Copy link
Collaborator

dacarson commented Dec 4, 2024

Thank you!

dacarson added a commit that referenced this issue Dec 4, 2024
#303 Fix punycode warning. Used fix recommended in mathiasbynens/punycode.js#137
@dacarson
Copy link
Collaborator

dacarson commented Dec 4, 2024

The instructions mathiasbynens/punycode.js#137 fix the puny code warning.

I am unable to reproduce this warning:
(node:1189266) [DEP0060] DeprecationWarning: The util._extend API is deprecated. Please use Object.assign() instead.
(Use node --trace-deprecation ... to show where the warning was created)

@dacarson
Copy link
Collaborator

dacarson commented Dec 5, 2024

I am still not able to reproduce the warning, however, I think I found where the issue is.
In utils/characteristics.js there is this pattern:

const underscore = require('underscore');
...

	let rainfallProps = (max) =>
	{
		var range = (units !== 'imperial') ? {unit: 'mm', maxValue: max, minValue: 0, minStep: 0.1}
			: {unit: 'in', maxValue: Math.round(max / 25.4), minValue: 0, minStep: 0.01};

		return underscore.extend(
			{
				format: Characteristic.Formats.FLOAT
				, perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
			}, range);
	};

I believe it is coming from return underscore.extend()

It is mentioned here Unitech/pm2#5238 :

Reference: https://nodejs.org/api/util.html#util_extendtarget-source
The util._extend() method was never intended to be used outside of internal Node.js modules. There are some modules in pm2 still using this method, and it is hereafter suggested to be replaced.

@dacarson dacarson reopened this Dec 5, 2024
@dacarson
Copy link
Collaborator

dacarson commented Dec 5, 2024

I see how this works. In the checkin comment if I put "Fix #xxx" issue number, it automatically closes the issue. As I have submitted a fix now, it should be closed.

@dacarson dacarson closed this as completed Dec 5, 2024
dacarson added a commit that referenced this issue Dec 6, 2024
#150  Migrate off the deprecated request package and moved all URL loads to using the supported axios package. Tried to make as smaller changes as possible.
Added a little more failure logging to enable better debugging.

Found that punycode was only being used by request so I could remove the work around for it (#303)
Found that debug package wasn't explicitly being listed as a dependency in package.json, though index.js requires it, so added that.

Tested with valid tokens - all worked (only tested openweathermap 2.5 API)
Tested with invalid tokens - got correct error messages, didn’t crash HomeBridge
Tested with bad URLs - got correct error messages, didn’t crash HomeBridge

Migrated weewx weather station, though I wasn’t able to test it.
Danimal4326 pushed a commit to Danimal4326/homebridge-weather-plus that referenced this issue Dec 20, 2024
naofireblade#303 Fix punycode warning. Used fix recommended in mathiasbynens/punycode.js#137
Danimal4326 pushed a commit to Danimal4326/homebridge-weather-plus that referenced this issue Dec 20, 2024
Fix naofireblade#303  Though I could not reproduce the warning, this should fix it.
Danimal4326 pushed a commit to Danimal4326/homebridge-weather-plus that referenced this issue Dec 20, 2024
naofireblade#150  Migrate off the deprecated request package and moved all URL loads to using the supported axios package. Tried to make as smaller changes as possible.
Added a little more failure logging to enable better debugging.

Found that punycode was only being used by request so I could remove the work around for it (naofireblade#303)
Found that debug package wasn't explicitly being listed as a dependency in package.json, though index.js requires it, so added that.

Tested with valid tokens - all worked (only tested openweathermap 2.5 API)
Tested with invalid tokens - got correct error messages, didn’t crash HomeBridge
Tested with bad URLs - got correct error messages, didn’t crash HomeBridge

Migrated weewx weather station, though I wasn’t able to test it.
Danimal4326 added a commit to Danimal4326/homebridge-weather-plus that referenced this issue Dec 20, 2024
* Fix threshold triggers

naofireblade#296  Fix issue with threshold triggers and WeatherUnderground. In 3.3.4, WeatherUnderground API call was modified and incorrectly return values in km, and km/h

* Fix punycode warning

naofireblade#303 Fix punycode warning. Used fix recommended in mathiasbynens/punycode.js#137

* Fix util._extend warning

Fix naofireblade#303  Though I could not reproduce the warning, this should fix it.

* Migrate off request package

naofireblade#150  Migrate off the deprecated request package and moved all URL loads to using the supported axios package. Tried to make as smaller changes as possible.
Added a little more failure logging to enable better debugging.

Found that punycode was only being used by request so I could remove the work around for it (naofireblade#303)
Found that debug package wasn't explicitly being listed as a dependency in package.json, though index.js requires it, so added that.

Tested with valid tokens - all worked (only tested openweathermap 2.5 API)
Tested with invalid tokens - got correct error messages, didn’t crash HomeBridge
Tested with bad URLs - got correct error messages, didn’t crash HomeBridge

Migrated weewx weather station, though I wasn’t able to test it.

* Update CHANGELOG.md

naofireblade#150 Update Changelog

* Changes for Homebridge 2.0

naofireblade#301 Initial fixes to make the plugin work with Homebridge 2.0
Two basic changes:
1. Use of enums off the Characteristic class is no longer supported:
Instead of const Units = Characteristic.Units; you will need to use const Units = api.hap.Units;
Instead of const Formats = Characteristic.Formats; you will need to use const Formats = api.hap.Formats;
Instead of const Perms = Characteristic.Perms; you will need to use const Perms = api.hap.Perms;

2. Change custom characteristics to be classes with constructors, rather than using the inherits() functionality.

* Change colons for Modifier Letter Triangular Colon

naofireblade#301 Homekit has special rules for naming items. They must start with an alpha or numeric value, then they can contain alphanumeric characters, space and apostrophe, and they must end with an alpha or numeric character. The created sensors are using colons for delimiters, which isn't allowed. However, according to Apple documentation alphanumeric characters consist of Unicode character sets L*, M* and N*. The Modifier Letter Triangular Colon falls into the L* set, so it should be legal to use.
See homebridge/HAP-NodeJS#1079 for more detail.

---------

Co-authored-by: dacarson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants