Last active
March 13, 2023 23:20
-
-
Save hiway/62a7c0f27a463657d04c5d6c4f791aca to your computer and use it in GitHub Desktop.
Example Python program to publish text messages received on a TP-Link MR200 4G modem to Home Assistant. Note: this example is incomplete as the modules "hasspy" and "tplink_mr200" have not been released yet.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hasspy import Device | |
from tplink_mr200 import TPLinkMR200 | |
device = Device( | |
name="TP Link MR 200", | |
component="binary_sensor", | |
initial_state="ON", | |
unique_id="tplink-mr200-002", | |
) | |
text_message = device.entity( | |
name="Text Message", component="text", unique_id="tplink-mr200-lm-002" | |
) | |
@device.on_interval(minutes=10) | |
async def poll_for_data(): | |
router = TPLinkMR200() | |
try: | |
for sms in router.unread_messages(): | |
await text_message.publish_state( | |
f"{sms.text} [{sms.sender} @{sms.timestamp}]" | |
) | |
except (KeyboardInterrupt, IndexError): | |
router.logout() | |
finally: | |
router.close_browser() | |
device.run("homeassistant.local", username="example", password="example") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment