jeffreydwalter / arlo

Python module for interacting with Netgear's Arlo camera system.
Apache License 2.0
520 stars 123 forks source link

CustomMode() Not changing mode. #108

Closed zemerick1 closed 5 years ago

zemerick1 commented 5 years ago

Please answer these questions before submitting your issue. Thanks!

What version of Python are you using (python -V)?

3.7.1

What operating system and processor architecture are you using (python -c 'import platform; print(platform.uname());')?

Windows 10 x64

Which Python packages do you have installed (run the pip freeze or pip3 freeze command and paste output)?

arlo==1.2.9 beautifulsoup4==4.6.3 certifi==2018.10.15 chardet==3.0.4 idna==2.7 monotonic==1.5 Pillow==5.3.0 pyarlo==0.2.3 PySocks==1.6.8 requests==2.20.1 simplejson==3.16.0 six==1.11.0 sseclient==0.0.22 urllib3==1.24.1

Which Arlo hardware do you have (camera types - [Arlo, Pro, Q, etc.], basestation model, etc.)?

Arlo Wire-Free 1st gen

What did you do?

arlo = Arlo(USERNAME, PASSWORD)
basestations = arlo.GetDevices('basestation')
#print(basestations)
print(arlo.GetModes(basestations[0]))
arlo.CustomMode(basestations[0], 'mode2')
arlo.CustomMode(basestations[0], 'SmartThings')
# {'name': 'SmartThings', 'rules': ['rule0', 'rule1', 'rule2'], 'id': 'mode2'}

If possible, provide the steps you took to reproduce the issue. A complete runnable program is good. (don't include your user/password or any sensitive info)

What did you expect to see?

Basestation output [Set mode] [Set mode, different input]

What did you see instead?

Script exited with code 0. However, my app doesn't reflect the change. Is there a GetCurrentMode() I'm not seeing in API?

Does this issue reproduce with the latest release?

Yes.

jeffreydwalter commented 5 years ago

When changing the mode, you should use the id, like you did in arlo.CustomMode(basestations[0], 'mode2').

zemerick1 commented 5 years ago

Right. Neither change it. I was running both to see if it made a difference. I have the VMB3500R4 basestation. . Not sure if that matters or not.

jeffreydwalter commented 5 years ago

@zemerick1 install the latest build and try setting the mode now. Looks like they finally deprecated the old API for setting the mode, so I updated the library to always use that API.

zemerick1 commented 5 years ago

Gotcha. Just upgraded to .10 Now getting an error.

    arlo = Arlo(USERNAME, PASSWORD)
    basestations = arlo.GetDevices('basestation')
    #print(basestations)
    print(arlo.GetModes(basestations[0]))
    arlo.CustomMode(basestations[0], 'mode2')
    #arlo.CustomMode(basestations[0], 'SmartThings')
    # {'name': 'SmartThings', 'rules': ['rule0', 'rule1', 'rule2'], 'id': 'mode2'}

Invalid format string

NOTE: It still exits code 0

jeffreydwalter commented 5 years ago

@zemerick1, I don't get that error, even running the code you paste. (Please use a code block for your code examples, thanks).

I assume it's got to be something in your code. Please try cleaning up your example code, reducing it down to exactly what you need.

zemerick1 commented 5 years ago
from Arlo import Arlo

from datetime import timedelta, date
import datetime
import sys
import glob
import shutil
import os

USERNAME = 'REDACTED'
PASSWORD = 'REDACTED'

try:
    # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached.
    # Subsequent successful calls to login will update the oAuth token.
    arlo = Arlo(USERNAME, PASSWORD)
    basestations = arlo.GetDevices('basestation')
    #print(basestations)
    print(arlo.GetModes(basestations[0]))
    arlo.CustomMode(basestations[0], 'mode2')
    #arlo.CustomMode(basestations[0], 'SmartThings')
    # {'name': 'SmartThings', 'rules': ['rule0', 'rule1', 'rule2'], 'id': 'mode2'}

except Exception as e:
    print(e)

#CustomMode(basestation, mode)

This is my code verbatim. Outside of creds of course. EDIT I removed all the imports outside of Arlo. Same results.

zemerick1 commented 5 years ago

Progress perhaps: Code:

from Arlo import Arlo

USERNAME = 'REDACTED'
PASSWORD = 'REDACTED'

    # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached.
    # Subsequent successful calls to login will update the oAuth token.
arlo = Arlo(USERNAME, PASSWORD)
basestations = arlo.GetDevices('basestation')
    #print(basestations)
print(arlo.GetModes(basestations[0]))
arlo.CustomMode(basestations[0], 'mode2')
    #arlo.CustomMode(basestations[0], 'SmartThings')
    # {'name': 'SmartThings', 'rules': ['rule0', 'rule1', 'rule2'], 'id': 'mode2'}

#CustomMode(basestation, mode)

ERROR:

C:\Users\888\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/888/PycharmProjects/untitled/venv/Change_mode.py
{'resource': 'modes', 'properties': {'active': 'mode3', 'modes': [{'name': '', 'type': 'disarmed', 'rules': [], 'id': 'mode0'}, {'name': '', 'type': 'armed', 'rules': ['r_mode1_5EX184SM58F82', 'r_mode1_5EX184SM573C2', 'r_mode1_5EX184SL58C98', 'rule4'], 'id': 'mode1'}, {'name': 'SmartThings', 'rules': ['rule0', 'rule1', 'rule2'], 'id': 'mode2'}, {'name': 'front and garage', 'rules': ['r_mode3_5EX184SM58F82', 'r_mode3_5EX184SM573C2'], 'id': 'mode3'}]}, 'action': 'is', 'transId': 'web!b68a752d.a41a3!1548484676151', 'to': 'ACATJ3KN-100-40905896_web', 'from': '5BF3887NA20A0'}
Traceback (most recent call last):
  File "C:/Users/888/PycharmProjects/untitled/venv/Change_mode.py", line 12, in <module>
    arlo.CustomMode(basestations[0], 'mode2')
  File "C:\Users\888\PycharmProjects\untitled\venv\lib\site-packages\Arlo.py", line 516, in CustomMode
    return self.request.post('https://arlo.netgear.com/hmsweb/users/devices/automation/active', {'activeAutomations':[{'deviceId':device.get('deviceId'),'timestamp':self.to_timestamp(datetime.datetime.now()),'activeModes':[mode],'activeSchedules':schedules}]})
  File "C:\Users\888\PycharmProjects\untitled\venv\lib\site-packages\Arlo.py", line 182, in to_timestamp
    return int(dt.strftime("%s")) * 1000
ValueError: Invalid format string
jeffreydwalter commented 5 years ago

Interesting... I wonder if this is a Windows specific bug. Will look into it. Thanks.

zemerick1 commented 5 years ago

If you run it on a nix box, do you see the error? Oddly my dev box is a Windows machine, then I copy over and test on nix. Raspberry PI, specifically. Before you dump man hours into this, let me test the code on my PI and I'll report back.

jeffreydwalter commented 5 years ago

Nope, confirmed that it was a Windows related issue. Apparently, strftime doesn't support all of the format options. In this case %s.

Just pushed a fix. Let me know how it goes!

zemerick1 commented 5 years ago

Thanks. It looks like something else broke. .

C:\Users\888\PycharmProjects\Arlo_Stuff\venv\Scripts\python.exe C:/Users/888/PycharmProjects/Arlo_Stuff/venv/Change_Mode.py
Traceback (most recent call last):
  File "C:/Users/888/PycharmProjects/Arlo_Stuff/venv/Change_Mode.py", line 1, in <module>
    from arlo import Arlo
  File "C:\Users\888\PycharmProjects\Arlo_Stuff\venv\lib\site-packages\arlo.py", line 21, in <module>
    from request import Request
ModuleNotFoundError: No module named 'request'

Process finished with exit code 1

Also, for some reason after the package upgrade I had to change the letter case of the module from: from Arlo import Arlo to from arlo import Arlo

or I would receive a "No module naned 'Arlo' found"

jeffreydwalter commented 5 years ago

I reogranized the code last night and moved some of the classes out into their own files. I'm not super familiar with the python packaging tools, and so didn't realize I had neglected to update setup.py to include the new files.

Just made a new release, it should have everything.

zemerick1 commented 5 years ago

I figured it was just missing a module, but I didn't want to break anything further. This worked like a charm. Mode changed!

Thanks for the prompt help!

jeffreydwalter commented 5 years ago

Awesome! Thanks for all of your help.