feat: everything up to bluetooth scanning

This commit is contained in:
2025-03-26 21:01:42 +01:00
parent be964fab25
commit f4022dd249
21 changed files with 2496 additions and 132 deletions

View File

@ -0,0 +1,47 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'bluetooth_device_model.freezed.dart';
part 'bluetooth_device_model.g.dart';
/// Enum representing the type of Bluetooth device
enum DeviceType {
/// Universal Shifters device
universalShifters,
/// Other unspecified device types
other,
}
/// Model representing a Bluetooth device
@freezed
abstract class BluetoothDeviceModel with _$BluetoothDeviceModel {
const factory BluetoothDeviceModel({
/// Unique identifier for the device
required String id,
/// Name of the device as advertised
String? name,
/// MAC address of the device
required String address,
/// Signal strength indicator (RSSI)
int? rssi,
/// Type of the device
@Default(DeviceType.other) DeviceType type,
/// Whether the device is currently connected
@Default(false) bool isConnected,
/// Additional device information
Map<String, dynamic>? manufacturerData,
/// Service UUIDs advertised by the device
List<String>? serviceUuids,
}) = _BluetoothDeviceModel;
/// Create a BluetoothDeviceModel from JSON
factory BluetoothDeviceModel.fromJson(Map<String, dynamic> json) =>
_$BluetoothDeviceModelFromJson(json);
}

View File

@ -0,0 +1,366 @@
// dart format width=80
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'bluetooth_device_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$BluetoothDeviceModel {
/// Unique identifier for the device
String get id;
/// Name of the device as advertised
String? get name;
/// MAC address of the device
String get address;
/// Signal strength indicator (RSSI)
int? get rssi;
/// Type of the device
DeviceType get type;
/// Whether the device is currently connected
bool get isConnected;
/// Additional device information
Map<String, dynamic>? get manufacturerData;
/// Service UUIDs advertised by the device
List<String>? get serviceUuids;
/// Create a copy of BluetoothDeviceModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$BluetoothDeviceModelCopyWith<BluetoothDeviceModel> get copyWith =>
_$BluetoothDeviceModelCopyWithImpl<BluetoothDeviceModel>(
this as BluetoothDeviceModel, _$identity);
/// Serializes this BluetoothDeviceModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is BluetoothDeviceModel &&
(identical(other.id, id) || other.id == id) &&
(identical(other.name, name) || other.name == name) &&
(identical(other.address, address) || other.address == address) &&
(identical(other.rssi, rssi) || other.rssi == rssi) &&
(identical(other.type, type) || other.type == type) &&
(identical(other.isConnected, isConnected) ||
other.isConnected == isConnected) &&
const DeepCollectionEquality()
.equals(other.manufacturerData, manufacturerData) &&
const DeepCollectionEquality()
.equals(other.serviceUuids, serviceUuids));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
id,
name,
address,
rssi,
type,
isConnected,
const DeepCollectionEquality().hash(manufacturerData),
const DeepCollectionEquality().hash(serviceUuids));
@override
String toString() {
return 'BluetoothDeviceModel(id: $id, name: $name, address: $address, rssi: $rssi, type: $type, isConnected: $isConnected, manufacturerData: $manufacturerData, serviceUuids: $serviceUuids)';
}
}
/// @nodoc
abstract mixin class $BluetoothDeviceModelCopyWith<$Res> {
factory $BluetoothDeviceModelCopyWith(BluetoothDeviceModel value,
$Res Function(BluetoothDeviceModel) _then) =
_$BluetoothDeviceModelCopyWithImpl;
@useResult
$Res call(
{String id,
String? name,
String address,
int? rssi,
DeviceType type,
bool isConnected,
Map<String, dynamic>? manufacturerData,
List<String>? serviceUuids});
}
/// @nodoc
class _$BluetoothDeviceModelCopyWithImpl<$Res>
implements $BluetoothDeviceModelCopyWith<$Res> {
_$BluetoothDeviceModelCopyWithImpl(this._self, this._then);
final BluetoothDeviceModel _self;
final $Res Function(BluetoothDeviceModel) _then;
/// Create a copy of BluetoothDeviceModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = null,
Object? name = freezed,
Object? address = null,
Object? rssi = freezed,
Object? type = null,
Object? isConnected = null,
Object? manufacturerData = freezed,
Object? serviceUuids = freezed,
}) {
return _then(_self.copyWith(
id: null == id
? _self.id
: id // ignore: cast_nullable_to_non_nullable
as String,
name: freezed == name
? _self.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
address: null == address
? _self.address
: address // ignore: cast_nullable_to_non_nullable
as String,
rssi: freezed == rssi
? _self.rssi
: rssi // ignore: cast_nullable_to_non_nullable
as int?,
type: null == type
? _self.type
: type // ignore: cast_nullable_to_non_nullable
as DeviceType,
isConnected: null == isConnected
? _self.isConnected
: isConnected // ignore: cast_nullable_to_non_nullable
as bool,
manufacturerData: freezed == manufacturerData
? _self.manufacturerData
: manufacturerData // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
serviceUuids: freezed == serviceUuids
? _self.serviceUuids
: serviceUuids // ignore: cast_nullable_to_non_nullable
as List<String>?,
));
}
}
/// @nodoc
@JsonSerializable()
class _BluetoothDeviceModel implements BluetoothDeviceModel {
const _BluetoothDeviceModel(
{required this.id,
this.name,
required this.address,
this.rssi,
this.type = DeviceType.other,
this.isConnected = false,
final Map<String, dynamic>? manufacturerData,
final List<String>? serviceUuids})
: _manufacturerData = manufacturerData,
_serviceUuids = serviceUuids;
factory _BluetoothDeviceModel.fromJson(Map<String, dynamic> json) =>
_$BluetoothDeviceModelFromJson(json);
/// Unique identifier for the device
@override
final String id;
/// Name of the device as advertised
@override
final String? name;
/// MAC address of the device
@override
final String address;
/// Signal strength indicator (RSSI)
@override
final int? rssi;
/// Type of the device
@override
@JsonKey()
final DeviceType type;
/// Whether the device is currently connected
@override
@JsonKey()
final bool isConnected;
/// Additional device information
final Map<String, dynamic>? _manufacturerData;
/// Additional device information
@override
Map<String, dynamic>? get manufacturerData {
final value = _manufacturerData;
if (value == null) return null;
if (_manufacturerData is EqualUnmodifiableMapView) return _manufacturerData;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}
/// Service UUIDs advertised by the device
final List<String>? _serviceUuids;
/// Service UUIDs advertised by the device
@override
List<String>? get serviceUuids {
final value = _serviceUuids;
if (value == null) return null;
if (_serviceUuids is EqualUnmodifiableListView) return _serviceUuids;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}
/// Create a copy of BluetoothDeviceModel
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$BluetoothDeviceModelCopyWith<_BluetoothDeviceModel> get copyWith =>
__$BluetoothDeviceModelCopyWithImpl<_BluetoothDeviceModel>(
this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$BluetoothDeviceModelToJson(
this,
);
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _BluetoothDeviceModel &&
(identical(other.id, id) || other.id == id) &&
(identical(other.name, name) || other.name == name) &&
(identical(other.address, address) || other.address == address) &&
(identical(other.rssi, rssi) || other.rssi == rssi) &&
(identical(other.type, type) || other.type == type) &&
(identical(other.isConnected, isConnected) ||
other.isConnected == isConnected) &&
const DeepCollectionEquality()
.equals(other._manufacturerData, _manufacturerData) &&
const DeepCollectionEquality()
.equals(other._serviceUuids, _serviceUuids));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
id,
name,
address,
rssi,
type,
isConnected,
const DeepCollectionEquality().hash(_manufacturerData),
const DeepCollectionEquality().hash(_serviceUuids));
@override
String toString() {
return 'BluetoothDeviceModel(id: $id, name: $name, address: $address, rssi: $rssi, type: $type, isConnected: $isConnected, manufacturerData: $manufacturerData, serviceUuids: $serviceUuids)';
}
}
/// @nodoc
abstract mixin class _$BluetoothDeviceModelCopyWith<$Res>
implements $BluetoothDeviceModelCopyWith<$Res> {
factory _$BluetoothDeviceModelCopyWith(_BluetoothDeviceModel value,
$Res Function(_BluetoothDeviceModel) _then) =
__$BluetoothDeviceModelCopyWithImpl;
@override
@useResult
$Res call(
{String id,
String? name,
String address,
int? rssi,
DeviceType type,
bool isConnected,
Map<String, dynamic>? manufacturerData,
List<String>? serviceUuids});
}
/// @nodoc
class __$BluetoothDeviceModelCopyWithImpl<$Res>
implements _$BluetoothDeviceModelCopyWith<$Res> {
__$BluetoothDeviceModelCopyWithImpl(this._self, this._then);
final _BluetoothDeviceModel _self;
final $Res Function(_BluetoothDeviceModel) _then;
/// Create a copy of BluetoothDeviceModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$Res call({
Object? id = null,
Object? name = freezed,
Object? address = null,
Object? rssi = freezed,
Object? type = null,
Object? isConnected = null,
Object? manufacturerData = freezed,
Object? serviceUuids = freezed,
}) {
return _then(_BluetoothDeviceModel(
id: null == id
? _self.id
: id // ignore: cast_nullable_to_non_nullable
as String,
name: freezed == name
? _self.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
address: null == address
? _self.address
: address // ignore: cast_nullable_to_non_nullable
as String,
rssi: freezed == rssi
? _self.rssi
: rssi // ignore: cast_nullable_to_non_nullable
as int?,
type: null == type
? _self.type
: type // ignore: cast_nullable_to_non_nullable
as DeviceType,
isConnected: null == isConnected
? _self.isConnected
: isConnected // ignore: cast_nullable_to_non_nullable
as bool,
manufacturerData: freezed == manufacturerData
? _self._manufacturerData
: manufacturerData // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
serviceUuids: freezed == serviceUuids
? _self._serviceUuids
: serviceUuids // ignore: cast_nullable_to_non_nullable
as List<String>?,
));
}
}
// dart format on

View File

@ -0,0 +1,41 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'bluetooth_device_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_BluetoothDeviceModel _$BluetoothDeviceModelFromJson(
Map<String, dynamic> json) =>
_BluetoothDeviceModel(
id: json['id'] as String,
name: json['name'] as String?,
address: json['address'] as String,
rssi: (json['rssi'] as num?)?.toInt(),
type: $enumDecodeNullable(_$DeviceTypeEnumMap, json['type']) ??
DeviceType.other,
isConnected: json['isConnected'] as bool? ?? false,
manufacturerData: json['manufacturerData'] as Map<String, dynamic>?,
serviceUuids: (json['serviceUuids'] as List<dynamic>?)
?.map((e) => e as String)
.toList(),
);
Map<String, dynamic> _$BluetoothDeviceModelToJson(
_BluetoothDeviceModel instance) =>
<String, dynamic>{
'id': instance.id,
'name': instance.name,
'address': instance.address,
'rssi': instance.rssi,
'type': _$DeviceTypeEnumMap[instance.type]!,
'isConnected': instance.isConnected,
'manufacturerData': instance.manufacturerData,
'serviceUuids': instance.serviceUuids,
};
const _$DeviceTypeEnumMap = {
DeviceType.universalShifters: 'universalShifters',
DeviceType.other: 'other',
};