Пример #1
0
    def send(self, msg):
        params = {
            'user': self.params['api_id'],
            'passwd': self.params['api_key']
        }
        f = FreeClient(**params)
        res = f.send_sms(msg)

        if res.status_code == 200:
            return True
        if res.status_code == 400:
            raise MissingConfigParameter()
        if res.status_code == 500:
            raise ServerError()
        return False
Пример #2
0
class TestSMS(unittest.TestCase):

    def setUp(self):
        self.client = FreeClient(user="******", passwd="secret")

    def test_500(self):
        with HTTMock(smsapi_mock):
            resp = self.client.send_sms("oops code500 error")

        self.assertFalse(bool(resp))
        self.assertEquals(resp.status_code, 500)
        self.assertFalse(resp.success())
        self.assertTrue(resp.error())

    def test_400(self):
        with HTTMock(smsapi_mock):
            resp = self.client.send_sms("oops code400 error")

        self.assertFalse(bool(resp))
        self.assertEquals(resp.status_code, 400)

    def test_200(self):
        with HTTMock(smsapi_mock):
            resp = self.client.send_sms("oops code200 error")

        self.assertTrue(bool(resp))
        self.assertEquals(resp.status_code, 200)
        self.assertTrue(resp.success())
        self.assertFalse(resp.error())

    def test_py2_bool_resp(self):
        ok = FreeResponse(200)
        ko = FreeResponse(400)

        self.assertTrue(ok.__nonzero__())
        self.assertFalse(ko.__nonzero__())

    def test_py3_bool_resp(self):
        ok = FreeResponse(200)
        ko = FreeResponse(400)

        self.assertTrue(ok.__bool__())
        self.assertFalse(ko.__bool__())
Пример #3
0
class TestSMS(unittest.TestCase):
    def setUp(self):
        self.client = FreeClient(user="******", passwd="secret")

    def test_500(self):
        with HTTMock(smsapi_mock):
            resp = self.client.send_sms("oops code500 error")

        self.assertFalse(bool(resp))
        self.assertEquals(resp.status_code, 500)
        self.assertFalse(resp.success())
        self.assertTrue(resp.error())

    def test_400(self):
        with HTTMock(smsapi_mock):
            resp = self.client.send_sms("oops code400 error")

        self.assertFalse(bool(resp))
        self.assertEquals(resp.status_code, 400)

    def test_200(self):
        with HTTMock(smsapi_mock):
            resp = self.client.send_sms("oops code200 error")

        self.assertTrue(bool(resp))
        self.assertEquals(resp.status_code, 200)
        self.assertTrue(resp.success())
        self.assertFalse(resp.error())

    def test_py2_bool_resp(self):
        ok = FreeResponse(200)
        ko = FreeResponse(400)

        self.assertTrue(ok.__nonzero__())
        self.assertFalse(ko.__nonzero__())

    def test_py3_bool_resp(self):
        ok = FreeResponse(200)
        ko = FreeResponse(400)

        self.assertTrue(ok.__bool__())
        self.assertFalse(ko.__bool__())
Пример #4
0
class FreeSMSNotificationService(BaseNotificationService):
    """ Implements notification service for the Free Mobile SMS service. """
    def __init__(self, username, access_token):
        from freesms import FreeClient
        self.free_client = FreeClient(username, access_token)

    def send_message(self, message="", **kwargs):
        """ Send a message to the Free Mobile user cell. """
        resp = self.free_client.send_sms(message)

        if resp.status_code == 400:
            _LOGGER.error("At least one parameter is missing")
        elif resp.status_code == 402:
            _LOGGER.error("Too much SMS send in a few time")
        elif resp.status_code == 403:
            _LOGGER.error("Wrong Username/Password")
        elif resp.status_code == 500:
            _LOGGER.error("Server error, try later")
Пример #5
0
class FreeSMSNotificationService(BaseNotificationService):
    """Implement a notification service for the Free Mobile SMS service."""
    def __init__(self, username, access_token):
        """Initialize the service."""
        self.free_client = FreeClient(username, access_token)

    def send_message(self, message="", **kwargs):
        """Send a message to the Free Mobile user cell."""
        resp = self.free_client.send_sms(message)

        if resp.status_code == HTTP_BAD_REQUEST:
            _LOGGER.error("At least one parameter is missing")
        elif resp.status_code == 402:
            _LOGGER.error("Too much SMS send in a few time")
        elif resp.status_code == HTTP_FORBIDDEN:
            _LOGGER.error("Wrong Username/Password")
        elif resp.status_code == HTTP_INTERNAL_SERVER_ERROR:
            _LOGGER.error("Server error, try later")
Пример #6
0
class FreeSMSNotificationService(BaseNotificationService):
    """ Implements notification service for the Free Mobile SMS service. """

    def __init__(self, username, access_token):
        from freesms import FreeClient
        self.free_client = FreeClient(username, access_token)

    def send_message(self, message="", **kwargs):
        """ Send a message to the Free Mobile user cell. """
        resp = self.free_client.send_sms(message)

        if resp.status_code == 400:
            _LOGGER.error("At least one parameter is missing")
        elif resp.status_code == 402:
            _LOGGER.error("Too much SMS send in a few time")
        elif resp.status_code == 403:
            _LOGGER.error("Wrong Username/Password")
        elif resp.status_code == 500:
            _LOGGER.error("Server error, try later")
Пример #7
0
 def setUp(self):
     self.client = FreeClient(user="******", passwd="secret")
Пример #8
0
 def __init__(self, username, access_token):
     """Initialize the service."""
     from freesms import FreeClient
     self.free_client = FreeClient(username, access_token)
Пример #9
0
 def __init__(self, username, access_token):
     """Initialize the service."""
     from freesms import FreeClient
     self.free_client = FreeClient(username, access_token)
Пример #10
0
 def __init__(self, username, access_token):
     from freesms import FreeClient
     self.free_client = FreeClient(username, access_token)
Пример #11
0
 def setUp(self):
     self.client = FreeClient(user="******", passwd="secret")
Пример #12
0
            #IDX = sys.argv[1]
    except:
        MSG = "On vient de sonner"  # Message par defaut quand un appui sur la sonnette a ete detecte.
        IDX = 97

url = 'http://' + DOMO_IP + ':' + DOMO_PORT + '/json.htm'
arguments = {
    'type': 'command',
    'param': 'switchlight',
    'idx': IDX,
    'switchcmd': 'On'
}
r = requests.get(url, params=arguments)

for i in range(2):
    f = FreeClient(user=ABONNEMENTFREE[i], passwd=CLEEABONNEMENTFREE[i])
    resp = f.send_sms(MSG)

#sys.exit(0)

# -------- Allumage de la lumière quand il fait nuit --------------
sunrise = {'type': 'command', 'param': 'getSunRiseSet'}
r = requests.get(url, params=sunrise)
info = r.json()
couche = info['Sunset']
levee = info['Sunrise']

DAY, NIGHT = 1, 2


def check_time(time_to_check, on_time, off_time):
Пример #13
0
 def __init__(self, username, access_token):
     from freesms import FreeClient
     self.free_client = FreeClient(username, access_token)