Skip to content

Commit

Permalink
fix log output
Browse files Browse the repository at this point in the history
  • Loading branch information
rgwch committed Jun 8, 2020
2 parents d06f992 + d812689 commit 8ff88ab
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/node_modules
/nbproject
.DS_Store
*.tgz
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ node_modules
test
.travis.yml
appveyor.yml
src
tsconfig.json
tsconfig.build.json
.afphoto
12 changes: 0 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ os:
language: node_js
node_js:
- lts/*
before_script:
- export NPMVERSION=$(echo "$($(which npm) -v)"|cut -c1)
- "if [[ $NPMVERSION == 5 ]]; then npm install -g npm@5; fi"
- npm -v
env:
- CXX=g++-6
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
script:
- "npm run test:package"
- "npm run test:unit"
Expand Down
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
![Logo](admin/mystrom-wifi-switch.jpg)
![Logo](admin/mystrom-wifi-switch.png)
[![NPM version](http://img.shields.io/npm/v/iobroker.mystrom-wifi-switch.svg)](https://www.npmjs.com/package/iobroker.mystrom-wifi-switch)
[![Build Status](https://travis-ci.com/rgwch/ioBroker.mystrom-wifi-switch.svg?branch=master)](https://travis-ci.com/rgwch/ioBroker.mystrom-wifi-switch)

![Number of Installations](http://iobroker.live/badges/mystrom-wifi-switch-installed.svg)

# ioBroker.mystrom-wifi-switch
![Number of Installations](http://iobroker.live/badges/mystrom-wifi-switch-installed.svg) ![Number of Installations](http://iobroker.live/badges/mystrom-wifi-switch-stable.svg)


Note: This is a complete rewrite of the original adapter v1.x, now based on the great [@iobroker/create-adapter](https://github.com/ioBroker/create-adapter) tool.
Expand All @@ -13,15 +16,17 @@ This adapter connects [myStrom WiFi Switches](https://mystrom.ch/wifi-switch) to

## Install

This adapter is not part of the official ioBroker distribution. So it will not show up in ioBroker admin's adapter list,
Install it from a shell. CD into /opt/iobroker and then
This adapter is not part of the official ioBroker distribution. So it will not show up in ioBroker admin's adapter list. You can install it either directly from NPM:

[![NPM](https://nodei.co/npm/iobroker.mystrom-wifi-switch.png)](https://nodei.co/npm/iobroker.mystrom-wifi-switch/)

npm install https://github.com/rgwch/ioBroker.mystrom-wifi-switch/tarball/master
or as a custom adapter from the admin-ui. Make sure to select "Beliebig" even though it's located at Github:

or, install it as a custom adapter from the admin-ui:
![custom adapter](install_1.jpg)

![custom adapter](install_mystrom.jpg)
Find out the release you're interessed in: <https://github.com/rgwch/ioBroker.mystrom-wifi-switch/releases> and copy/paste the address of the .tar.gz link.

Read the warning and click "install" if you agree.

The adapter should then be in the admin pages's list.

Expand All @@ -30,7 +35,7 @@ That's all. If you have several switches, just create several instances.

## Use

Each instance will create a switchState and a switchPower object. SwitchState is true or false, switchPower is in Watts (and will always be 0 if switchState is false, of course)
Each instance will create a switchState and a switchPower object. SwitchState is true or false, switchPower is in Watts (and will always be 0 if switchState is false, of course). Newer models of the switch feature an additional temperature indicator. With older switches, this will always be 0.

SwitchState is writeable.

Expand Down Expand Up @@ -100,3 +105,9 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

## More like this

* ['MyStrom Dingz' Adapter](http://github.com/rgwch/ioBroker.dingz)
* ['MyStrom WiFi Button' Adapter](http://github.com/rgwch/ioBroker.mystrom-wifi-button)
* ['MyStrom WiFi Bulb' Adapter](http://github.com/rgwch/ioBroker.mystrom-wifi-bulb)
2 changes: 1 addition & 1 deletion admin/index_m.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<div class="row">
<div class="col s12 m4 l2">
<img src="mystrom-wifi-switch.jpg" class="logo">
<img src="mystrom-wifi-switch.png" class="logo">
</div>
</div>

Expand Down
Binary file removed admin/mystrom-wifi-switch.jpg
Binary file not shown.
Binary file added admin/mystrom-wifi-switch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bild.afphoto
Binary file not shown.
14 changes: 10 additions & 4 deletions build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,20 @@ class MystromSwitch extends utils.Adapter {
}
doFetch(addr) {
return __awaiter(this, void 0, void 0, function* () {
const url = this.config.url;
let url = this.config.url;
if (url.indexOf("://") == -1) {
url = "http://" + url;
}
this.log.info("Fetching " + url + addr);
try {
const response = yield node_fetch_1.default(url + addr, { method: "get" });
if (response.status == 200) {
const result = yield response.json();
this.log.debug("got " + JSON.stringify(result));
return result;
const text = yield response.text();
this.log.debug("got: " + text);
if (text.length) {
return JSON.parse(text);
}
return text;
}
else {
this.log.error("Error while fetching " + addr + ": " + response.status);
Expand Down
Binary file added install_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 16 additions & 4 deletions io-package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"common": {
"name": "mystrom-wifi-switch",
"version": "2.0.1",
"version": "2.0.3",
"news": {
"2.0.1": {
"2.0.3": {
"en": "fix empty response error",
"de": "Behebung eines leeren Antwortfehlers",
"ru": "исправить пустую ошибку ответа",
Expand All @@ -15,6 +15,18 @@
"pl": "naprawić błąd pustej odpowiedzi",
"zh-cn": "修复空响应错误"
},
"2.0.2": {
"en": "better upgrade of url config from earlier versions",
"de": "Besseres Upgrade der URL-Konfiguration von früheren Versionen",
"ru": "лучшее обновление конфига url с более ранних версий",
"pt": "melhor atualização da configuração de URL de versões anteriores",
"nl": "betere upgrade van url-configuratie van eerdere versies",
"fr": "meilleure mise à niveau de la configuration d'URL des versions antérieures",
"it": "migliore aggiornamento di url config dalle versioni precedenti",
"es": "Mejor actualización de la configuración de URL desde versiones anteriores",
"pl": "lepsza aktualizacja konfiguracji adresu URL z wcześniejszych wersji",
"zh-cn": "从早期版本更好地升级url配置"
},
"2.0.0": {
"en": "complete redesign",
"de": "komplette Neugestaltung",
Expand Down Expand Up @@ -108,9 +120,9 @@
"license": "MIT",
"platform": "Javascript/Node.js",
"main": "build/main.js",
"icon": "mystrom-wifi-switch.jpg",
"icon": "mystrom-wifi-switch.png",
"enabled": true,
"extIcon": "https://raw.githubusercontent.com/rgwch/ioBroker.mystrom-wifi-switch/master/admin/mystrom-wifi-switch.jpg",
"extIcon": "https://raw.githubusercontent.com/rgwch/ioBroker.mystrom-wifi-switch/master/admin/mystrom-wifi-switch.png",
"readme": "https://github.com/rgwch/ioBroker.mystrom-wifi-switch/blob/master/README.md",
"loglevel": "info",
"mode": "daemon",
Expand Down
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
{
"name": "iobroker.mystrom-wifi-switch",
"version": "2.0.1",
"version": "2.0.3",
"description": "control mystrom switches",
"author": {
"name": "rgwch",
Expand Down
15 changes: 10 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,20 @@ class MystromSwitch extends utils.Adapter {


private async doFetch(addr: string): Promise<any> {
const url = this.config.url

let url = this.config.url
if (url.indexOf("://") == -1) {
url = "http://" + url
}
this.log.info("Fetching " + url + addr)
try {
const response = await fetch(url + addr, { method: "get" })
if (response.status == 200) {
const result = await response.json()
this.log.debug("got " + JSON.stringify(result))
return result
const text=await response.text()
this.log.debug("got: "+text)
if(text.length){
return JSON.parse(text)
}
return text
} else {
this.log.error("Error while fetching " + addr + ": " + response.status)
this.setState("info.connection", false, true);
Expand Down

0 comments on commit 8ff88ab

Please sign in to comment.