Skip to content

Instantly share code, notes, and snippets.

@cbpowell
Last active March 18, 2022 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbpowell/cb9cf9c34f68530374eb2cfa777b597f to your computer and use it in GitHub Desktop.
Save cbpowell/cb9cf9c34f68530374eb2cfa777b597f to your computer and use it in GitHub Desktop.
sources:
- mutable:
plugs:
- TesSense:
alias: "Tesla Charger"
mac: 50:c7:bf:f6:4f:39 # matches value in TesSenseLink.py line 245
power: 0 # will be updated with live values
@cbpowell
Copy link
Author

Good stuff!

Yeah I can see how the broad config option is less useful in your case. While I might eventually change this up to make it a little more streamlined, you can replace the config file by doing something the following - using my module_usage_exampe.py code as an example below, but it's highly similar to your latest TesSense code:

Original:

# pip install
from senselink import SenseLink
...
async def main():
    # Get config
    config = open('config.yml', 'r')
    # Create controller, with config
    controller = SenseLink(config)
    # Create instances
    controller.create_instances()

    # Get Mutable controller object, and create task to update it
    mutable_plug = controller.plug_for_mac("50:c7:bf:f6:4f:39")

Change to:

from senselink import SenseLink
from senselink.plug_instance import PlugInstance
from senselink.data_source import MutableSource
...
async def main():
    # Create controller, with NO config
    controller =  SenseLink(None)
    
    # Create a PlugInstance, setting at least the identifier and MAC
    mutable_plug = PlugInstance("mutable",mac="50:c7:bf:f6:4f:39")
    # Create and assign a Mutable Data Source to that plug
    mutable_data_source = MutableSource("mutable", None)
    mutable_plug.data_source = mutable_data_source
    
    # Add that plug to the controller
    controller.add_instances({mutable_plug.identifier: mutable_plug})

    # Note: you can then use the mutable_plug variable directly instead of needing a controller.plug_for_mac() call.
    # They are the same object.

Just a heads up though, I see some areas for improvement around this, so it could change in future releases of SenseLink!

@israndy
Copy link

israndy commented Mar 17, 2022 via email

@cbpowell
Copy link
Author

Yeah sure thing! It's definitely helped me make some improvements to SenseLink.

As for it waking up the car, there is a way to query the Tesla API in such a way that it doesn't wake up the car, but I think it might have to be via the streaming API. Unfortunately it seems like the Teslapy docs on streaming are a little light/nonexistent. I gather that if you use the streaming API it doesn't wake the car up, but you can tell if it is awake you can then query it like normal. I have telsamate set up for myself, which I can verify doesn't wake the car up.

@israndy
Copy link

israndy commented Mar 18, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment