def test_send_batch_data(self): io = self.get_client() self.ensure_feed_deleted(io, 'testfeed') test_feed = io.create_feed(Feed(name="testfeed")) data_list = [Data(value=42), Data(value=42)] io.send_batch_data(test_feed.key, data_list) data = io.receive(test_feed.key) self.assertEqual(int(data.value), 42)
def echo_all(message): if str(message.text) == 'Light on' or str(message.text) == 'light on' or str(message.text) == 'On' or str(message.text) == 'on': from Adafruit_IO import Data data = Data(value=1) aio.create_data('mylightbot', data) bot.reply_to(message,'light is on') bot.send_photo(chat_id, photo=("https://ak.picdn.net/shutterstock/videos/3560576/thumb/1.jpg")) elif str(message.text) == 'Light off' or str(message.text) == 'light off' or str(message.text) == 'Off' or str(message.text) == 'off': from Adafruit_IO import Data data = Data(value=0) aio.create_data('mylightbot', data) bot.reply_to(message,'light is off') bot.send_photo(chat_id, photo=("https://ak.picdn.net/shutterstock/videos/3560594/thumb/1.jpg"))
def turn_off_light(bot,update): value = Data(value=0) value_send = aio.create_data('bot',value) chat_id = update.message.chat_id bot.send_message(chat_id,text='The light is turned off') bot.send_photo(chat_id,photo='https://tse3.mm.bing.net/th?id=OIP.ArFIDBnNFp2NeARkI6tIhgHaKP&pid=Api&P=0&w=300&h=300') u = Updater('1376734750:AAGoRkNk2_5lXTcf67f9Keibrny5giRT43Y')
def on(bot,update): chat_id=update.message.chat_id bot.send_photo(chat_id,photo='https://cdn1.vectorstock.com/i/1000x1000/59/15/bulb-light-icon-line-lamp-on-symbol-vector-21085915.jpg') bot.send_message(chat_id,text='bulb turned on') aio = Client(x,y) value=Data(value=1) value_send=aio.create_data('lightningbot',value)
def test_create_data(self): aio = self.get_client() self.ensure_feed_deleted(aio, 'testfeed') test_feed = aio.create_feed(Feed(name="testfeed")) aio.send_data('testfeed', 1) # Make sure TestFeed exists. data = Data(value=42) result = aio.create_data('testfeed', data) self.assertEqual(int(result.value), 42)
def off(bot, update): chat_id = update.message.chat_id bot.send_photo(chat_id, photo='https://pngimg.com/uploads/bulb/bulb_PNG1241.png') bot.send_message(chat_id, text='led is off') aio = Client(x, y) value = Data(value=0) value_send = aio.create_data('bot', value)
def off(bot, update): chat_id = update.message.chat_id bot.send_photo( chat_id, photo=("https://ak.picdn.net/shutterstock/videos/3560594/thumb/1.jpg"), caption='Turning Lights off.') value = Data(value=0) value_send = aio.create_data('bot123', value)
def on(bot, update): chat_id = update.message.chat_id bot.send_photo(chat_id, photo='https://img.icons8.com/plasticine/2x/light-on.png') bot.send_message(chat_id, text='led is on') aio = Client(x, y) value = Data(value=1) value_send = aio.create_data('bot', value)
def off(bot,update): url = get_url() chat_id = update.message.chat_id txt = 'light is turning off' pic = 'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTuueKIndqjMG0rlzPZrO0UUFP6ts8b_CrUIQ&usqp=CAU' bot.send_message(chat_id,txt) bot.send_photo(chat_id,pic) value = Data(value=0) value_send = aio.create_data('lit',value)
def ledoff(bot, update): value = Data(value=0) #Sending a value to a feed value_send = aio.create_data('chatbot', value) chat_id = bot.message.chat_id update.bot.sendPhoto( chat_id=chat_id, photo= "https://pp.netclipart.com/pp/s/147-1471460_graphic-freeuse-download-light-clipart-black-and-white.png", caption="light off")
def ledon(bot, update): value = Data(value=1) value_send = aio.create_data('chatbot', value) chat_id = bot.message.chat_id update.bot.sendPhoto( chat_id=chat_id, photo= "https://toppng.com/uploads/preview/light-bulb-on-off-png-11553940194wdc9uy3j5o.png", caption="light on")
def on(bot,update): url = get_url() chat_id = update.message.chat_id txt = 'light is turning on' pic = 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5d/Green_sphere.svg/1024px-Green_sphere.svg.png' bot.send_message(chat_id,txt) bot.send_photo(chat_id,pic) value = Data(value=1) value_send = aio.create_data('lit',value)
def ledoff(bot, update): value = Data(value=0) #Sending a value to a feed value_send = aio.create_data('chatbot1', value) chat_id = bot.message.chat_id update.bot.sendPhoto( chat_id=chat_id, photo= "https://tse3.mm.bing.net/th?id=OIP.dTmDdvOWEO-0s7t0Z3Yr4gHaJ4&pid=Api&P=0&w=300&h=300", caption="light off")
def stop_alarm(): global timer_stop timer_stop = time.time() reaction_time = timer_stop - timer_start reaction_time = round(reaction_time, 2) print(reaction_time) os.system('kill $(pgrep omxplayer)') data = Data(value=reaction_time) aio.create_data('stop-alarm', data)
def ledon(bot, update): value = Data(value=1) value_send = aio.create_data('chatbot1', value) chat_id = bot.message.chat_id update.bot.sendPhoto( chat_id=chat_id, photo= "https://tse1.mm.bing.net/th?id=OIP.E0jSIrVy0lS6LIULac0rngHaKj&pid=Api&P=0&w=300&h=300", caption="light on")
def off(bot,update): chat_id = update.message.chat_id txt = 'light is turning off' #to display the message that light is turning off pic = 'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTYcNq48qvRya6UCjHWkjCRQiqoxJRnYUSQ4w&usqp=CAU' #to display the green indication image time.sleep(2) bot.send_message(chat_id,txt) time.sleep(1) bot.send_photo(chat_id,pic) value = Data(value=0) value_send = aio.create_data('lit',value) #sending value to a feed with key 'lit' which is already created
def on(bot,update): chat_id = update.message.chat_id txt = 'light is turning on' #to display the message that light is turning on pic = 'https://assets.bose.com/content/dam/Bose_DAM/Web/consumer_electronics/support/articles/speakers/solo_10_series_ii/system_settings/solo_volume_max_green.psd/_jcr_content/renditions/cq5dam.web.320.320.jpeg' #to display the green indication image time.sleep(2) bot.send_message(chat_id,txt) time.sleep(1) bot.send_photo(chat_id,pic) value = Data(value=1) value_send = aio.create_data('lit',value) #sending value to a feed with key 'lit' which is already created
def off(bot, update): chat_id = update.message.chat_id bot.send_message(chat_id, text="Led is off") bot.send_photo( chat_id, photo= 'https://cdn5.vectorstock.com/i/1000x1000/59/14/bulb-light-icon-line-idea-symbol-vector-21085914.jpg' ) value = Data(value=0) value_send = aio.create_data('BOT', value)
def on(bot, update): chat_id = update.message.chat_id bot.send_message(chat_id, text="Led is on") bot.send_photo( chat_id, photo= 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5d/Green_sphere.svg/1024px-Green_sphere.svg.png' ) value = Data(value=1) value_send = aio.create_data('lightbot', value)
def led_off(bot, update): value = Data(value=0) #Sending a value to a feed value_send = aio.create_data('ledbot', value) chat_id = bot.message.chat_id bot.message.reply_text('Light is turning off... wait for a moment') update.bot.sendPhoto( chat_id=chat_id, photo= "https://toppng.com/uploads/preview/light-bulb-on-off-png-11553940208oq66nq8jew.png", caption="Light turned off!")
def led_on(bot, update): value = Data(value=1) value_send = aio.create_data('ledbot', value) chat_id = bot.message.chat_id bot.message.reply_text('Light is turning on... wait for a moment') update.bot.sendPhoto( chat_id=chat_id, photo= "https://toppng.com/uploads/preview/light-bulb-on-off-png-11553940194wdc9uy3j5o.png", caption="Light turned on!")
def off(bot,update): url = get_url() chat_id = update.message.chat_id txt = 'ligth turned off' pic = 'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTuueKIndqjMG0rlzPZrO0UUFP6ts8b_CrUIQ&usqp=CAU' bot.send_message(chat_id, txt) bot.send_photo(chat_id, pic) from Adafruit_IO import Data value = Data(value=0) value_send = aio.create_data('yeshwinbot',value)
def off(bot, update): chat_id = update.message.chat_id bot.send_message(chat_id, text="Led is off") bot.send_photo( chat_id, photo= 'https://cainlive.com/wp-content/uploads/2018/08/cropped-clip-art-red-dot-clipart-1.png' ) value = Data(value=0) value_send = aio.create_data('lightbot', value)
def on(bot, update): chat_id = update.message.chat_id bot.send_message(chat_id, text="Led is on") bot.send_photo( chat_id, photo= 'https://cdn1.vectorstock.com/i/1000x1000/59/15/bulb-light-icon-line-lamp-on-symbol-vector-21085915.jpg' ) value = Data(value=1) value_send = aio.create_data('BOT', value)
def on(bot,update): url = get_url() chat_id = update.message.chat_id txt = 'ligth turned on' pic = 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5d/Green_sphere.svg/1024px-Green_sphere.svg.png' bot.send_message(chat_id, txt) bot.send_photo(chat_id, pic) from Adafruit_IO import Data value = Data(value=1) value_send = aio.create_data('telebot',value)
def all_off(username, key): aio = Client(username, key) feeds_key = ["yatak-odasi-isik1", "yatak-odasi-isik2", "yatak-odasi-isik3"] data = Data(value="OFF") for feed_key in feeds_key: aio.create_data(feed_key, data) return ("All the lights in the bedroom turned off")
def test_data_properties_are_optional(self): data = Data(value='foo', feed_id=10) self.assertEqual(data.value, 'foo') self.assertEqual(data.feed_id, 10) self.assertIsNone(data.created_epoch) self.assertIsNone(data.created_at) self.assertIsNone(data.updated_at) self.assertIsNone(data.completed_at) self.assertIsNone(data.expiration) self.assertIsNone(data.position) self.assertIsNone(data.id)
def turnon(bot, update): chat_id = update.message.chat_id bot.send_photo( chat_id, photo= 'https://www.christmaslightsetc.com/p/G40-E12-Clear-Globe-Replacement-Lamps--18769.htm#' ) bot.send_message(chat_id, text="the BULB is ON") aio = Client(a, b) value = Data(value=1) value_send = aio.create_data('botpubgbot', value)
def turnoff(bot, update): chat_id = update.message.chat_id bot.send_photo( chat_id, photo= 'https://www.batteriesplus.com/content/images/product/large/443078.jpg' ) bot.send_message(chat_id, text="The BULB is OFF") aio = Client(a, b) value = Data(value=0) value_send = aio.create_data('botpubgbot', value)
def test_from_dict_ignores_unknown_items(self): data = Data.from_dict({'value': 'foo', 'feed_id': 10, 'unknown_param': 42}) self.assertEqual(data.value, 'foo') self.assertEqual(data.feed_id, 10) self.assertIsNone(data.created_epoch) self.assertIsNone(data.created_at) self.assertIsNone(data.updated_at) self.assertIsNone(data.completed_at) self.assertIsNone(data.expiration) self.assertIsNone(data.position) self.assertIsNone(data.id)
def send_batch_data(self, feed, data_list, created_at=None): # Setup batch data with custom created_at values if created_at is None: time = datetime.datetime.utcnow().isoformat() else: time = created_at.isoformat() # The data batch data_tuplelist = [Data(value=data_list[_idx], created_at=time) for _idx in range(len(data_list))] # Send batch data self.aio.send_batch_data(feed.key, data_tuplelist)