Skip to content

Commit

Permalink
Added pytz, updated Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingDiver committed Apr 16, 2022
1 parent af54bfa commit 1dc6083
Show file tree
Hide file tree
Showing 608 changed files with 8,272 additions and 10 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@

This [Indigo](http://www.indigodomo.com/) plugin integrates [Twilio](http://www.twilio.com) as an [Indigo](http://www.indigodomo.com/docs/overview) custom device . This enables sending and receiving SMS and MMS messages from Indigo. In addition, this plugin enables outbound voice calls with recorded messages.

| Requirement | | |
|------------------------|---------------------|---|
| Minimum Indigo Version | 2022.1 | |
| Python Library (API) | Official | |
| Requires Local Network | No | |
| Requires Internet | Yes | |
| Hardware Interface | None | |

Check out the [full documentation](https://github.com/FlyingDiver/Indigo-Twilio/wiki) for a complete description of how to use the plugin. You can always get the latest release directly from the [GitHub repo](https://github.com/IndigoDomotics/Indigo-Twilio/releases) or from the [Indigo Plugin Store](http://www.indigodomo.com/pluginstore/).
17 changes: 7 additions & 10 deletions Twilio.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import sys
import time
from datetime import datetime
import pytz
import urllib
import logging
import random
import string
import json
import threading

import pytz
from twilio.rest import Client
from twilio.base.exceptions import TwilioException

Expand Down Expand Up @@ -375,16 +375,13 @@ def checkMessagesAction(self, pluginAction, twilioDevice):
def checkMessages(self, twilioDevice):

deleteMsgs = twilioDevice.pluginProps.get('delete', False)
lastMessageStamp = datetime.strptime(self.pluginPrefs.get(u"lastMessageStamp", "2000-01-01 00:00:00"),
'%Y-%m-%d %H:%M:%S')
self.logger.debug(
u"checkMessages: checking {}, lastMessageStamp {}".format(twilioDevice.name, lastMessageStamp))
lastMessageStamp = datetime.strptime(self.pluginPrefs.get(u"lastMessageStamp", "2000-01-01 00:00:00"),'%Y-%m-%d %H:%M:%S')
self.logger.debug(f"checkMessages: checking {twilioDevice.name}, lastMessageStamp {lastMessageStamp}")
messageStamp = lastMessageStamp

try:
for message in self.twilioClient.messages.list(to=twilioDevice.address):
self.logger.debug(u"checkMessages: Message from %s, to: %s, direction: %s, date_sent: '%s'" % (
message.from_, message.to, message.direction, message.date_sent))
self.logger.debug(f"checkMessages: Message from {message.from_}, to: {message.to}, direction: {message.direction}, date_sent: '{message.date_sent}'")
if message.date_sent and (
message.date_sent.replace(tzinfo=pytz.UTC) > lastMessageStamp.replace(tzinfo=pytz.UTC)):
messageStamp = message.date_sent
Expand All @@ -403,12 +400,12 @@ def checkMessages(self, twilioDevice):
self.twilioClient.messages(message.sid).delete()
except TwilioException as e:
if e[0:6] == "HTTP 4":
self.logger.warning(u"checkMessages: twilioClient.messages.delete() error: %s" % e)
self.logger.warning(f"checkMessages: twilioClient.messages.delete() error: {e}")
else:
self.logger.exception(u"checkMessages: twilioClient.messages.delete() error: %s" % e)
self.logger.exception(f"checkMessages: twilioClient.messages.delete() error: {e}")

except Exception as e:
self.logger.exception(u"checkMessages: twilioClient.messages.list error: %s" % e)
self.logger.exception(f"checkMessages: twilioClient.messages.list error: {e}")
twilioDevice.updateStateOnServer(key="numberStatus", value="Error")
twilioDevice.updateStateImageOnServer(indigo.kStateImageSel.SensorOff)

Expand Down

0 comments on commit 1dc6083

Please sign in to comment.