Skip to content

Commit

Permalink
Added comments explaining what the test and mock scripts do, moved to…
Browse files Browse the repository at this point in the history
… subfolder to make it clear they're separate from the actual hass component, tweaked gitignore
  • Loading branch information
beveradb committed Jan 23, 2019
1 parent 4a52f4d commit 04bf20c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,10 @@ venv.bak/

# mypy
.mypy_cache/

# Log files generated by running the test scripts in the source directory
*.log

# JetBrains IDE settings
.idea
.idea/
5 changes: 5 additions & 0 deletions mock_sonoff.py → non-hass-scripts/mock_sonoff.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# This script can be used to simulate a real Sonoff device in LAN mode, to test 2-way communication with other code.
# When executed (e.g. from a terminal with `python mock_sonoff.py`), it will open a WebSocket server on port 8081,
# allowing you to connect to this mock Sonoff device with other code designed to simulate the eWeLink mobile app.
# Any messages sent or received are logged to the log file 'mock_sonoff.log' for further research.

import json
import logging
import logging.config
Expand Down
2 changes: 2 additions & 0 deletions non-hass-scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
six==1.12.0
websocket-client==0.54.0
11 changes: 9 additions & 2 deletions test_sonoff.py → non-hass-scripts/test_sonoff.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# This script can be used to test 2-way communication with a Sonoff device in LAN mode.
# When executed (e.g. from a terminal with `python test_sonoff.py`), it will open a WebSocket connection on port 8081
# to the device on the IP address you specify below, simulating the eWeLink mobile app.
# Any messages sent to or received by the device are logged to the log file 'test_sonoff.log' for further research.

SONOFF_LAN_IP = "192.168.0.XXX" # Replace with the IP address of the Sonoff you want to test, e.g. "192.168.0.112"

import json
import random
import threading
import time
import websocket
import logging
import logging.config
import websocket


class Sonoff:
Expand All @@ -13,7 +20,7 @@ def __init__(self):

self.logger.debug('Sonoff class initialising')

self._wshost = "localhost" # Replace with local LAN IP, e.g. 192.168.0.112
self._wshost = SONOFF_LAN_IP
self._wsport = "8081"
self._wsendpoint = "/"

Expand Down

0 comments on commit 04bf20c

Please sign in to comment.