当前位置: 首页>>代码示例>>Golang>>正文


Golang model.LightBulb类代码示例

本文整理汇总了Golang中github.com/brutella/hc/model.LightBulb的典型用法代码示例。如果您正苦于以下问题:Golang LightBulb类的具体用法?Golang LightBulb怎么用?Golang LightBulb使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LightBulb类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: updateHaPowerState

func updateHaPowerState(light common.Light, haLight model.LightBulb) (err error) {
	turnedOn, err := light.GetPower()

	if err != nil {
		log.WithField(`error`, err).Error(`Getting power state light`)
		return err
	}

	haLight.SetOn(turnedOn)

	return nil
}
开发者ID:hsystr,项目名称:lifx-homekit,代码行数:12,代码来源:lifx-homekit.go

示例2: updateLightColors

func updateLightColors(light common.Light, haLight model.LightBulb) {
	// HAP: [0...360]
	// LIFX: [0...MAX_UINT16]
	hue := haLight.GetHue()
	convertedHue := uint16(math.MaxUint16 * float64(hue) / 360)

	// HAP: [0...100]
	// LIFX: [0...MAX_UINT16]
	saturation := haLight.GetSaturation()
	convertedSaturation := uint16(math.MaxUint16 * float64(saturation) / 100)

	// HAP: [0...100]
	// LIFX: [0...MAX_UINT16]
	brightness := haLight.GetBrightness()
	convertedBrightness := uint16(math.MaxUint16 * int(brightness) / 100)

	// HAP: ?
	// LIFX: [2500..9000]
	kelvin := HSBKKelvinDefault

	log.Infof("[updateLightColors] Hue: %s => %s, Saturation: %s => %s, Brightness: %s => %s", hue, convertedHue, saturation, convertedSaturation, brightness, convertedBrightness)

	color := common.Color{
		Hue:        convertedHue,
		Saturation: convertedSaturation,
		Brightness: convertedBrightness,
		Kelvin:     kelvin,
	}

	light.SetColor(color, 1*time.Second)
}
开发者ID:hsystr,项目名称:lifx-homekit,代码行数:31,代码来源:lifx-homekit.go

示例3: TestLightBulb

func TestLightBulb(t *testing.T) {
	info := model.Info{
		Name:         "My Light Bulb",
		SerialNumber: "001",
		Manufacturer: "Google",
		Model:        "Switchy",
	}

	var bulb model.LightBulb = NewLightBulb(info)

	if is, want := bulb.GetBrightness(), 100; is != want {
		t.Fatalf("is=%v want=%v", is, want)
	}

	bulb.SetBrightness(90)

	if is, want := bulb.GetBrightness(), 90; is != want {
		t.Fatalf("is=%v want=%v", is, want)
	}
}
开发者ID:smitterson,项目名称:hc,代码行数:20,代码来源:light_bulb_test.go

示例4: updateHaColors

func updateHaColors(light common.Light, haLight model.LightBulb) (err error) {
	color, err := light.GetColor()

	if err != nil {
		log.WithField(`error`, err).Error(`Getting color state of light`)
		return err
	}

	hue := color.Hue
	saturation := color.Saturation
	brightness := color.Brightness
	convertedHue := float64(hue) * 360 / math.MaxUint16
	convertedSaturation := float64(saturation) * 100 / math.MaxUint16
	convertedBrightness := int(brightness) * 100 / math.MaxUint16

	log.Infof("[updateHaColors] Hue: %s => %s, Saturation: %s => %s, Brightness: %s => %s", hue, convertedHue, saturation, convertedSaturation, brightness, convertedBrightness)

	haLight.SetHue(convertedHue)
	haLight.SetSaturation(convertedSaturation)
	haLight.SetBrightness(convertedBrightness)

	return nil
}
开发者ID:hsystr,项目名称:lifx-homekit,代码行数:23,代码来源:lifx-homekit.go


注:本文中的github.com/brutella/hc/model.LightBulb类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。