Skip to content

Commit

Permalink
Added get_data method to return watt and state
Browse files Browse the repository at this point in the history
  • Loading branch information
Superkikim committed Aug 14, 2023
1 parent d24b1ed commit af3e146
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
11 changes: 11 additions & 0 deletions maxsmart/maxsmart.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ def turn_off(self, port):
else:
self._verify_port_state(port, 0)

def get_data(self):
response = self._send_command(511)
state = response.get('data', {}).get('switch', [])
wattage = response.get('data', {}).get('watt', [])

if state is None or wattage is None:
raise Exception(f"Error: 'switch' or 'watt' data not found in response from power strip")

return {"switch": state, "watt": wattage}


def check_state(self):
response = self._send_command(511)
state = response.get('data', {}).get('switch', [])
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='maxsmart',
version='0.1.9b',
version='0.2.0',
author='Akim Sissaoui',
author_email='superkikim@sissaoui.com',
description='A Python module for operating network connected power strips',
Expand Down
1 change: 1 addition & 0 deletions test_scripts/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
def discover_devices(ip=None):
print("Discovering MaxSmart devices...")
discovery = MaxSmartDiscovery() # Create an instance of MaxSmartDiscovery
ip = "255.255.255.255"
devices = discovery.discover_maxsmart(ip) # Call the instance method
return devices

Expand Down
2 changes: 1 addition & 1 deletion test_scripts/test_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def main():

# Retrieve the state of the strip
strip_state = cuisine_maxsmart.check_state()

print(strip_state)
# Display the results
print("Port states:")
for port, state in port_states:
Expand Down
4 changes: 4 additions & 0 deletions test_scripts/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
try:
data, addr = sock.recvfrom(1024)
raw_result = data.decode()

# Extract and print the source IP address
source_ip = addr[0]
print("Source IP:", source_ip)
print("Raw Result:", raw_result)
except socket.timeout:
print("Socket timeout occurred.")
Expand Down

0 comments on commit af3e146

Please sign in to comment.