calvinmclean / homebridge-kettle

Homebridge plugin for Fellow Stagg EKG+ electric kettle
MIT License
7 stars 1 forks source link

errors when sending commands to the API #3

Open nickpdawson opened 3 years ago

nickpdawson commented 3 years ago

I'm getting errors in home bridge when I try and issue a command. Also worth noting, the plug-in defaults to using port 8080 but the apy.py script defaults to 8000. I use 8000 in my HB setup.

here's my config:

{
    "bridge": {
        "name": "Homebridge 713B",
        "username": "0E:5A:F2:28:71:3B",
        "port": 51148,
        "pin": "<redacted>"
    },
    "accessories": [],
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "platform": "config"
        },
        {
            "name": "Stagg EKG+",
            "host": "127.0.0.1",
            "port": 8000,
            "tempUnits": "f",
            "serialNumber": "<my serial>",
            "platform": "Stagg EKG+"
        }
    ]
}

here's the errors:

[22/08/2021, 16:40:09] [Stagg EKG+] Error: socket hang up at connResetException (internal/errors.js:628:14) at Socket.socketOnEnd (_http_client.js:499:23) at Socket.emit (events.js:412:35) at endReadableNT (internal/streams/readable.js:1317:12) at processTicksAndRejections (internal/process/task_queues.js:82:21) { code: 'ECONNRESET', config: { url: 'http://127.0.0.1:8000/api/power', method: 'post', data: '{"targetState":1}', headers: { Accept: 'application/json, text/plain, /', 'Content-Type': 'application/json;charset=utf-8', 'User-Agent': 'axios/0.19.2', 'Content-Length': 17 }, transformRequest: [ [Function: transformRequest] ], transformResponse: [ [Function: transformResponse] ], timeout: 0, adapter: [Function: httpAdapter], xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, validateStatus: [Function: validateStatus] }, request: <ref 1> Writable { _writableState: WritableState { objectMode: false, highWaterMark: 16384, finalCalled: false, needDrain: false, ending: false, ended: false, finished: false, destroyed: false, decodeStrings: true, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: true, bufferProcessing: false, onwrite: [Function: bound onwrite], writecb: null, writelen: 0, afterWriteTickInfo: null, buffered: [], bufferedIndex: 0, allBuffers: true, allNoop: true, pendingcb: 0, prefinished: false, errorEmitted: false, emitClose: true, autoDestroy: true, errored: null, closed: false }, _events: [Object: null prototype] { response: [Function: handleResponse], error: [Function: handleRequestError] }, _eventsCount: 2, _maxListeners: undefined, _options: { protocol: 'http:', maxRedirects: 21, maxBodyLength: 10485760, path: '/api/power', method: 'POST', headers: [Object], agent: undefined, agents: [Object], auth: undefined, hostname: '127.0.0.1', port: '8000', nativeProtocols: [Object], pathname: '/api/power' }, _redirectCount: 0, _redirects: [], _requestBodyLength: 17, _requestBodyBuffers: [ [Object] ], _onNativeResponse: [Function (anonymous)], _currentRequest: ClientRequest { _events: [Object: null prototype], _eventsCount: 6, _maxListeners: undefined, outputData: [], outputSize: 0, writable: true, destroyed: false, _last: true, chunkedEncoding: false, shouldKeepAlive: false, _defaultKeepAlive: true, useChunkedEncodingByDefault: true, sendDate: false, _removedConnection: false, _removedContLen: false, _removedTE: false, _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: [Socket], _header: 'POST /api/power HTTP/1.1\r\n' + 'Accept: application/json, text/plain, /\r\n' + 'Content-Type: application/json;charset=utf-8\r\n' + 'User-Agent: axios/0.19.2\r\n' + 'Content-Length: 17\r\n' + 'Host: 127.0.0.1:8000\r\n' + 'Connection: close\r\n' + '\r\n', _keepAliveTimeout: 0, _onPendingData: [Function: noopPendingOutput], agent: [Agent], socketPath: undefined, method: 'POST', maxHeaderSize: undefined, insecureHTTPParser: undefined, path: '/api/power', _ended: false, res: null, aborted: false, timeoutCb: null, upgradeOrConnect: false, parser: null, maxHeadersCount: null, reusedSocket: false, host: '127.0.0.1', protocol: 'http:', _redirectable: [Circular 1],

  [Symbol(kNeedDrain)]: false,
  [Symbol(corked)]: 0,
  [Symbol(kOutHeaders)]: [Object: null prototype]
},
_currentUrl: 'http://127.0.0.1:8000/api/power',
[Symbol(kCapture)]: false

}, response: undefined, isAxiosError: true, toJSON: [Function (anonymous)] } [22/08/2021, 16:40:21] [Stagg EKG+] Current State: undefined [22/08/2021, 16:40:21] [homebridge-stagg-ekg-plus] This plugin generated a warning from the characteristic 'Target Heating Cooling State': characteristic value expected valid finite number and received "undefined" (undefined). See https://git.io/JtMGR for more info. [22/08/2021, 16:40:21] [Stagg EKG+] Current Temp: undefined

calvinmclean commented 3 years ago

I'll take a look tomorrow and see if I can reproduce this.

I just merged a PR to the python application from another contributor, so maybe that fix is related to this. Sorry for not seeing this sooner! Need to fix my email notifications or something since I missed a few issues and PRs.

calvinmclean commented 3 years ago

@nickpdawson I haven't been able to reproduce this yet, but noticed a few things. First, I am using a pretty old version of Homebridge since I only use it for this one accessory: 0.4.50. Also, my configuration looks pretty different from yours. I'm not super familiar with Homebridge configuration so it's possible that these end up meaning the same thing, or it's a difference in Homebridge versions. Here's my config:

{
  "bridge": {
    "name": "Homebridge",
    "username": "CC:22:3D:E3:CE:41",
    "port": 51826,
    "pin": "031-45-154",
    "room": "Kitchen"
  },

  "description": "This is an example configuration file with one fake accessory and one fake platform. You can use this as a template for creating your own configuration file containing devices you actually own.",
  "ports": {
    "start": 52100,
    "end": 52150,
    "comment": "This section is used to control the range of ports that separate accessory (like camera or television) should be bind to."
  },
  "accessories": [
    {
      "accessory": "MyKettle",
      "room": "Kitchen",
      "name": "Kettle"
    }
  ]
}

The biggest difference is that my kettle is in accessories instead of platforms.

Additionally, I don't think it is correct that the plugin defaults to 8080. In the code, until a recent PR updating the configuration, all calls to the api.py Python service use http://localhost:8000 and the Python api.py runs on port 8000. Maybe there is an issue from changing ports?

calvinmclean commented 3 years ago

Actually, what operating system are you running on? AFAIK, it only works on Linux due to the bluepy dependency in the Python program.

If you could share the logs from api.py that could be useful.