Skip to content

Commit

Permalink
solve #400 Cannot read property 'initialized' of undefined handleStates
Browse files Browse the repository at this point in the history
  • Loading branch information
DutchmanNL committed Jun 8, 2022
1 parent 1b1ae30 commit 3ad11a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ When the adapter crashes or another Code error happens, this error message that
Placeholder for the next version (at the beginning of the line):
### __WORK IN PROGRESS__
-->
### __WORK IN PROGRESS__ - Bugfix [#400](https://github.com/DrozmotiX/ioBroker.wled/issues/400)
* (DutchmanNL) Cannot read property 'initialized' of undefined handleStates solve [#400](https://github.com/DrozmotiX/ioBroker.wled/issues/400)

### 0.6.6 (2022-06-08) - Log messages and error reporting improved
* (DutchmanNL) Log messages and error reporting improved
* (DutchmanNL) Don't send missing attribute definitions to Sentry
Expand Down
22 changes: 11 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ class Wled extends utils.Adapter {
const deviceStates = deviceData.state;
infoStates.ip = infoStates.ip !== undefined ? infoStates.ip : ipAddress;

if (!this.devices[infoStates.ip].initialized) {
if (!this.devices[ipAddress].initialized) {
await this.setObjectNotExistsAsync(infoStates.mac + '._info', {
type: 'channel',
common: {
Expand All @@ -534,7 +534,7 @@ class Wled extends utils.Adapter {
for (const i in infoStates) {

// Create Info channels
if (!this.devices[infoStates.ip].initialized) {
if (!this.devices[ipAddress].initialized) {

// Create Channels for led and wifi configuration
switch (i) {
Expand Down Expand Up @@ -591,7 +591,7 @@ class Wled extends utils.Adapter {
// Create Channels for nested states
switch (i) {
case ('ccnf'):
if (!this.devices[infoStates.ip].initialized) await this.setObjectNotExistsAsync(infoStates.mac + '.ccnf', {
if (!this.devices[ipAddress].initialized) await this.setObjectNotExistsAsync(infoStates.mac + '.ccnf', {
type: 'channel',
common: {
name: 'ccnf',
Expand All @@ -601,7 +601,7 @@ class Wled extends utils.Adapter {
break;

case ('nl'):
if (!this.devices[infoStates.ip].initialized) await this.setObjectNotExistsAsync(infoStates.mac + '.nl', {
if (!this.devices[ipAddress].initialized) await this.setObjectNotExistsAsync(infoStates.mac + '.nl', {
type: 'channel',
common: {
name: 'Nightlight',
Expand All @@ -611,7 +611,7 @@ class Wled extends utils.Adapter {
break;

case ('udpn'):
if (!this.devices[infoStates.ip].initialized) await this.setObjectNotExistsAsync(infoStates.mac + '.udpn', {
if (!this.devices[ipAddress].initialized) await this.setObjectNotExistsAsync(infoStates.mac + '.udpn', {
type: 'channel',
common: {
name: 'Broadcast (UDP sync)',
Expand All @@ -624,7 +624,7 @@ class Wled extends utils.Adapter {

this.log.debug('Segment Array : ' + JSON.stringify(deviceStates[i]));

if (!this.devices[infoStates.ip].initialized) await this.setObjectNotExistsAsync(infoStates.mac + '.seg', {
if (!this.devices[ipAddress].initialized) await this.setObjectNotExistsAsync(infoStates.mac + '.seg', {
type: 'channel',
common: {
name: 'Segmentation',
Expand All @@ -634,7 +634,7 @@ class Wled extends utils.Adapter {

for (const y in deviceStates[i]) {

if (!this.devices[infoStates.ip].initialized) await this.setObjectNotExistsAsync(infoStates.mac + '.seg.' + y, {
if (!this.devices[ipAddress].initialized) await this.setObjectNotExistsAsync(infoStates.mac + '.seg.' + y, {
type: 'channel',
common: {
name: 'Segment ' + y,
Expand Down Expand Up @@ -699,14 +699,14 @@ class Wled extends utils.Adapter {
}
}

if (!this.devices[infoStates.ip].initialized) {
this.devices[infoStates.ip].initialized = true;
if (!this.devices[ipAddress].initialized) {
this.devices[ipAddress].initialized = true;
// Start websocket connection and and listen to state changes
await this.handleWebSocket(infoStates.ip);
await this.handleWebSocket(ipAddress);
}

// Update device working state
if (!this.devices[infoStates.ip].connected) this.devices[infoStates.ip].connected = true;
if (!this.devices[ipAddress].connected) this.devices[ipAddress].connected = true;
this.create_state(infoStates.mac + '._info' + '._online', `Online status`, true);

} catch (error) {
Expand Down

0 comments on commit 3ad11a8

Please sign in to comment.