def load(self, char_type: str): """ This function loads a decoder for the specified characteristics: - get the name of the characteristic via the given uuid (via `CharacteristicsTypes.get_short()`) - load a module from `homekit.model.characteristics` plus the name of the characteristic - the module must contain a function `decoder` :param char_type: the uuid of the characteristic :return: a function that decodes the value of the characteristic into a `tlv8.EntryList` """ characteristic_name = CharacteristicsTypes.get_short(char_type) if characteristic_name.startswith('Unknown'): mod_name = 'uuid_{}'.format(char_type.replace('-', '_')) logging.info('modname %s', mod_name) else: mod_name = characteristic_name.replace('-', '_') if char_type not in self.decoders: # try to dynamically load from the standard characteristics by name try: logging.info('loading module "%s" for type "%s"', mod_name, char_type) module = importlib.import_module('homekit.model.characteristics.' + mod_name) decoder = getattr(module, 'decoder') self.decoders[char_type] = decoder return decoder except Exception as e: logging.info('Error loading decoder: "%s" for type "%s"', e, char_type) # try to load from all plugins, it may be a non-standard characteristic with vendor specific data try: for _, plugin_name, _ in pkgutil.iter_modules(): if not plugin_name.startswith('homekit_'): continue logging.info('loading module "%s" for type "%s" from plugin "%s"', mod_name, char_type, plugin_name) module = importlib.import_module('.model.characteristics.' + mod_name, plugin_name) decoder = getattr(module, 'decoder') self.decoders[char_type] = decoder return decoder except Exception as e: logging.info('Error loading decoder: "%s" for type "%s"', e, char_type) return None else: logging.info('got decoder for %s from cache', char_type) return self.decoders[char_type]
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import tlv8 from enum import IntEnum from homekit.model.characteristics.characteristic_types import CharacteristicsTypes CHARACTERISTIC_ID = CharacteristicsTypes.get_uuid( CharacteristicsTypes.SUPPORTED_AUDIO_CONFIGURATION) class SupportedAudioStreamConfigurationKeys(IntEnum): """ Page 215 / Table 9-18 """ AUDIO_CODEC_CONFIGURATION = 1 COMFORT_NOISE_SUPPORT = 2 class AudioCodecConfigurationKeys(IntEnum): """ Page 215 / Table 9-18 """ CODEC_TYPE = 1
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import tlv8 from enum import IntEnum from homekit.model.characteristics.supported_video_stream_configuration import VideoAttributesKeys, \ VideoCodecParametersKeys, ProfileIdValues, VideoCodecTypeValues, LevelValues, CVOEnabledValue, \ PacketizationModeValues from homekit.model.characteristics.supported_audio_configuration import AudioCodecParametersKeys, \ BitRateValues, SampleRateValues, RtpTimeValues from homekit.model.characteristics.characteristic_types import CharacteristicsTypes CHARACTERISTIC_ID = CharacteristicsTypes.get_uuid(CharacteristicsTypes.SELECTED_RTP_STREAM_CONFIGURATION) class SelectedRtpStreamConfigurationKeys(IntEnum): """ Page 204 / Table 9-7 """ SESSION_CONTROL = 1 SELECTED_VIDEO_PARAMS = 2 SELECTED_AUDIO_PARAMS = 3 class SessionControlKeys(IntEnum): """ Page 205 / Table 9-8 """
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import tlv8 from enum import IntEnum from homekit.model.characteristics.characteristic_types import CharacteristicsTypes CHARACTERISTIC_ID = CharacteristicsTypes.get_uuid(CharacteristicsTypes.STREAMING_STATUS) class StreamingStatusKeys(IntEnum): """ Page 215 / Table 9-17 """ STATUS = 1 class StreamingStatusValues(IntEnum): """ Page 215 / Table 9-17 Values for Key Status """ AVAILABLE = 0 IN_USE = 1
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import tlv8 from enum import IntEnum from homekit.model.characteristics.characteristic_types import CharacteristicsTypes CHARACTERISTIC_ID = CharacteristicsTypes.get_uuid( CharacteristicsTypes.SUPPORTED_VIDEO_STREAM_CONFIGURATION) class SupportedVideoStreamConfigurationKeys(IntEnum): """ Page 219 / Table 9-25 """ VIDEO_CODEC_CONFIGURATION = 1 class VideoCodecConfigurationKeys(IntEnum): """ Page 219 / Table 9-26 """ VIDEO_CODEC_TYPE = 1 VIDEO_CODEC_PARAMETERS = 2
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import tlv8 from enum import IntEnum from homekit.model.characteristics.characteristic_types import CharacteristicsTypes CHARACTERISTIC_ID = CharacteristicsTypes.get_uuid(CharacteristicsTypes.SETUP_ENDPOINTS) class CameraSRTPCryptoSuiteValues(IntEnum): """ Page 218 / Table 9-24 Values for key 'SRTP Crypto Suite' Page 209 / Table 9-15 Values for key 'SRTP Crypto Suite' """ AES_CM_128_HMAC_SHA1_80 = 0 AES_256_CM_HMAC_SHA1_80 = 1 DISABLED = 2 class SrtpParameterKeys(IntEnum): """ Page 209 / Table 9-15
def test_get_short_unknown(self): self.assertEqual('Unknown Characteristic 1234', CharacteristicsTypes.get_short('1234'))
def test_get_short_short_uuid(self): self.assertEqual('position.current', CharacteristicsTypes.get_short('6D'))
def test_get_short_full_uuid(self): self.assertEqual( 'position.current', CharacteristicsTypes.get_short( '0000006D-0000-1000-8000-0026BB765291'))
def test_get_short_uuid_passthrough(self): self.assertEqual( '0000006D-1234-1234-1234-012345678901', CharacteristicsTypes.get_short_uuid( '0000006D-1234-1234-1234-012345678901'))
def test_get_short_uuid_short(self): self.assertEqual('6D', CharacteristicsTypes.get_short_uuid('6D'))
def test_get_short_uuid_name(self): self.assertEqual( '6D', CharacteristicsTypes.get_short_uuid( 'public.hap.characteristic.position.current'))
def test_get_short_uuid_full_uuid(self): self.assertEqual( '6D', CharacteristicsTypes.get_short_uuid( '0000006D-0000-1000-8000-0026BB765291'))
def test_get_uuid_name(self): self.assertEqual( '0000006D-0000-1000-8000-0026BB765291', CharacteristicsTypes.get_uuid( 'public.hap.characteristic.position.current'))
def test_get_uuid_passthrough(self): self.assertEqual( '4AAAF936-0DEC-11E5-B939-0800200C9A66', CharacteristicsTypes.get_uuid( '4AAAF936-0DEC-11E5-B939-0800200C9A66'))