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 }
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 }