feat: expose flag to disable strict name checking in service registra… · python-zeroconf/python-zeroconf@5df8a57
@@ -620,6 +620,7 @@ def register_service(
620620ttl: Optional[int] = None,
621621allow_name_change: bool = False,
622622cooperating_responders: bool = False,
623+strict: bool = True,
623624 ) -> None:
624625"""Registers service information to the network with a default TTL.
625626 Zeroconf will then respond to requests for information for that
@@ -635,7 +636,7 @@ def register_service(
635636assert self.loop is not None
636637run_coro_with_timeout(
637638await_awaitable(
638-self.async_register_service(info, ttl, allow_name_change, cooperating_responders)
639+self.async_register_service(info, ttl, allow_name_change, cooperating_responders, strict)
639640 ),
640641self.loop,
641642_REGISTER_TIME * _REGISTER_BROADCASTS,
@@ -647,6 +648,7 @@ async def async_register_service(
647648ttl: Optional[int] = None,
648649allow_name_change: bool = False,
649650cooperating_responders: bool = False,
651+strict: bool = True,
650652 ) -> Awaitable:
651653"""Registers service information to the network with a default TTL.
652654 Zeroconf will then respond to requests for information for that
@@ -662,7 +664,7 @@ async def async_register_service(
662664663665info.set_server_if_missing()
664666await self.async_wait_for_start()
665-await self.async_check_service(info, allow_name_change, cooperating_responders)
667+await self.async_check_service(info, allow_name_change, cooperating_responders, strict)
666668self.registry.async_add(info)
667669return asyncio.ensure_future(self._async_broadcast_service(info, _REGISTER_TIME, None))
668670@@ -810,11 +812,15 @@ def unregister_all_services(self) -> None:
810812 )
811813812814async def async_check_service(
813-self, info: ServiceInfo, allow_name_change: bool, cooperating_responders: bool = False
815+self,
816+info: ServiceInfo,
817+allow_name_change: bool,
818+cooperating_responders: bool = False,
819+strict: bool = True,
814820 ) -> None:
815821"""Checks the network for a unique service name, modifying the
816822 ServiceInfo passed in if it is not unique."""
817-instance_name = instance_name_from_service_info(info)
823+instance_name = instance_name_from_service_info(info, strict=strict)
818824if cooperating_responders:
819825return
820826next_instance_number = 2
@@ -829,7 +835,7 @@ async def async_check_service(
829835# change the name and look for a conflict
830836info.name = f'{instance_name}-{next_instance_number}.{info.type}'
831837next_instance_number += 1
832-service_type_name(info.name)
838+service_type_name(info.name, strict=strict)
833839next_time = now
834840i = 0
835841