def test_initialize_board_padding2(self): # Test initializing board with the need for padding less readily apparent # Invalid json board representation valid_json = json.loads( "[[1, 3, 4], [1, 2], [1, 0, 3, 5, 4], [0, 2, 3]]") # Board obtained from the initialize_board function result_board = xboard.initialize_board(valid_json) # Test properties of the board self.assertTrue(isinstance(result_board, Board)) self.assertEquals(result_board.rows, 4) self.assertEquals(result_board.cols, 5) self.assertEquals(result_board.tile_no, 20) # Expected tile dict expected_tiles = \ { Position(0, 0): Tile(1), Position(0, 1): Tile(3), Position(0, 2): Tile(4), Position(0, 3): Hole(), Position(0, 4): Hole(), Position(1, 0): Tile(1), Position(1, 1): Tile(2), Position(1, 2): Hole(), Position(1, 3): Hole(), Position(1, 4): Hole(), Position(2, 0): Tile(1), Position(2, 1): Hole(), Position(2, 2): Tile(3), Position(2, 3): Tile(5), Position(2, 4): Tile(4), Position(3, 0): Hole(), Position(3, 1): Tile(2), Position(3, 2): Tile(3), Position(3, 3): Hole(), Position(3, 4): Hole() } # Verify all the positions in the board are the same as expected self.assertCountEqual(expected_tiles.keys(), result_board.tiles.keys()) # Verify that all tiles have the correct number of fish for key in expected_tiles: tile = expected_tiles[key] # Tile on initialized board actual_tile = result_board.get_tile(key) # Assert both tiles are the same type self.assertEqual(tile.is_tile, actual_tile.is_tile) # If the tiles are both tiles, assert that the ones on the board # have the expected number of fish if tile.is_tile: self.assertEqual(tile.fish_no, actual_tile.fish_no)
def test_init_success(self): # Tests successful constructor # Create board with 10 rows x 20 cols b = Board({ (0, 0): Tile(2), (0, 1): Tile(2), (1, 0): Hole(), (1, 1): Hole() }) # Check externally accessible properties self.assertEqual(b.rows, 2) self.assertEqual(b.cols, 2) self.assertEqual(b.tile_no, 4)
def create_holes(golf_course_holes_dict): """ Use the dictionary created in the create_golf_courses function to create a list of Hole objects. The dictionary has golf_course_id as the key, and a list of 18 tuples containing (hole_num, par_value) as the value Each entry will have: golf_course_id: [(hole_num, par_value), (hole_num, par_value), ..., (hole_num, par_value)] Create a Hole object for each hole_num and par_value containing - hole_id, golf_course_id, hole_num, and par_value Return a list, where each element is a Hole object """ print("\nThe Hole object list:\n") # Create an empty list called holes_list holes_list = [] hole_id = 1 for golf_course_id, hole_info in golf_course_holes_dict.items(): for hole_num, par in hole_info: hole = Hole(hole_id, golf_course_id, hole_num, par) holes_list.append(hole) hole_id += 1 for hole_info in holes_list: print(hole_info) return holes_list
async def main(): """Get the data from a *hole instance.""" async with aiohttp.ClientSession() as session: data = Hole(url_dns, loop, session) await data.get_data() print("Status:", data.status) return data.status
async def async_setup_entry(hass, entry): """Set up Pi-hole entry.""" name = entry.data[CONF_NAME] host = entry.data[CONF_HOST] use_tls = entry.data[CONF_SSL] verify_tls = entry.data[CONF_VERIFY_SSL] location = entry.data[CONF_LOCATION] api_key = entry.data.get(CONF_API_KEY) LOGGER.debug("Setting up %s integration with host %s", DOMAIN, host) try: session = async_get_clientsession(hass, verify_tls) pi_hole = PiHoleData( Hole( host, hass.loop, session, location=location, tls=use_tls, api_token=api_key, ), name, ) await pi_hole.async_update() hass.data[DOMAIN][name] = pi_hole except HoleError as ex: LOGGER.warning("Failed to connect: %s", ex) raise ConfigEntryNotReady hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, SENSOR_DOMAIN)) return True
def click_callback(event, x, y, flags, param): global img, state, sel_p1, sel_p2, roi_p1, roi_p2, points, real_dis if event == cv2.EVENT_LBUTTONDOWN: if state == 0: sel_p1 = [x, y] state += 1 print("Click scale setting point 2") elif state == 1: sel_p2 = [x, y] state += 1 real_dis = float(input("Input the real distance (in):: ")) print("Click roi setting point 1") elif state == 2: roi_p1 = [x, y] state += 1 print("Click roi setting point 2") elif state == 3: roi_p2 = [x, y] state += 1 print("Click the holes then hit any key") elif state == 4: p = [x, y] points.append(p) # draw marker circle = Hole(x, y, 20) draw_circle(circle, img) cv2.imshow("original", img)
async def async_setup_platform( hass, config, async_add_devices, discovery_info=None): """Set up the Pi-hole sensor.""" from hole import Hole name = config.get(CONF_NAME) host = config.get(CONF_HOST) use_tls = config.get(CONF_SSL) location = config.get(CONF_LOCATION) verify_tls = config.get(CONF_VERIFY_SSL) session = async_get_clientsession(hass) pi_hole = PiHoleData(Hole( host, hass.loop, session, location=location, tls=use_tls, verify_tls=verify_tls)) await pi_hole.async_update() if pi_hole.api.data is None: raise PlatformNotReady sensors = [PiHoleSensor(pi_hole, name, condition) for condition in config[CONF_MONITORED_CONDITIONS]] async_add_devices(sensors, True)
def listdiff(list1, list2): """ Given two lists, returns a "diff" list, with Hole instances inserted as necessary. """ hole = Hole() # Special case. if list1 == list2 == []: return [] best_size, offset1, offset2 = longest_common_substring(list1, list2) result = [] if best_size == 0: result.append(hole) if offset1 > 0 and offset2 > 0: # There's leftover stuff on the left side of BOTH lists. result.extend(listdiff(list1[:offset1], list2[:offset2])) elif offset1 > 0 or offset2 > 0: # There's leftover stuff on the left side of ONLY ONE of the lists. result.append(hole) if best_size > 0: result.extend(list1[offset1:offset1+best_size]) if (offset1 + best_size < len(list1)) and (offset2 + best_size < len(list2)): # There's leftover stuff on the right side of BOTH lists. result.extend(listdiff(list1[offset1+best_size:], list2[offset2+best_size:])) elif (offset1 + best_size < len(list1)) or (offset2 + best_size < len(list2)): # There's leftover stuff on the right side of ONLY ONE of the lists. result.append(hole) return result
async def async_setup(hass, config): """Set up the pi_hole integration.""" conf = config[DOMAIN] name = conf[CONF_NAME] host = conf[CONF_HOST] use_tls = conf[CONF_SSL] verify_tls = conf[CONF_VERIFY_SSL] location = conf[CONF_LOCATION] LOGGER.debug("Setting up %s integration with host %s", DOMAIN, host) session = async_get_clientsession(hass, True) pi_hole = PiHoleData( Hole( host, hass.loop, session, location=location, tls=use_tls, verify_tls=verify_tls, ), name, ) await pi_hole.async_update() hass.data[DOMAIN] = pi_hole hass.async_create_task( async_load_platform(hass, SENSOR_DOMAIN, DOMAIN, {}, config)) return True
def __init__(self, name, width, height, framerate=60): self.name = name self.width = width self.height = height self.framerate = framerate pygame.init() pygame.display.set_caption(name) self.surface = pygame.display.set_mode((width, height)) self.clock = pygame.time.Clock() self.running = False self.ball = Ball(self.surface) self.hole = Hole(self.surface) self.score = 0
async def _async_try_connect(self, host, location, tls, verify_tls): session = async_get_clientsession(self.opp, verify_tls) pi_hole = Hole(host, self.opp.loop, session, location=location, tls=tls) await pi_hole.get_data()
async def enable(self): """Get the data from a *hole instance.""" async with aiohttp.ClientSession() as session: data = Hole(self._hole_ip, self.loop, session, api_token=self._api_token) await data.enable()
async def async_setup(hass, config): """Set up the pi_hole integration.""" hass.data[DOMAIN] = [] for conf in config[DOMAIN]: name = conf[CONF_NAME] host = conf[CONF_HOST] use_tls = conf[CONF_SSL] verify_tls = conf[CONF_VERIFY_SSL] location = conf[CONF_LOCATION] api_key = conf.get(CONF_API_KEY) LOGGER.debug("Setting up %s integration with host %s", DOMAIN, host) session = async_get_clientsession(hass, verify_tls) pi_hole = PiHoleData( Hole(host, hass.loop, session, location=location, tls=use_tls, api_token=api_key), name, ) await pi_hole.async_update() hass.data[DOMAIN].append(pi_hole) async def handle_disable(call): if api_key is None: raise vol.Invalid( "Pi-hole api_key must be provided in configuration") duration = call.data[SERVICE_DISABLE_ATTR_DURATION].total_seconds() LOGGER.debug("Disabling %s %s for %d seconds", DOMAIN, host, duration) await pi_hole.api.disable(duration) async def handle_enable(call): if api_key is None: raise vol.Invalid( "Pi-hole api_key must be provided in configuration") LOGGER.debug("Enabling %s %s", DOMAIN, host) await pi_hole.api.enable() hass.services.async_register(DOMAIN, SERVICE_DISABLE, handle_disable, schema=SERVICE_DISABLE_SCHEMA) hass.services.async_register(DOMAIN, SERVICE_ENABLE, handle_enable) hass.async_create_task( async_load_platform(hass, SENSOR_DOMAIN, DOMAIN, {}, config)) return True
async def async_setup_entry(hass, entry): """Set up Pi-hole entry.""" name = entry.data[CONF_NAME] host = entry.data[CONF_HOST] use_tls = entry.data[CONF_SSL] verify_tls = entry.data[CONF_VERIFY_SSL] location = entry.data[CONF_LOCATION] api_key = entry.data.get(CONF_API_KEY) # For backward compatibility if CONF_STATISTICS_ONLY not in entry.data: hass.config_entries.async_update_entry( entry, data={ **entry.data, CONF_STATISTICS_ONLY: not api_key }) _LOGGER.debug("Setting up %s integration with host %s", DOMAIN, host) try: session = async_get_clientsession(hass, verify_tls) api = Hole( host, hass.loop, session, location=location, tls=use_tls, api_token=api_key, ) await api.get_data() except HoleError as ex: _LOGGER.warning("Failed to connect: %s", ex) raise ConfigEntryNotReady from ex async def async_update_data(): """Fetch data from API endpoint.""" try: await api.get_data() except HoleError as err: raise UpdateFailed( f"Failed to communicate with API: {err}") from err coordinator = DataUpdateCoordinator( hass, _LOGGER, name=name, update_method=async_update_data, update_interval=MIN_TIME_BETWEEN_UPDATES, ) hass.data[DOMAIN][entry.entry_id] = { DATA_KEY_API: api, DATA_KEY_COORDINATOR: coordinator, } for platform in _async_platforms(entry): hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, platform)) return True
def test_board_to_json_success2(self): # Tests successful board to json b = Board({ Position(0, 0): Tile(5), Position(0, 1): Tile(3), Position(0, 2): Tile(2), Position(1, 0): Hole(), Position(1, 1): Hole(), Position(1, 2): Tile(2), Position(2, 0): Tile(3), Position(2, 1): Tile(4), Position(2, 2): Hole(), Position(3, 0): Hole(), Position(3, 1): Tile(1), Position(3, 2): Tile(5) }) self.assertSequenceEqual(_board_to_json(b), [[5, 3, 2], [0, 0, 2], [3, 4, 0], [0, 1, 5]])
def test_init_fail3(self): # Tests constructor failing due to there being invalid # tiles in the collection with self.assertRaises(ValueError): Board({ (0, 0): Tile(2), (0, 1): Tile(2), (1, 0): Hole(), (1, 1): None })
async def _async_try_connect(self, host, location, tls, verify_tls, api_token): session = async_get_clientsession(self.hass, verify_tls) pi_hole = Hole( host, self.hass.loop, session, location=location, tls=tls, api_token=api_token, ) await pi_hole.get_data()
async def main(): """Get the data from a *hole instance.""" async with aiohttp.ClientSession() as session: data = Hole('192.168.0.215', loop, session) await data.get_data() # Get the raw data print(json.dumps(data.data, indent=4, sort_keys=True)) print("Status:", data.status) print("Domains being blocked:", data.domains_being_blocked)
def relocate_holes(self): self.holes.clear() for i in range(self.num_holes): pos = (randint(0, self.dim[1] - self.hole_w), randint(self.screen.y, self.dim[1] - self.hole_w)) unique = False while not unique: unique = True for h in self.holes: r = pygame.Rect(pos[0], pos[1], self.hole_w, self.hole_w) if r.colliderect(h.rect.move(h.pos[0], h.pos[1])): pos = (randint(0, self.dim[1] - self.hole_w), randint(self.screen.y, self.dim[1] - self.hole_w)) unique = False break self.holes.append(Hole(pos, (self.hole_w, self.hole_w)))
def create_holes(golf_course_holes_dict): """ Use the dictionary created in the create_golf_courses function to create a list of Hole objects. The dictionary has golf_course_id as the key, and a list of 18 tuples containing (hole_num, par_value) as the value Each entry will have: golf_course_id: [(hole_num, par_value), (hole_num, par_value), ..., (hole_num, par_value)] Create a Hole object for each hole_num and par_value containing - hole_id, golf_course_id, hole_num, and par_value Return a list, where each element is a Hole object """ print("\nThe Hole object list:\n") # Create an empty list called holes_list holes_list = [] # initialize hole_id hole_id = 1 # outer loop reads key(1) into golf_course_id, and puts the value into hole_info for golf_course_id, hole_info in golf_course_holes_dict.items(): # inner loop through hole_info to get hole_num and par_value for info in hole_info: hole_num = info[0] par_value = info[1] # create a new Hole object passing in hole_id, golf_course_id, hole_num, par_value hole_obj = Hole(hole_id, golf_course_id, hole_num, par_value) # append hole object to the hole_list holes_list.append(hole_obj) # increment hole_id hole_id += 1 # print the holes_list objects to the console for ob in holes_list: print(ob) return holes_list
def collide(self, other): # This code is ambiguous because of 'circular dependencies' #or type(other) is Ground or type(other) is type(Bullet) from rock import Rock from ground import Ground from hole import Hole from rover import Rover if isinstance(other, Ground): if 20 <= randint(0, 100) <= 80: rand_dim_bullet_h = randint(1, 2) Hole(self._arena, (self._x, 600), rand_dim_bullet_h, self._difficulty) if isinstance(other, Rock) or isinstance(other, Hole) or isinstance( other, Rover): self._state = 'explode'
def initialize_board(json_board: list) -> Board: """ Initialize a Board object based on the given json representation of the board. :param json_board: the json representation of a board as provided by the testing specifications :return: a Board object consisting of the tiles described by the board_json """ # Dict to store tile objects tiles = {} # Determine the maximum row length so that we can determine whether we need to pad certain rows with 0's max_row_length = max(map(lambda x: len(x), json_board)) # Iterate through each row in the json board for row in range(len(json_board)): # Current row in the board current_row = json_board[row] # Iterate through all columns in the current row (and, if row length # is shorter than the maximum, iterate extra times to pad with zeros) for current_col in range(max_row_length): try: # The current position current_pos = Position(row, current_col) # The number of fish according to the json object num_fish = current_row[current_col] if current_col < len(current_row) else 0 # Initialize a new tile/hole according to the number provided new_tile = Tile(num_fish) if num_fish > 0 else Hole() # Add the tile to the current collection of tiles tiles[current_pos] = new_tile except ValueError: raise ValueError("Issue initializing tile because of an invalid number of fish.") except TypeError: raise TypeError("Issue initializing tile because a non-integer value was encountered.") try: # Disable sprite rendering for testing purposes Board.DISABLE_SPRITE_MANAGER = True # Initialize a board with the given dictionary of tiles board = Board(tiles) return board except ValueError: raise ValueError("Could not initialize board - perhaps there was an error initializing the tiles?")
async def pihole_stats(self): """Get the data from a *hole instance.""" pihole_data = {} async with aiohttp.ClientSession() as session: data = Hole(self._hole_ip, self.loop, session) await data.get_versions() # version = json.dumps(data.data, indent=4, sort_keys=True) pihole_data['version'] = data.data await data.get_data() # pihole_data = json.dumps(data.data, indent=4, sort_keys=True) pihole_data['stats'] = data.data # Get the raw data # print("Status:", data.status) # print("Domains being blocked:", data.domains_being_blocked) return pihole_data
def runHough(self, image): circles = cv2.HoughCircles(image, cv2.HOUGH_GRADIENT, self.dp, self.minDist, param1=self.canny, param2=self.accum, minRadius=self.minRadius, maxRadius=self.maxRadius) output = [] # check if empty if circles is None: return output circles = np.uint16(np.around(circles)) for i in circles[0, :]: hole = Hole(i[0], i[1], i[2]) output.append(hole) return output
def test_initialize_board_success(self): # Test successful validation of a board object from valid board json # Create json board object based on the provided representation valid_json = json.loads("[[1, 0], [3, 5], [2, 4]]") # Board obtained from the initialize_board function result_board = xboard.initialize_board(valid_json) # Test properties of the board self.assertTrue(isinstance(result_board, Board)) self.assertEquals(result_board.rows, 3) self.assertEquals(result_board.cols, 2) self.assertEquals(result_board.tile_no, 6) # Expected tile dict expected_tiles = \ { Position(0, 0): Tile(1), Position(0, 1): Hole(), Position(1, 0): Tile(3), Position(1, 1): Tile(5), Position(2, 0): Tile(2), Position(2, 1): Tile(4) } # Verify all the positions in the board are the same as expected self.assertCountEqual(expected_tiles.keys(), result_board.tiles.keys()) # Verify that all tiles have the correct number of fish for key in expected_tiles: tile = expected_tiles[key] # Tile on initialized board actual_tile = result_board.get_tile(key) # Assert both tiles are the same type self.assertEqual(tile.is_tile, actual_tile.is_tile) # If the tiles are both tiles, assert that the ones on the board # have the expected number of fish if tile.is_tile: self.assertEqual(tile.fish_no, actual_tile.fish_no)
def remove_tile(self, pt: Position) -> None: """ Removes a tile at the given position (if one exists) by replacing it with a Hole instead. :param pt: position to remove tile :return: None """ # Validate point if not isinstance(pt, Position): raise ValueError('Expected Position object for pt!') # Retrieve tile at point tile = self.get_tile(pt) # Check tile type if tile.is_tile: self.__tiles.update({pt: Hole()}) else: raise ValueError('No tile at given location!')
def create_holes(golf_course_holes_dict): """ Use the dictionary created in the create_golf_courses function to create a list of Hole objects. The dictionary has golf_course_id as the key, and a list of 18 tuples containing (hole_num, par_value) as the value Each entry will have: golf_course_id: [(hole_num, par_value), (hole_num, par_value), ..., (hole_num, par_value)] Create a Hole object for each hole_num and par_value containing - hole_id, golf_course_id, hole_num, and par_value Return a list, where each element is a Hole object """ print("\nThe Hole object list:\n") # Create an empty list called holes_list holes_list = [] #initialize the hold_id to 1 hole_id = 1 # Create an outer loop to read the golf course holes dictionary for golf_course_id, hole_info in golf_course_holes_dict.items(): for hole_num, par_value in hole_info: #create hole object, pass hole_id, golf_course_id, hole_num, par_value to the object holeObject = Hole(hole_id, golf_course_id, hole_num, par_value) #append the object info to the holes_list holes_list.append(holeObject) #increment the hole_id up 1 hole_id = hole_id + 1 #print holes list to the console for hl in holes_list: print(hl) #return holes_list return holes_list
async def main(): """Get the data from a *hole instance.""" async with aiohttp.ClientSession() as session: data = Hole("192.168.0.215", session) await data.get_versions() print(json.dumps(data.versions, indent=4, sort_keys=True)) print("Version:", data.core_current, "Latest:", data.core_latest, "Update available:", data.core_update) print("FTL:", data.ftl_current, "Latest:", data.ftl_latest, "Update available:", data.ftl_update) print("Web:", data.web_current, "Latest:", data.web_latest, "Update available:", data.web_update) await data.get_data() # Get the raw data print(json.dumps(data.data, indent=4, sort_keys=True)) print("Status:", data.status) print("Domains being blocked:", data.domains_being_blocked)
def run_test(row, params): path = row["file"] target_type = row["type"] diameter = float(row["diameter"]) real_dis = float(row["scale"]) scale_p = row["scale_p"] scale_pairs = scale_p.split(",") scale_p1 = get_coord(scale_pairs[0]) scale_p2 = get_coord(scale_pairs[1]) roi_p = row["roi_p"] roi_pairs = roi_p.split(",") roi_p1 = get_coord(roi_pairs[0]) roi_p2 = get_coord(roi_pairs[1]) holes_string = row["holes"] holes_pairs = holes_string.split(",") check = [] for pair in holes_pairs: coord = get_coord(pair) coord_hole = Hole(coord[0], coord[1], 0) check.append(coord_hole); analyzer = Analyzer() analyzer.params = params img = cv2.imread(path, 0) analyzer.set_image(img) analyzer.set_scale(20, diameter, real_dis, scale_p1, scale_p2) analyzer.set_roi(roi_p1, roi_p2) analyzer.run() stats = check_holes(check, analyzer.holes) stats.diameter = diameter stats.target_type = target_type return stats, analyzer
async def async_setup(hass, config): """Set up the pi_hole integration.""" def get_data(): """Retrive component data.""" return hass.data[DOMAIN] def ensure_api_token(call_data): """Ensure the Pi-Hole to be enabled/disabled has a api_token configured.""" data = get_data() if SERVICE_DISABLE_ATTR_NAME not in call_data: for slug in data: call_data[SERVICE_DISABLE_ATTR_NAME] = data[slug].name ensure_api_token(call_data) call_data[SERVICE_DISABLE_ATTR_NAME] = None else: slug = cv.slugify(call_data[SERVICE_DISABLE_ATTR_NAME]) if (data[slug]).api.api_token is None: raise vol.Invalid( "Pi-hole '{}' must have an api_key provided in configuration to be enabled." .format(pi_hole.name)) return call_data service_disable_schema = vol.Schema( # pylint: disable=invalid-name vol.All( { vol.Required(SERVICE_DISABLE_ATTR_DURATION): vol.All(cv.time_period_str, cv.positive_timedelta), vol.Optional(SERVICE_DISABLE_ATTR_NAME): vol.In( [conf[CONF_NAME] for conf in config[DOMAIN]], msg="Unknown Pi-Hole", ), }, ensure_api_token, )) service_enable_schema = vol.Schema({ vol.Optional(SERVICE_ENABLE_ATTR_NAME): vol.In([conf[CONF_NAME] for conf in config[DOMAIN]], msg="Unknown Pi-Hole") }) hass.data[DOMAIN] = {} for conf in config[DOMAIN]: name = conf[CONF_NAME] slug = conf[CONF_SLUG] host = conf[CONF_HOST] use_tls = conf[CONF_SSL] verify_tls = conf[CONF_VERIFY_SSL] location = conf[CONF_LOCATION] api_key = conf.get(CONF_API_KEY) LOGGER.debug("Setting up %s integration with host %s", DOMAIN, host) session = async_get_clientsession(hass, verify_tls) pi_hole = PiHoleData( Hole( host, hass.loop, session, location=location, tls=use_tls, api_token=api_key, ), name, ) await pi_hole.async_update() hass.data[DOMAIN][slug] = pi_hole async def disable_service_handler(call): """Handle the service call to disable a single Pi-Hole or all configured Pi-Holes.""" duration = call.data[SERVICE_DISABLE_ATTR_DURATION].total_seconds() name = call.data.get(SERVICE_DISABLE_ATTR_NAME) async def do_disable(name): """Disable the named Pi-Hole.""" slug = cv.slugify(name) pi_hole = hass.data[DOMAIN][slug] LOGGER.debug( "Disabling Pi-hole '%s' (%s) for %d seconds", name, pi_hole.api.host, duration, ) await pi_hole.api.disable(duration) if name is not None: await do_disable(name) else: for pi_hole in hass.data[DOMAIN].values(): await do_disable(pi_hole.name) async def enable_service_handler(call): """Handle the service call to enable a single Pi-Hole or all configured Pi-Holes.""" name = call.data.get(SERVICE_ENABLE_ATTR_NAME) async def do_enable(name): """Enable the named Pi-Hole.""" slug = cv.slugify(name) pi_hole = hass.data[DOMAIN][slug] LOGGER.debug("Enabling Pi-hole '%s' (%s)", name, pi_hole.api.host) await pi_hole.api.enable() if name is not None: await do_enable(name) else: for pi_hole in hass.data[DOMAIN].values(): await do_enable(pi_hole.name) hass.services.async_register(DOMAIN, SERVICE_DISABLE, disable_service_handler, schema=service_disable_schema) hass.services.async_register(DOMAIN, SERVICE_ENABLE, enable_service_handler, schema=service_enable_schema) hass.async_create_task( async_load_platform(hass, SENSOR_DOMAIN, DOMAIN, {}, config)) return True