Пример #1
0
    def _decode_control(self, _p_topic, p_message):
        """ Decode the message.
        As a side effect - control pioneer.

        @param p_message: is the payload used to control
        """
        LOG.debug('Decode-Control called:\n\tTopic:{}\n\tMessage:{}'.format(
            _p_topic, p_message))
        l_family = extract_tools.get_mqtt_field(p_message, 'Family')
        if l_family == None:
            l_family = 'pioneer'
        l_model = extract_tools.get_mqtt_field(p_message, 'Model')
        # l_device_obj = self._find_device(l_family, l_model)
        l_power = self._get_power(p_message)
        l_input = extract_tools.get_mqtt_field(p_message, 'Input')
        l_volume = extract_tools.get_mqtt_field(p_message, 'Volume')
        l_logmsg = '\tPioneer Control:\n\t\tDevice:{}-{}\n\t\tPower:{}\n\t\tVolume:{}\n\t\tInput:{}'.format(
            l_family, l_model, l_power, l_volume, l_input)
        #
        if l_power != None:
            l_logmsg += ' Turn power {} to {}.'.format(l_power, l_model)
            self._pioneer_power(l_family, l_model, l_power)
        #
        if l_input != None:
            l_logmsg += ' Turn input to {}.'.format(l_input)
            self._pioneer_input(l_family, l_model, l_input)
        #
        if l_volume != None:
            l_logmsg += ' Change volume {}.'.format(l_volume)
            self._pioneer_volume(l_family, l_model, l_volume)
        #
        return l_logmsg
Пример #2
0
 def _decode_control(self, p_message):
     """
     pyhouse/<housename>/house/lighting/light/xxx
     """
     l_control = LightData()
     l_light_name = extract_tools.get_mqtt_field(p_message, 'LightName')
     l_control.BrightnessPct = _l_brightness = extract_tools.get_mqtt_field(
         p_message, 'Brightness')
     LOG.info('Mqtt Control "{}'.format(l_light_name))
     # LOG.debug(PrettyFormatAny.form(l_control, 'Control'))
     #
     l_light_obj = lightingUtility().get_object_by_id(
         self.m_pyhouse_obj.House.Lighting.Lights, name=l_light_name)
     if l_light_obj == None:
         LOG.warn(' Light "{}" was not found.'.format(l_light_name))
         return
     # LOG.debug(PrettyFormatObject(l_light_obj, 'Light'))
     # LOG.debug(PrettyFormatAny.form(l_light_obj.Family, 'Light.Family'))
     #
     l_controller_obj = lightingUtility().get_controller_objs_by_family(
         self.m_pyhouse_obj.House.Lighting.Controllers, 'insteon')
     # LOG.debug(PrettyFormatAny.form(l_controller_obj[0], 'Controller'))
     #
     if len(l_controller_obj) > 0:
         l_api = FamUtil._get_family_device_api(self.m_pyhouse_obj,
                                                l_light_obj)
         if l_api == None:
             return
         l_api.AbstractControlLight(self.m_pyhouse_obj, l_light_obj,
                                    l_controller_obj[0], l_control)
Пример #3
0
    def decode(self, p_topic, p_message):
        """ Decode the Mqtt message
        ==> pyhouse/<house name>/house/entertainment/onkyo/<type>
        <type> = control, status

        @param p_topic: is the topic with pyhouse/housename/entertainment/onkyo stripped off.
        @param p_message: is the body of the json message string.
        """
        LOG.debug('Decode called:\n\tTopic:{}\n\tMessage:{}'.format(
            p_topic, p_message))
        l_logmsg = ' Onkyo-{}'.format(p_topic[0])
        self.m_sender = extract_tools.get_mqtt_field(p_message, 'Sender')
        self.m_model = extract_tools.get_mqtt_field(p_message, 'Model')
        # self.m_device = self._find_model(SECTION, self.m_model)

        if p_topic[0].lower() == 'control':
            l_logmsg += '\tControl: {}\n'.format(
                self._decode_control(p_topic, p_message))
        elif p_topic[0].lower() == 'status':
            l_logmsg += '\tStatus: {}\n'.format(
                self._decode_status(p_topic, p_message))
        else:
            l_logmsg += '\tUnknown Onkyo sub-topic: {}  Message: {}'.format(
                p_topic,
                PrettyFormatAny.form(p_message, 'Entertainment msg', 160))
            LOG.warn('Unknown Onkyo Topic: {}'.format(p_topic[0]))
        return l_logmsg
Пример #4
0
 def _decode_room(self, p_topic, p_message, p_logmsg):
     p_logmsg += '\tRooms:\n'
     if p_topic[1] == 'add':
         p_logmsg += '\tName: {}\n'.format(extract_tools.get_mqtt_field(p_message, 'Name'))
     elif p_topic[1] == 'delete':
         p_logmsg += '\tName: {}\n'.format(extract_tools.get_mqtt_field(p_message, 'Name'))
     elif p_topic[1] == 'sync':
         p_logmsg += '\tName: {}\n'.format(extract_tools.get_mqtt_field(p_message, 'Name'))
     elif p_topic[1] == 'update':
         p_logmsg += '\tName: {}\n'.format(extract_tools.get_mqtt_field(p_message, 'Name'))
     else:
         p_logmsg += '\tUnknown sub-topic {}'.format(PrettyFormatAny.form(p_message, 'Rooms msg', 160))
     return p_logmsg
Пример #5
0
 def decode(self, p_topic, p_message):
     """ Decode the computer specific portions of the message and append them to the log string.
     @param p-logmsg: is the partially decoded Mqtt message json
     @param p_topic: is a list of topic part strings ( pyhouse, housename have been dropped
     @param p_message: is the payload that is JSON
     """
     l_logmsg = '\tComputer:\n'
     if p_topic[0] == 'browser':
         l_logmsg += '\tBrowser: Message {}'.format(PrettyFormatAny.form(p_message, 'Computer msg', 160))
     elif p_topic[0] == 'node' or p_topic[0] == 'nodes':
         l_logmsg += nodesMqtt(self.m_pyhouse_obj).decode(p_topic[1:], p_message, l_logmsg)
     #  computer/ip
     elif p_topic[1] == 'ip':
         l_ip = extract_tools.get_mqtt_field(p_message, 'ExternalIPv4Address')
         l_logmsg += '\tIPv4: {}'.format(l_ip)
     #  computer/startup
     elif p_topic[1] == 'startup':
         self._extract_node(p_message)
         l_logmsg += '\tStartup {}'.format(PrettyFormatAny.form(p_message, 'Computer msg', 160))
         if self.m_myname == self.m_sender:
             l_logmsg += '\tMy own startup of PyHouse\n'
         else:
             l_logmsg += '\tAnother computer started up: {}'.format(self.m_sender)
     #  computer/shutdown
     elif p_topic[1] == 'shutdown':
         del self.m_pyhouse_obj.Computer.Nodes[self.m_name]
         l_logmsg += '\tSelf Shutdown {}'.format(PrettyFormatAny.form(p_message, 'Computer msg', 160))
     #  computer/***
     else:
         l_logmsg += '\tUnknown sub-topic {}'.format(PrettyFormatAny.form(p_message, 'Computer msg', 160))
     return l_logmsg
Пример #6
0
 def _decode_hvac(self, p_logmsg, _p_topic, p_message):
     p_logmsg += '\tThermostat:\n'
     p_logmsg += '\tName: {}'.format(self.m_name)
     p_logmsg += '\tRoom: {}\n'.format(self.m_room_name)
     p_logmsg += '\tTemp: {}'.format(
         extract_tools.get_mqtt_field(p_message, 'CurrentTemperature'))
     return p_logmsg
Пример #7
0
 def decode(self, p_topic, p_message):
     """ Decode the Mqtt message
     ==> pyhouse/<house name>/security/<type>/<Name>
     <type> = garage door, motion sensor, camera
     """
     l_logmsg = '\tSecurity:\n'
     if p_topic[0] == 'garage_door':
         l_logmsg += '\tGarage Door: {}\n'.format(
             get_mqtt_field(p_message, 'Name'))
     elif p_topic[0] == 'motion_sensor':
         l_logmsg += '\tMotion Sensor:{}\n\t{}'.format(
             get_mqtt_field(p_message, 'Name'),
             get_mqtt_field(p_message, 'Status'))
     else:
         l_logmsg += '\tUnknown sub-topic {}'.format(
             PrettyFormatAny.form(p_message, 'Security msg', 160))
     return l_logmsg
Пример #8
0
 def _get_power(self, p_message):
     """
     force power to be None, 'On' or 'Off'
     """
     l_ret = extract_tools.get_mqtt_field(p_message, 'Power')
     if l_ret == None:
         return l_ret
     if l_ret == 'On':
         return 'On'
     return 'Off'
Пример #9
0
    def _decode_control(self, p_topic, p_message):
        """ Decode the message.
        As a side effect - control samsung.
        """
        l_logmsg = '\tControl: '
        l_control = extract_tools.get_mqtt_field(p_message, 'Control')
        if l_control == 'On':
            l_logmsg += ' Turn On '
            self.m_api.Start()
        elif l_control == 'Off':
            l_logmsg += ' Turn Off '
            self.m_api.Stop()

        elif l_control == 'VolUp1':
            l_logmsg += ' Volume Up 1 '
        else:
            l_logmsg += ' Unknown samsung Control Message {} {}'.format(
                p_topic, p_message)
        return l_logmsg
Пример #10
0
 def decode(self, p_topic, p_message, p_logmsg):
     """ Decode the computer specific portions of the message and append them to the log string.
     @param p-logmsg: is the partially decoded Mqtt message json
     @param p_topic: is a list of topic part strings ( pyhouse, housename have been dropped
     @param p_message: is the payload that is JSON
     """
     p_logmsg += '\tNodes:\n'
     l_topic = p_topic[0].lower()
     if l_topic == 'browser':
         p_logmsg += '\tBrowser: Message {}'.format(
             PrettyFormatAny.form(p_message, 'Computer msg', 160))
     #  computer/ip
     elif l_topic == 'ip':
         l_ip = extract_tools.get_mqtt_field(p_message,
                                             'ExternalIPv4Address')
         p_logmsg += '\tIPv4: {}'.format(l_ip)
     #  computer/startup
     elif l_topic == 'startup':
         self._extract_node(p_message)
         p_logmsg += '\tStartup {}'.format(
             PrettyFormatAny.form(p_message, 'Computer msg', 160))
         if self.m_myname == self.m_sender:
             p_logmsg += '\tMy own startup of PyHouse\n'
         else:
             p_logmsg += '\tAnother computer started up: {}'.format(
                 self.m_sender)
     #  computer/shutdown
     elif l_topic == 'shutdown':
         del self.m_pyhouse_obj.Computer.Nodes[self.m_name]
         p_logmsg += '\tSelf Shutdown {}'.format(
             PrettyFormatAny.form(p_message, 'Computer msg', 160))
     #
     elif l_topic == 'sync':
         p_logmsg += syncAPI(self.m_pyhouse_obj).DecodeMqttMessage(
             p_topic[1:], p_message)
     else:
         p_logmsg += '\tUnknown sub-topic {}'.format(
             PrettyFormatAny.form(p_message, 'Computer msg', 160))
         LOG.warn('Unknown Node sub-topic: {}\n\tMsg: {}'.format(
             l_topic, p_message))
     return p_logmsg
Пример #11
0
    def _decode_control(self, p_topic, p_message):
        """ Decode the control message.

        @param p_message: is the payload used to control
        """
        LOG.debug('Decode-Control called:\n\tTopic:{}\n\tMessage:{}'.format(
            p_topic, p_message))
        l_sender = extract_tools.get_mqtt_field(p_message, 'Sender')
        l_family = extract_tools.get_mqtt_field(p_message, 'Family')
        l_model = extract_tools.get_mqtt_field(p_message, 'Model')
        if l_family == None:
            l_family = 'onkyo'
        l_device_obj = self._find_model(l_family, l_model)
        #
        l_zone = extract_tools.get_mqtt_field(p_message, 'Zone')
        l_power = self._get_power(p_message)
        l_input = extract_tools.get_mqtt_field(p_message, 'Input')
        l_volume = extract_tools.get_mqtt_field(p_message, 'Volume')
        l_logmsg = 'Control from: {}; '.format(l_sender)
        if l_power != None:
            l_queue = OnkyoQueueData()
            l_queue.Command = 'Power'
            l_queue.Args = l_power
            l_queue.Zone = l_zone
            l_device_obj._Queue.put(l_queue)
            l_logmsg += ' Turn power {} to {}.'.format(l_power, l_model)
        if l_input != None:
            l_queue = OnkyoQueueData()
            l_queue.Command = 'InputSelect'
            l_queue.Args = l_input
            l_queue.Zone = l_zone
            l_device_obj._Queue.put(l_queue)
            l_logmsg += ' Turn input to {}.'.format(l_input)
        if l_volume != None:
            l_queue = OnkyoQueueData()
            l_queue.Command = 'Volume'
            l_queue.Args = l_volume
            l_queue.Zone = l_zone
            l_device_obj._Queue.put(l_queue)
            l_logmsg += ' Turn volume to {}.'.format(l_volume)
        self.run_queue(l_device_obj)
        #
        LOG.info('Decode-Control 2 called:\n\tTopic:{}\n\tMessage:{}'.format(
            p_topic, p_message))
        return l_logmsg
Пример #12
0
 def _decode_thermostat(self, _p_topic, p_message, p_logmsg):
     """
     """
     p_logmsg += '\tThermostat: {}\n'.format(
         extract_tools.get_mqtt_field(p_message, 'Name'))
     return p_logmsg
Пример #13
0
    def _decode_control(self, p_topic, p_message):
        """ Decode the Pandora Control message we just received.
         Someone (web page via node-red) wants to control pandora in some manner.

         ServiceName must match one of the Pandora services on this node.

        ==>
            Topic: pyhouse/<house name>/house/entertainment/pandora/control
            Msg:{   'Time':   '2019-05-07T22:19:19.536Z',
                    'Sender': 'pi-04-pp',
                    'Status': 'On'}


        We may need to issue a message to control connected audio devices.
                    Zone:  0,1 ...
                    Power: On, Off
                    Input: Tv, Game
                    Volume: 0..100
        As a side effect, we need to control Pandora ( PianoBar ) via the control socket
                    Like:
                    Dislike:
                    Skip:
        """
        l_logmsg = '\tPandora Control'
        l_zone = extract_tools.get_mqtt_field(p_message, 'Zone')
        l_input = extract_tools.get_mqtt_field(p_message, 'Input')
        l_power = extract_tools.get_mqtt_field(p_message, 'Power')
        l_volume = extract_tools.get_mqtt_field(p_message, 'Volume')
        l_like = extract_tools.get_mqtt_field(p_message, 'Like')
        l_skip = extract_tools.get_mqtt_field(p_message, 'Skip')
        if l_zone == None:
            l_zone = 0
        LOG.debug('{} {}'.format(p_topic, p_message))

        # These directly control pianobar(pandora)
        if l_power == 'On':
            l_logmsg += ' Turn On '
            PandoraControl(self.m_pyhouse_obj)._start_pandora(p_message)
            A_V_Control(self.m_pyhouse_obj).change_av_device(
                l_zone, l_power, l_input, l_volume)
            return l_logmsg
        elif l_power == 'Off':
            l_logmsg += ' Turn Off '
            PandoraControl(self.m_pyhouse_obj)._halt_pandora(p_message)
            A_V_Control(self.m_pyhouse_obj).change_av_device(
                l_zone, l_power, l_input, l_volume)
            return l_logmsg
        elif l_volume != None:
            l_logmsg += ' Volume to: {}'.format(l_volume)
            A_V_Control(self.m_pyhouse_obj).change_av_device(
                l_zone, l_power, l_input, l_volume)
            return l_logmsg
        elif l_like == 'LikeYes':
            l_logmsg += ' Like '
            l_like = 'Yes'
        elif l_like == 'LikeNo':
            l_logmsg += ' Dislike '
            l_like = 'No'
        elif l_skip == 'SkipYes':
            l_logmsg += ' Skip '
            l_skip = 'Yes'
        else:
            l_logmsg += ' Unknown Pandora Control Message {} {}'.format(
                p_topic, p_message)
        return l_logmsg