Ejemplo n.º 1
0
Archivo: db.go Proyecto: upwrd/sift
func getLightEmitterTx(tx *sqlx.Tx, dbc Component, exFlags ExpansionFlags) (types.LightEmitter, error) {
	dbLE, err := getDBLightEmitterTx(tx, dbc.ID, dbc, exFlags)
	if err != nil {
		return types.LightEmitter{}, fmt.Errorf("error getting light emitter with id %v: %v", dbc.ID, err)
	}

	if dbLE.BrightnessInPercent < 0 || dbLE.BrightnessInPercent > 255 {
		return types.LightEmitter{}, fmt.Errorf("brightness value from database does not fit in uint8: %v", dbLE.BrightnessInPercent)
	}

	brightnessAsUint8 := uint8(dbLE.BrightnessInPercent)

	le := types.LightEmitter{
		BaseComponent: dbToBaseComponent(dbc),
		State: types.LightEmitterState{
			BrightnessInPercent: brightnessAsUint8,
		},
	}
	if exFlags&(ExpandAll|exFlags&ExpandSpecs) != 0 {
		le.Specs = &types.LightEmitterSpecs{
			MaxOutputInLumens:       dbLE.MaxOutputInLumens,
			MinOutputInLumens:       dbLE.MinOutputInLumens,
			ExpectedLifetimeInHours: dbLE.ExpectedLifetimeInHours,
		}
	}
	return le, nil
}
Ejemplo n.º 2
0
Archivo: db.go Proyecto: upwrd/sift
func (sdb *SiftDB) expandLightEmitterSpecs(le *types.LightEmitter) error {
	specs, err := sdb.getLightEmitterSpecs(le.Make, le.Model)
	if err != nil {
		return err
	}
	le.Specs = specs
	return nil
}