<commit_before>// Copyright 2014 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// 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.
package wemo

import (
	"regexp"
	"time"
)

var belkinRE *regexp.Regexp = regexp.MustCompile(`http://([^/]+)/setup.xml`)

type Wemo struct {
	ipAddr string
	Debug  bool
}

func (self *Wemo) DiscoverAll(timeout time.Duration) ([]*Device, error) {
	urns := []string{
		"urn:Belkin:device:controllee:1",
		"urn:Belkin:device:light:1",
		"urn:Belkin:device:sensor:1",
	}

	var all []*Device
	for _, urn := range urns {
		devices, _ := self.Discover(urn, timeout)
		for _, device := range devices {
			all = append(all, device)
		}
	}

	return all, nil
}

func (self *Wemo) Discover(urn string, timeout time.Duration) ([]*Device, error) {
	locations, err := self.scan(urn, timeout)
	if err != nil {
		return nil, err
	}

	var devices []*Device
	for _, uri := range locations {
		if matches := belkinRE.FindStringSubmatch(uri.String()); len(matches) == 2 {
			host := matches[1]
			devices = append(devices, &Device{Host: host})
		}
	}

	return devices, nil
}<commit_msg>added urn for netcam so it finds NetCam camera<commit_after>// Copyright 2014 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// 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.
package wemo

import (
	"regexp"
	"time"
)

var belkinRE *regexp.Regexp = regexp.MustCompile(`http://([^/]+)/setup.xml`)

type Wemo struct {
	ipAddr string
	Debug  bool
}

func (self *Wemo) DiscoverAll(timeout time.Duration) ([]*Device, error) {
	urns := []string{
		"urn:Belkin:device:controllee:1",
		"urn:Belkin:device:light:1",
		"urn:Belkin:device:sensor:1",
		"urn:Belkin:device:netcam:1",
	}

	var all []*Device
	for _, urn := range urns {
		devices, _ := self.Discover(urn, timeout)
		for _, device := range devices {
			all = append(all, device)
		}
	}

	return all, nil
}

func (self *Wemo) Discover(urn string, timeout time.Duration) ([]*Device, error) {
	locations, err := self.scan(urn, timeout)
	if err != nil {
		return nil, err
	}

	var devices []*Device
	for _, uri := range locations {
		if matches := belkinRE.FindStringSubmatch(uri.String()); len(matches) == 2 {
			host := matches[1]
			devices = append(devices, &Device{Host: host})
		}
	}
	return devices, nil
}
{'fraction_non_alphanumeric': 0.13544940289126337, 'fraction_numerical': 0.008485229415461974, 'mean_word_length': 3.8595419847328243, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1586873', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1007, 'n_words': 349}