def publish_dimmer_cancelled_action(self, arduino_name: str, button_number: int) -> None: publish_topic = constants.iRulezTopic + '/' + constants.dimmerCancelled + '/' + constants.dimmerModuleTopic payload = util.serialize_json({ "arduino_name": arduino_name, "button_number": button_number }) logger.debug(f"Publishing: {publish_topic}{payload}") self.client.publish(publish_topic, payload, 0, False)
def publish_relative_action(self, individual_action) -> None: payload = \ util.serialize_json( {"name": individual_action.name, "topic": constants.iRulezTopic + '/' + individual_action.name + '/' + constants.actionTopic, "on": individual_action.pin_numbers_on, "off": individual_action.pin_numbers_off, "delay": individual_action.delay}) logger.debug(f"Publishing: {individual_action.topic}{payload}") self.client.publish(individual_action.topic, payload, 0, False)
def get_arduino_dim_pin_status(self, name: str, pin: int) -> Optional[str]: arduino = self.arduinos.get(name, None) if arduino is None: # Unknown arduino logger.info(f"Could not find arduino with name '{name}'.") return None return util.serialize_json( { "state": arduino.output_pins[pin].dim_state, "direction": arduino.output_pins[pin].direction } )
def publish_dimming_action_to_timer(self, dimming_action_id: uuid.UUID, delay: int): publish_topic = topic_factory.create_timer_dimmer_timer_fired_topic() topic_name = topic_factory.create_timer_dimmer_timer_fired_response_topic( ) payload = util.serialize_json({ 'topic': topic_name, 'payload': str(dimming_action_id), 'delay': delay }) logger.debug(f"Publishing: {publish_topic}{payload}") self.__client.publish(publish_topic, payload, 0, False)
def publish_last_light_values( self, last_light_values_to_update: Dict[int, int]) -> None: publish_topic = topic_factory.create_last_light_value_update_topic() for dimmer_output_pin_id in last_light_values_to_update: payload = util.serialize_json({ 'dimmer_id': dimmer_output_pin_id, 'last_light_value': last_light_values_to_update[dimmer_output_pin_id] }) logger.debug(f"Publishing: {publish_topic}{payload}") self.client.publish(publish_topic, payload, 0, False)
def publish_multiclick_message_to_button_processor( self, multiclick: List[object]): arduino_name = multiclick[0] button_pin = multiclick[1] clicks = multiclick[2] publish_topic = constants.iRulezTopic + '/' + constants.buttonMulticlickFiredTopic payload = util.serialize_json({ "name": arduino_name, "button_pin": button_pin, "clicks": clicks }) logger.debug(f"Publishing: {publish_topic}{payload}") self.client.publish(publish_topic, payload, 0, False)
def publish_message_to_button_processor(self, timer: List[object]): arduino_name = timer[0] button_pin = timer[1] seconds_down = timer[2] clicks = timer[3] publish_topic = constants.iRulezTopic + '/' + constants.buttonTimerFiredTopic payload = util.serialize_json({ "name": arduino_name, "button_pin": button_pin, "seconds_down": seconds_down, "clicks": clicks }) logger.debug(f"Publishing: {publish_topic}{payload}") self.client.publish(publish_topic, payload, 0, False)
def publish_dimmer_module_action( self, json_list: Dict[str, List[irulez_domain.IndividualDimAction]], arduino_name: str, button_number: int): for name in json_list: for i in range(len(json_list[name])): topic_name = constants.iRulezTopic + '/' + name + '/' + constants.actionTopic publish_topic = constants.iRulezTopic + '/' + constants.actionTopic + '/' + constants.dimmerModuleTopic if json_list[name][i].delay != 0: logger.error( f"Delayed dimmer module messages aren't supported yet!" ) return topic_name = topic_name + '/' + constants.dimmerModuleTopic publish_topic = publish_topic + '/' + constants.timerTopic payload = util.serialize_json({ "name": name, "topic": topic_name, "pins": json_list[name][i].pin_numbers, "delay": json_list[name][i].delay, "speed": json_list[name][i].speed, "dim_light_value": json_list[name][i].dim_light_value, "cancel_on_button_release": json_list[name][i].cancel_on_button_release, "arduino_name": arduino_name, "button_number": button_number }) logger.debug(f"Publishing: {publish_topic}{payload}") self.client.publish(publish_topic, payload, 0, False)
def publish_relative_action( self, json_list: Dict[str, List[irulez_domain.IndividualAction]]): # for name in json_list: # topic_name = constants.arduinoTopic + '/' + name + '/' + constants.actionTopic # publish_topic = constants.arduinoTopic + '/' + constants.actionTopic + '/' + constants.relativeTopic # if json_list[name].delay != 0: # topic_name = topic_name + '/' + constants.relativeTopic # publish_topic = publish_topic + '/' + constants.timerTopic # # payload = util.serialize_json( # { # "name": name, # "topic": topic_name, # "on": json_list[name].pin_numbers_on, "off": json_list[name].pin_numbers_off, # "delay": json_list[name].delay}) # # logger.debug(f"Publishing: {publish_topic}{payload}") # self.client.publish(publish_topic, payload, 0, False) for name in json_list: for i in range(len(json_list[name])): topic_name = constants.iRulezTopic + '/' + name + '/' + constants.actionTopic publish_topic = constants.iRulezTopic + '/' + constants.actionTopic + '/' + constants.relativeTopic if json_list[name][i].delay != 0: topic_name = topic_name + '/' + constants.relativeTopic publish_topic = publish_topic + '/' + constants.timerTopic payload = util.serialize_json({ "name": name, "topic": topic_name, "on": json_list[name][i].pin_numbers_on, "off": json_list[name][i].pin_numbers_off, "delay": json_list[name][i].delay }) logger.debug(f"Publishing: {publish_topic}{payload}") self.client.publish(publish_topic, payload, 0, False)
def test_get_bool(self) -> None: json_object = util.serialize_json({"key": True}) deserialized = util.deserialize_json(json_object) result = util.get_int_from_json_object(deserialized, "key") self.assertEqual(True, result)
def get_payload(self) -> str: return util.serialize_json({ "tokens": self.tokens, "message": self.message })
def get_payload(self) -> str: return util.serialize_json({ "mails": self.mails, "message": self.message, "subject": self.subject })